diff --git a/templates/plumbing/argocd-super-role.yaml b/templates/plumbing/argocd-super-role.yaml index 2317bfb..fb5b598 100644 --- a/templates/plumbing/argocd-super-role.yaml +++ b/templates/plumbing/argocd-super-role.yaml @@ -7,8 +7,10 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: {{ $.Values.global.vpArgoNamespace }}-cluster-admin-rolebinding +{{- if ne ($.Values.global.options.clusterRoleBindingSyncWave | toString) "0" }} annotations: argocd.argoproj.io/sync-wave: {{ $.Values.global.options.clusterRoleBindingSyncWave | quote }} +{{- end }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -29,8 +31,10 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: {{ $.Values.global.pattern }}-{{ .Values.clusterGroup.name }}-cluster-admin-rolebinding +{{- if ne ($.Values.global.options.clusterRoleBindingSyncWave | toString) "0" }} annotations: argocd.argoproj.io/sync-wave: {{ $.Values.global.options.clusterRoleBindingSyncWave | quote }} +{{- end }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/tests/argocd_super_role_test.yaml b/tests/argocd_super_role_test.yaml index 4453225..6fe6ce6 100644 --- a/tests/argocd_super_role_test.yaml +++ b/tests/argocd_super_role_test.yaml @@ -97,7 +97,7 @@ tests: path: subjects[1].namespace value: mypattern-edge - - it: should set default sync-wave annotation to -1 on first ClusterRoleBinding + - it: should not set sync-wave annotation by default on first ClusterRoleBinding set: global: pattern: common @@ -106,11 +106,10 @@ tests: name: hub asserts: - documentIndex: 0 - equal: - path: metadata.annotations["argocd.argoproj.io/sync-wave"] - value: "-1" + isNull: + path: metadata.annotations - - it: should set default sync-wave annotation to -1 on second ClusterRoleBinding + - it: should not set sync-wave annotation by default on second ClusterRoleBinding set: global: pattern: common @@ -118,6 +117,24 @@ tests: clusterGroup: name: hub asserts: + - documentIndex: 1 + isNull: + path: metadata.annotations + + - it: should set sync-wave annotation when clusterRoleBindingSyncWave is non-zero + set: + global: + pattern: common + vpArgoNamespace: openshift-gitops + options: + clusterRoleBindingSyncWave: "-1" + clusterGroup: + name: hub + asserts: + - documentIndex: 0 + equal: + path: metadata.annotations["argocd.argoproj.io/sync-wave"] + value: "-1" - documentIndex: 1 equal: path: metadata.annotations["argocd.argoproj.io/sync-wave"] @@ -142,7 +159,7 @@ tests: path: metadata.annotations["argocd.argoproj.io/sync-wave"] value: "-2" - - it: should allow setting sync-wave to zero + - it: should not set sync-wave annotation when explicitly set to zero set: global: pattern: common @@ -153,10 +170,8 @@ tests: name: hub asserts: - documentIndex: 0 - equal: - path: metadata.annotations["argocd.argoproj.io/sync-wave"] - value: "0" + isNull: + path: metadata.annotations - documentIndex: 1 - equal: - path: metadata.annotations["argocd.argoproj.io/sync-wave"] - value: "0" + isNull: + path: metadata.annotations diff --git a/values.schema.json b/values.schema.json index a1ff6e4..33386d5 100644 --- a/values.schema.json +++ b/values.schema.json @@ -296,8 +296,8 @@ }, "clusterRoleBindingSyncWave": { "type": "string", - "description": "Sync-wave annotation value for the cluster-admin ClusterRoleBinding. Defaults to -1 so it is applied before wave-0 resources", - "default": "-1" + "description": "Sync-wave annotation value for the cluster-admin ClusterRoleBinding. When set to 0 (default) no annotation is added. Set to -1 to apply before wave-0 resources", + "default": "0" } }, "required": [ diff --git a/values.yaml b/values.yaml index e40664d..c250da2 100644 --- a/values.yaml +++ b/values.yaml @@ -18,8 +18,8 @@ global: syncPolicy: Automatic installPlanApproval: Automatic applicationRetryLimit: 20 - # -- Sync-wave annotation for the cluster-admin ClusterRoleBinding. Set to "-1" so it is applied before wave-0 resources that need cluster-admin privileges - clusterRoleBindingSyncWave: "-1" + # -- Sync-wave annotation for the cluster-admin ClusterRoleBinding. When set to "0" (default) no sync-wave annotation is added. Set to "-1" to apply before wave-0 resources + clusterRoleBindingSyncWave: "0" # Note that sometimes changing helm values might require a hard refresh (https://github.com/helm/helm/issues/3486) clusterGroup: