Skip to content

Commit

Permalink
Include needed argocd k8s resources and change the code to set the de…
Browse files Browse the repository at this point in the history
…veloper's password. cnoe-io#441

Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Nov 12, 2024
1 parent d392287 commit 0c62564
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
1 change: 1 addition & 0 deletions hack/argo-cd/argocd-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: argocd-cm
data:
application.resourceTrackingMethod: annotation
accounts.developer: apiKey, login
timeout.reconciliation: 60s
resource.exclusions: |
- kinds:
Expand Down
12 changes: 12 additions & 0 deletions hack/argo-cd/argocd-rbac-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/name: argocd-rbac-cm
app.kubernetes.io/part-of: argocd
name: argocd-rbac-cm
namespace: argocd
data:
policy.csv: |
p, role:developer, applications, *, *, allow
g, developer, role:developer
1 change: 1 addition & 0 deletions hack/argo-cd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://raw.githubusercontent.com/argoproj/argo-cd/v2.10.7/manifests/install.yaml
- argocd-rbac-dev.yaml

patches:
- path: dex-server.yaml
Expand Down
52 changes: 27 additions & 25 deletions pkg/controllers/localbuild/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"golang.org/x/crypto/bcrypt"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"
Expand Down Expand Up @@ -83,8 +82,8 @@ func (r *LocalbuildReconciler) ReconcileArgo(ctx context.Context, req ctrl.Reque
// Prepare the patch for the Secret's `stringData` field
patchData := map[string]interface{}{
"stringData": map[string]string{
"admin.password": string(hashedPassword),
"admin.passwordMtime": time.Now().Format(time.RFC3339),
"account.developer.password": string(hashedPassword),
"account.developer.passwordMtime": time.Now().Format(time.RFC3339),
},
}
// Convert patch data to JSON
Expand All @@ -105,33 +104,36 @@ func (r *LocalbuildReconciler) ReconcileArgo(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, fmt.Errorf("getting argocd secret: %w", err)
}

// Patching the argocd-secret with the hashed password
// Patching the argocd-secret with the user's hashed password
err = kubeClient.Patch(ctx, &s, client.RawPatch(types.StrategicMergePatchType, patchBytes))
if err != nil {
return ctrl.Result{}, fmt.Errorf("Error patching the Secret: %w", err)
}

adminSecret := v1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: argocdInitialAdminSecretName,
Namespace: argocdNamespace,
},
StringData: map[string]string{
argocdInitialAdminPasswordKey: argocdDevModePassword,
},
}

// 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: %w", err)
} else {
return ctrl.Result{}, nil
}
/*
This is not needed as we will not generate a new admin password
adminSecret := v1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: argocdInitialAdminSecretName,
Namespace: argocdNamespace,
},
StringData: map[string]string{
argocdInitialAdminPasswordKey: argocdDevModePassword,
},
}
// 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: %w", err)
} else {
return ctrl.Result{}, nil
}*/

}

Expand Down
14 changes: 14 additions & 0 deletions pkg/controllers/localbuild/resources/argo/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21081,6 +21081,20 @@ subjects:
---
apiVersion: v1
data:
policy.csv: |-
p, role:developer, applications, *, *, allow
g, developer, role:developer
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/name: argocd-rbac-cm
app.kubernetes.io/part-of: argocd
name: argocd-rbac-cm
namespace: argocd
---
apiVersion: v1
data:
accounts.developer: apiKey, login
application.resourceTrackingMethod: annotation
resource.exclusions: |
- kinds:
Expand Down

0 comments on commit 0c62564

Please sign in to comment.