diff --git a/pkg/comp-functions/functions/vshnkeycloak/deploy.go b/pkg/comp-functions/functions/vshnkeycloak/deploy.go index efdbeae1b..8d863a046 100644 --- a/pkg/comp-functions/functions/vshnkeycloak/deploy.go +++ b/pkg/comp-functions/functions/vshnkeycloak/deploy.go @@ -152,7 +152,6 @@ func addPostgreSQL(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNKeycloak) error params := &vshnv1.VSHNPostgreSQLParameters{ Size: comp.Spec.Parameters.Size, - Instances: 1, Maintenance: comp.GetFullMaintenanceSchedule(), Backup: vshnv1.VSHNPostgreSQLBackup{ Retention: retention, @@ -183,6 +182,9 @@ func addPostgreSQL(svc *runtime.ServiceRuntime, comp *vshnv1.VSHNKeycloak) error params.Backup.DeletionProtection = comp.Spec.Parameters.Service.PostgreSQLParameters.Backup.DeletionProtection } } + // We need to set this after the merge, as the default instance count for PostgreSQL is always 1 + // and would therefore override any value we set before the merge. + params.Instances = comp.Spec.Parameters.Instances pg := &vshnv1.XVSHNPostgreSQL{ ObjectMeta: metav1.ObjectMeta{ @@ -371,6 +373,7 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS } values = map[string]any{ + "replicas": comp.Spec.Parameters.Instances, "extraEnv": extraEnv, "extraVolumes": extraVolumes, "extraVolumeMounts": extraVolumeMounts, diff --git a/pkg/comp-functions/functions/vshnkeycloak/deploy_test.go b/pkg/comp-functions/functions/vshnkeycloak/deploy_test.go index 05b31edfb..e100ef479 100644 --- a/pkg/comp-functions/functions/vshnkeycloak/deploy_test.go +++ b/pkg/comp-functions/functions/vshnkeycloak/deploy_test.go @@ -2,6 +2,7 @@ package vshnkeycloak import ( "context" + "encoding/json" "testing" "github.com/stretchr/testify/assert" @@ -26,7 +27,6 @@ func Test_addPostgreSQL(t *testing.T) { // Assert default values assert.True(t, *pg.Spec.Parameters.Backup.DeletionProtection) - assert.Equal(t, 1, pg.Spec.Parameters.Instances) assert.Equal(t, 6, pg.Spec.Parameters.Backup.Retention) // Assert default overrides @@ -35,13 +35,11 @@ func Test_addPostgreSQL(t *testing.T) { DeletionProtection: ptr.To(false), Retention: 1, }, - Instances: 2, } assert.NoError(t, addPostgreSQL(svc, comp)) assert.NoError(t, svc.GetDesiredComposedResourceByName(pg, comp.GetName()+pgInstanceNameSuffix)) assert.False(t, *pg.Spec.Parameters.Backup.DeletionProtection) - assert.Equal(t, 2, pg.Spec.Parameters.Instances) assert.Equal(t, 1, pg.Spec.Parameters.Backup.Retention) } @@ -69,3 +67,36 @@ func Test_addRelease(t *testing.T) { assert.NoError(t, svc.GetDesiredComposedResourceByName(release, comp.GetName()+"-release")) } + +func Test_addHARelease(t *testing.T) { + svc := commontest.LoadRuntimeFromFile(t, "vshnkeycloak/01_default.yaml") + + comp := &vshnv1.VSHNKeycloak{ + ObjectMeta: metav1.ObjectMeta{ + Name: "mycloak", + Namespace: "default", + }, + Spec: vshnv1.VSHNKeycloakSpec{ + Parameters: vshnv1.VSHNKeycloakParameters{ + Instances: 2, + Service: vshnv1.VSHNKeycloakServiceSpec{ + Version: "23", + }, + }, + }, + } + + assert.NoError(t, addRelease(context.TODO(), svc, comp, "mysecret")) + release := &xhelmv1.Release{} + assert.NoError(t, svc.GetDesiredComposedResourceByName(release, comp.GetName()+"-release")) + values := map[string]any{} + assert.NoError(t, json.Unmarshal(release.Spec.ForProvider.Values.Raw, &values)) + assert.Equal(t, float64(2), values["replicas"]) + + pg := &vshnv1.XVSHNPostgreSQL{} + + assert.NoError(t, addPostgreSQL(svc, comp)) + assert.NoError(t, svc.GetDesiredComposedResourceByName(pg, comp.GetName()+pgInstanceNameSuffix)) + assert.Equal(t, 2, pg.Spec.Parameters.Instances) + +}