diff --git a/api/v1beta1/argocd_types.go b/api/v1beta1/argocd_types.go index a7d72b532..2d2e3c22b 100644 --- a/api/v1beta1/argocd_types.go +++ b/api/v1beta1/argocd_types.go @@ -753,6 +753,10 @@ type ArgoCDSpec struct { // Import is the import/restore options for ArgoCD. Import *ArgoCDImportSpec `json:"import,omitempty"` + // InClusterName represents the name of the cluster where Argo CD is deployed + //+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="In-Cluster Name",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldGroup:ArgoCD","urn:alm:descriptor:com.tectonic.ui:text"} + InClusterName string `json:"inClusterName,omitempty"` + // InitialRepositories to configure Argo CD with upon creation of the cluster. //+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Initial Repositories'",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text","urn:alm:descriptor:com.tectonic.ui:advanced"} InitialRepositories string `json:"initialRepositories,omitempty"` diff --git a/bundle/manifests/argocd-operator.clusterserviceversion.yaml b/bundle/manifests/argocd-operator.clusterserviceversion.yaml index c9f758a34..2bd98ffce 100644 --- a/bundle/manifests/argocd-operator.clusterserviceversion.yaml +++ b/bundle/manifests/argocd-operator.clusterserviceversion.yaml @@ -1152,6 +1152,13 @@ spec: x-descriptors: - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Import - urn:alm:descriptor:com.tectonic.ui:text + - description: InClusterName represents the name of the cluster where Argo CD + is deployed + displayName: In-Cluster Name + path: inClusterName + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldGroup:ArgoCD + - urn:alm:descriptor:com.tectonic.ui:text - description: InitialRepositories to configure Argo CD with upon creation of the cluster. displayName: Initial Repositories' diff --git a/bundle/manifests/argoproj.io_argocds.yaml b/bundle/manifests/argoproj.io_argocds.yaml index 242e229ee..606f372d2 100644 --- a/bundle/manifests/argoproj.io_argocds.yaml +++ b/bundle/manifests/argoproj.io_argocds.yaml @@ -7887,6 +7887,10 @@ spec: required: - name type: object + inClusterName: + description: InClusterName represents the name of the cluster where + Argo CD is deployed + type: string initialRepositories: description: InitialRepositories to configure Argo CD with upon creation of the cluster. diff --git a/config/crd/bases/argoproj.io_argocds.yaml b/config/crd/bases/argoproj.io_argocds.yaml index 67b2103e6..99ff89963 100644 --- a/config/crd/bases/argoproj.io_argocds.yaml +++ b/config/crd/bases/argoproj.io_argocds.yaml @@ -7878,6 +7878,10 @@ spec: required: - name type: object + inClusterName: + description: InClusterName represents the name of the cluster where + Argo CD is deployed + type: string initialRepositories: description: InitialRepositories to configure Argo CD with upon creation of the cluster. diff --git a/config/manifests/bases/argocd-operator.clusterserviceversion.yaml b/config/manifests/bases/argocd-operator.clusterserviceversion.yaml index 93894fa0e..2b56207b9 100644 --- a/config/manifests/bases/argocd-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/argocd-operator.clusterserviceversion.yaml @@ -328,6 +328,13 @@ spec: x-descriptors: - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Import - urn:alm:descriptor:com.tectonic.ui:text + - description: InClusterName represents the name of the cluster where Argo CD + is deployed + displayName: In-Cluster Name + path: inClusterName + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldGroup:ArgoCD + - urn:alm:descriptor:com.tectonic.ui:text - description: InitialRepositories to configure Argo CD with upon creation of the cluster. displayName: Initial Repositories' diff --git a/controllers/argocd/secret.go b/controllers/argocd/secret.go index 59640db28..ffaecfd77 100644 --- a/controllers/argocd/secret.go +++ b/controllers/argocd/secret.go @@ -449,9 +449,14 @@ func (r *ReconcileArgoCD) reconcileClusterPermissionsSecret(cr *argoproj.ArgoCD) } sort.Strings(namespaces) + inClusterName := "in-cluster" + if cr.Spec.InClusterName != "" { + inClusterName = cr.Spec.InClusterName + } + secret.Data = map[string][]byte{ "config": dataBytes, - "name": []byte("in-cluster"), + "name": []byte(inClusterName), "server": []byte(common.ArgoCDDefaultServer), "namespaces": []byte(strings.Join(namespaces, ",")), } @@ -483,6 +488,9 @@ func (r *ReconcileArgoCD) reconcileClusterPermissionsSecret(cr *argoproj.ArgoCD) sort.Strings(ns) s.Data["namespaces"] = []byte(strings.Join(ns, ",")) } + // update Argo CD cluster name + s.Data["name"] = []byte(inClusterName) + return r.Client.Update(context.TODO(), &s) } } diff --git a/controllers/argocd/secret_test.go b/controllers/argocd/secret_test.go index 8fbcc0058..9aca0d8d8 100644 --- a/controllers/argocd/secret_test.go +++ b/controllers/argocd/secret_test.go @@ -485,4 +485,18 @@ func Test_ReconcileArgoCD_ClusterPermissionsSecret(t *testing.T) { //TODO: https://github.com/stretchr/testify/pull/1022 introduced ErrorContains, but is not yet available in a tagged release. Revert to ErrorContains once this becomes available assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) assert.Nil(t, r.Client.Get(context.TODO(), types.NamespacedName{Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + + customClusterName := "custom-cluster-name" + a.Spec.InClusterName = customClusterName + assert.NoError(t, r.reconcileClusterPermissionsSecret(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{ + Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Equal(t, customClusterName, string(testSecret.Data["name"])) + + // Reset InClusterName and test for default value + a.Spec.InClusterName = "" + assert.NoError(t, r.reconcileClusterPermissionsSecret(a)) + assert.NoError(t, r.Client.Get(context.TODO(), types.NamespacedName{ + Name: testSecret.Name, Namespace: testSecret.Namespace}, testSecret)) + assert.Equal(t, "in-cluster", string(testSecret.Data["name"])) } diff --git a/deploy/olm-catalog/argocd-operator/0.9.0/argocd-operator.v0.9.0.clusterserviceversion.yaml b/deploy/olm-catalog/argocd-operator/0.9.0/argocd-operator.v0.9.0.clusterserviceversion.yaml index c9f758a34..2bd98ffce 100644 --- a/deploy/olm-catalog/argocd-operator/0.9.0/argocd-operator.v0.9.0.clusterserviceversion.yaml +++ b/deploy/olm-catalog/argocd-operator/0.9.0/argocd-operator.v0.9.0.clusterserviceversion.yaml @@ -1152,6 +1152,13 @@ spec: x-descriptors: - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Import - urn:alm:descriptor:com.tectonic.ui:text + - description: InClusterName represents the name of the cluster where Argo CD + is deployed + displayName: In-Cluster Name + path: inClusterName + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldGroup:ArgoCD + - urn:alm:descriptor:com.tectonic.ui:text - description: InitialRepositories to configure Argo CD with upon creation of the cluster. displayName: Initial Repositories' diff --git a/deploy/olm-catalog/argocd-operator/0.9.0/argoproj.io_argocds.yaml b/deploy/olm-catalog/argocd-operator/0.9.0/argoproj.io_argocds.yaml index 242e229ee..606f372d2 100644 --- a/deploy/olm-catalog/argocd-operator/0.9.0/argoproj.io_argocds.yaml +++ b/deploy/olm-catalog/argocd-operator/0.9.0/argoproj.io_argocds.yaml @@ -7887,6 +7887,10 @@ spec: required: - name type: object + inClusterName: + description: InClusterName represents the name of the cluster where + Argo CD is deployed + type: string initialRepositories: description: InitialRepositories to configure Argo CD with upon creation of the cluster. diff --git a/docs/reference/argocd.md b/docs/reference/argocd.md index 0c7e8d2f1..2a99b6550 100644 --- a/docs/reference/argocd.md +++ b/docs/reference/argocd.md @@ -25,6 +25,7 @@ Name | Default | Description [**HelpChatText**](#help-chat-text) | `Chat now!` | The text for getting chat help. [**Image**](#image) | `argoproj/argocd` | The container image for all Argo CD components. This overrides the `ARGOCD_IMAGE` environment variable. [**Import**](#import-options) | [Object] | Import configuration options. +[**InClusterName**](#in-cluster-name) | `in-cluster` | Represents the name of the cluster where Argo CD is deployed. [**Ingress**](#ingress-options) | [Object] | Ingress configuration options. [**InitialRepositories**](#initial-repositories) | [Empty] | Initial git repositories to configure Argo CD to use upon creation of the cluster. [**Notifications**](#notifications-controller-options) | [Object] | Notifications controller configuration options. @@ -528,6 +529,25 @@ argoproj.io/AppProject default unchanged argo-cd import complete ``` +## In-Cluster Name + +The `inClusterName` property specifies the name of the cluster where Argo CD is deployed. Its default value is `in-cluster`. + +### In-Cluster Name Example + +The following example sets the cluster name to `example-cluster` in the `-default-cluster-config` secret. + +``` yaml +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: example-argocd + labels: + example: in-cluster-name +spec: + inClusterName: example-cluster +``` + ## Initial Repositories Initial git repositories to configure Argo CD to use upon creation of the cluster. diff --git a/tests/k8s/1-036_validate_cluster_name/01-assert.yaml b/tests/k8s/1-036_validate_cluster_name/01-assert.yaml new file mode 100644 index 000000000..cf300f961 --- /dev/null +++ b/tests/k8s/1-036_validate_cluster_name/01-assert.yaml @@ -0,0 +1,17 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 120 +--- +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: argocd +status: + phase: Available +--- +apiVersion: v1 +kind: Secret +metadata: + name: argocd-default-cluster-config +data: + name: dGVzdC1jbHVzdGVy # test-cluster diff --git a/tests/k8s/1-036_validate_cluster_name/01-install.yaml b/tests/k8s/1-036_validate_cluster_name/01-install.yaml new file mode 100644 index 000000000..af97fe6c7 --- /dev/null +++ b/tests/k8s/1-036_validate_cluster_name/01-install.yaml @@ -0,0 +1,6 @@ +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: argocd +spec: + inClusterName: test-cluster diff --git a/tests/k8s/1-036_validate_cluster_name/02-assert.yaml b/tests/k8s/1-036_validate_cluster_name/02-assert.yaml new file mode 100644 index 000000000..943d5eba5 --- /dev/null +++ b/tests/k8s/1-036_validate_cluster_name/02-assert.yaml @@ -0,0 +1,17 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 120 +--- +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: argocd +status: + phase: Available +--- +apiVersion: v1 +kind: Secret +metadata: + name: argocd-default-cluster-config +data: + name: YW5vdGhlci10ZXN0LWNsdXN0ZXI= # another-test-cluster diff --git a/tests/k8s/1-036_validate_cluster_name/02-install.yaml b/tests/k8s/1-036_validate_cluster_name/02-install.yaml new file mode 100644 index 000000000..25123eafd --- /dev/null +++ b/tests/k8s/1-036_validate_cluster_name/02-install.yaml @@ -0,0 +1,6 @@ +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: argocd +spec: + inClusterName: another-test-cluster