Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
fix: reconcile admin secret
Browse files Browse the repository at this point in the history
  • Loading branch information
pb82 committed Oct 2, 2019
1 parent 10e7431 commit 43d7fc1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/keycloak/keycloak_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (i *KeycloakReconciler) GetKeycloakAdminSecretDesiredState(clusterState *co
}
}
return common.GenericUpdateAction{
Ref: keycloakAdminSecret,
Ref: model.KeycloakAdminSecretReconciled(cr, clusterState.KeycloakAdminSecret),
Msg: "Update Keycloak admin secret",
}
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/model/keycloak_admin_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func KeycloakAdminSecret(cr *v1alpha1.Keycloak) *v1.Secret {
},
},
Data: map[string][]byte{
"ADMIN_USERNAME": []byte("admin"),
"ADMIN_PASSWORD": []byte(randStringRunes(10)),
AdminUsernameProperty: []byte("admin"),
AdminPasswordProperty: []byte(randStringRunes(10)),
},
Type: "Opaque",
}
Expand All @@ -31,3 +31,15 @@ func KeycloakAdminSecretSelector(cr *v1alpha1.Keycloak) client.ObjectKey {
Namespace: cr.Namespace,
}
}

func KeycloakAdminSecretReconciled(cr *v1alpha1.Keycloak, currentState *v1.Secret) *v1.Secret {
reconciled := currentState.DeepCopy()
// K8s automatically converts StringData to Data when getting the resource
if _, ok := reconciled.Data[AdminUsernameProperty]; !ok {
reconciled.Data[AdminUsernameProperty] = []byte("admin")
}
if _, ok := reconciled.Data[AdminPasswordProperty]; !ok {
reconciled.Data[AdminPasswordProperty] = []byte(randStringRunes(10))
}
return reconciled
}

0 comments on commit 43d7fc1

Please sign in to comment.