Skip to content

Commit

Permalink
Merge pull request #135 from vshn/keycloak/internal_admin
Browse files Browse the repository at this point in the history
Add external admin account
  • Loading branch information
Kidswiss authored Mar 4, 2024
2 parents 65fa607 + e5349a6 commit 9d2837b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions apis/vshn/v1/dbaas_vshn_keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ type VSHNKeycloakServiceSpec struct {
// +kubebuilder:default="/"
RelativePath string `json:"relativePath,omitempty"`

// +kubebuilder:validation:Enum="23.0.5-202402021353-44-af6cea11"
// +kubebuilder:default="23.0.5-202402021353-44-af6cea11"
// +kubebuilder:validation:Enum="23"
// +kubebuilder:default="23"

// Version contains supported version of keycloak.
// Multiple versions are supported. The latest version 23 is the default version.
Expand Down
4 changes: 2 additions & 2 deletions crds/vshn.appcat.vshn.io_vshnkeycloaks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3725,10 +3725,10 @@ spec:
- guaranteed
type: string
version:
default: 23.0.5-202402021353-44-af6cea11
default: "23"
description: Version contains supported version of keycloak. Multiple versions are supported. The latest version 23 is the default version.
enum:
- 23.0.5-202402021353-44-af6cea11
- "23"
type: string
type: object
default: {}
Expand Down
4 changes: 2 additions & 2 deletions crds/vshn.appcat.vshn.io_xvshnkeycloaks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5957,12 +5957,12 @@ spec:
- guaranteed
type: string
version:
default: 23.0.5-202402021353-44-af6cea11
default: "23"
description: Version contains supported version of keycloak.
Multiple versions are supported. The latest version 23 is
the default version.
enum:
- 23.0.5-202402021353-44-af6cea11
- "23"
type: string
type: object
size:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func SetReleaseVersion(ctx context.Context, version string, desiredValues map[st

if observedVersion.GTE(desiredVersion) {
// In case the overved tag is valid and greater than the desired version, keep the observed version
return observedVersion.String(), unstructured.SetNestedField(desiredValues, tag, fields...)
return tag, unstructured.SetNestedField(desiredValues, tag, fields...)
}
// In case the observed tag is smaller than the desired version, then set the version from the claim
return version, unstructured.SetNestedField(desiredValues, version, fields...)
Expand Down
27 changes: 22 additions & 5 deletions pkg/comp-functions/functions/vshnkeycloak/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ import (
)

const (
pgInstanceNameSuffix = "-pg"
pgSecretName = "pg-creds"
adminPWSecretField = "password"
pgInstanceNameSuffix = "-pg"
pgSecretName = "pg-creds"
// Each instance has two admin accounts by default.
// One that's exposed to the user and one that's kept internally.
// The internal one is used for scripts within the keycloak image to handle various configurations.
internalAdminPWSecretField = "internalAdminPassword"
adminPWSecretField = "adminPassword"
adminPWConnectionDetailsField = "KEYCLOAK_PASSWORD"
adminConnectionDetailsField = "KEYCLOAK_USERNAME"
hostConnectionDetailsField = "KEYCLOAK_HOST"
Expand Down Expand Up @@ -91,7 +95,7 @@ func DeployKeycloak(ctx context.Context, svc *runtime.ServiceRuntime) *xfnproto.

svc.Log.Info("Adding release")

adminSecret, err := common.AddCredentialsSecret(comp, svc, []string{adminPWSecretField})
adminSecret, err := common.AddCredentialsSecret(comp, svc, []string{internalAdminPWSecretField, adminPWSecretField})
if err != nil {
return runtime.NewWarningResult(fmt.Sprintf("cannot generate admin secret: %s", err))
}
Expand Down Expand Up @@ -237,10 +241,23 @@ func newValues(ctx context.Context, svc *runtime.ServiceRuntime, comp *vshnv1.VS
extraEnvMap := []map[string]any{
{
"name": "KEYCLOAK_ADMIN",
"value": "admin",
"value": "internaladmin",
},
{
"name": "KEYCLOAK_ADMIN_PASSWORD",
"valueFrom": map[string]any{
"secretKeyRef": map[string]any{
"name": adminSecret,
"key": internalAdminPWSecretField,
},
},
},
{
"name": "KEYCLOAK_MANAGED",
"value": "admin",
},
{
"name": "KEYCLOAK_MANAGED_PASSWORD",
"valueFrom": map[string]any{
"secretKeyRef": map[string]any{
"name": adminSecret,
Expand Down
2 changes: 1 addition & 1 deletion pkg/maintenance/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func (m *Keycloak) DoMaintenance(ctx context.Context) error {

valuesPath := helm.NewValuePath("image", "tag")

return patcher.DoMaintenance(ctx, keycloakURL, valuesPath, helm.SemVerPatchesOnly(false))
return patcher.DoMaintenance(ctx, keycloakURL, valuesPath, helm.SemVerPatchesOnly(true))
}

0 comments on commit 9d2837b

Please sign in to comment.