Skip to content

Commit

Permalink
Move the current time function. Generate the missing field. cnoe-io#441
Browse files Browse the repository at this point in the history
Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Nov 8, 2024
1 parent ee9dc06 commit d392287
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/controllers/localbuild/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,18 @@ func (r *LocalbuildReconciler) ReconcileArgo(ctx context.Context, req ctrl.Reque
if err != nil {
return ctrl.Result{}, fmt.Errorf("Error hashing password: %w", err)
}
passwordMtime := time.Now().Format(time.RFC3339)

// Prepare the patch for the Secret's `stringData` field
patchData := map[string]interface{}{
"stringData": map[string]string{
"admin.password": string(hashedPassword),
"admin.passwordMtime": passwordMtime,
"admin.passwordMtime": time.Now().Format(time.RFC3339),
},
}
// Convert patch data to JSON
patchBytes, err := json.Marshal(patchData)
if err != nil {
return ctrl.Result{}, fmt.Errorf("Error marshalling patch data:", err)
return ctrl.Result{}, fmt.Errorf("Error marshalling patch data: %w", err)
}

kubeClient, err := k8s.GetKubeClient()
Expand All @@ -109,7 +108,7 @@ func (r *LocalbuildReconciler) ReconcileArgo(ctx context.Context, req ctrl.Reque
// Patching the argocd-secret with the hashed password
err = kubeClient.Patch(ctx, &s, client.RawPatch(types.StrategicMergePatchType, patchBytes))
if err != nil {
return ctrl.Result{}, fmt.Errorf("Error patching the Secret:", err)
return ctrl.Result{}, fmt.Errorf("Error patching the Secret: %w", err)
}

adminSecret := v1.Secret{
Expand All @@ -129,7 +128,9 @@ func (r *LocalbuildReconciler) ReconcileArgo(ctx context.Context, req ctrl.Reque
// Re-creating the initial admin password secret: argocd-initial-admin-secret as used with "idpbuilder get secrets -p argocd"
err = kubeClient.Create(ctx, &adminSecret)
if err != nil {
return ctrl.Result{}, fmt.Errorf("Error creating the initial admin secret:", err)
return ctrl.Result{}, fmt.Errorf("Error creating the initial admin secret: %w", err)
} else {
return ctrl.Result{}, nil
}

}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
description: BuildCustomizationSpec fields cannot change once a cluster
is created
properties:
devMode:
type: boolean
host:
type: string
ingressHost:
Expand Down

0 comments on commit d392287

Please sign in to comment.