Skip to content

Commit

Permalink
Merge pull request #165 from vshn/keycloak/ha
Browse files Browse the repository at this point in the history
Add HA support for keycloak
  • Loading branch information
TheBigLee authored May 16, 2024
2 parents ac70a88 + 131e923 commit ffff86b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/comp-functions/functions/vshnkeycloak/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 34 additions & 3 deletions pkg/comp-functions/functions/vshnkeycloak/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vshnkeycloak

import (
"context"
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)

}

0 comments on commit ffff86b

Please sign in to comment.