Skip to content

Commit

Permalink
Merge pull request #215 from vshn/keycloak-hot-load
Browse files Browse the repository at this point in the history
Add keycloak cm hash
  • Loading branch information
zugao authored Aug 13, 2024
2 parents 97bfd37 + e38fbbf commit 766be5a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/comp-functions/functions/vshnkeycloak/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vshnkeycloak

import (
"context"
"crypto/md5"
"encoding/base64"
"encoding/json"
"errors"
Expand Down Expand Up @@ -165,7 +166,7 @@ func getResources(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1
return res, nil
}

func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VSHNKeycloak, adminSecret string) (map[string]any, error) {
func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VSHNKeycloak, adminSecret, hashedCustomConfig string) (map[string]any, error) {
values := map[string]any{}

cd, err := svc.GetObservedComposedResourceConnectionDetails(comp.GetName() + common.PgInstanceNameSuffix)
Expand Down Expand Up @@ -263,13 +264,15 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS
},
}

podAnnotations := map[string]any{}
if comp.Spec.Parameters.Service.CustomConfigurationRef != nil {
extraVolumesMap = append(extraVolumesMap, map[string]any{
"name": "keycloak-configs",
"configMap": map[string]any{
"name": comp.Spec.Parameters.Service.CustomConfigurationRef,
},
})
podAnnotations["checksum/keycloak-config"] = hashedCustomConfig
}

extraVolumes, err := toYAML(extraVolumesMap)
Expand Down Expand Up @@ -393,6 +396,7 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS
// "internalPort": "http-internal",
},
"podSecurityContext": nil,
"podAnnotations": podAnnotations,
}

jsonned, _ := json.Marshal(values)
Expand All @@ -402,9 +406,10 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS
}

func newRelease(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VSHNKeycloak, adminSecret string) (*xhelmv1.Release, error) {

var hashedCustomConfig string
if comp.Spec.Parameters.Service.CustomConfigurationRef != nil {
err := copyConfigMap(comp, svc)
customCM, err := copyConfigMap(comp, svc)
hashedCustomConfig = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%v", customCM.Data))))
if err != nil {
return nil, fmt.Errorf("cannot copy keycloak config configmap to instance namespace: %w", err)
}
Expand All @@ -416,7 +421,7 @@ func newRelease(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.V
}
}

values, err := newValues(ctx, svc, comp, adminSecret)
values, err := newValues(ctx, svc, comp, adminSecret, hashedCustomConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -613,7 +618,7 @@ exit 0`,
return extraInitContainersMap, nil
}

func copyConfigMap(comp *vshnv1.VSHNKeycloak, svc *runtime.ServiceRuntime) error {
func copyConfigMap(comp *vshnv1.VSHNKeycloak, svc *runtime.ServiceRuntime) (*corev1.ConfigMap, error) {

cmObjectName := comp.GetName() + "-config-claim-observer"

Expand Down Expand Up @@ -647,7 +652,7 @@ func copyConfigMap(comp *vshnv1.VSHNKeycloak, svc *runtime.ServiceRuntime) error
Data: configMapClaim.Data,
}

return svc.SetDesiredKubeObject(configMapInstance, comp.GetName()+"-config-map")
return configMapInstance, svc.SetDesiredKubeObject(configMapInstance, comp.GetName()+"-config-map")
}

func copySecret(comp *vshnv1.VSHNKeycloak, svc *runtime.ServiceRuntime) error {
Expand Down

0 comments on commit 766be5a

Please sign in to comment.