diff --git a/api/v1beta1/argocd_types.go b/api/v1beta1/argocd_types.go index fa5a62ade..6717a0aeb 100644 --- a/api/v1beta1/argocd_types.go +++ b/api/v1beta1/argocd_types.go @@ -743,6 +743,20 @@ type ArgoCDNodePlacementSpec struct { Tolerations []corev1.Toleration `json:"tolerations,omitempty"` } +// ArgoCDLocalClusterSpec defines the configuration for the local cluster in Argo CD +type ArgoCDLocalClusterSpec struct { + + // Name represents the name of the local cluster + Name string `json:"name,omitempty"` +} + +// ArgoCDClustersSpec defines options related to cluster management in Argo CD +type ArgoCDClustersSpec struct { + + // Local provides the configuration for the local cluster + Local ArgoCDLocalClusterSpec `json:"local,omitempty"` +} + // ArgoCDSpec defines the desired state of ArgoCD // +k8s:openapi-gen=true type ArgoCDSpec struct { @@ -754,6 +768,10 @@ type ArgoCDSpec struct { //+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Application Instance Label Key'",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text","urn:alm:descriptor:com.tectonic.ui:advanced"} ApplicationInstanceLabelKey string `json:"applicationInstanceLabelKey,omitempty"` + // Clusters defines specific cluster options for managing Argo CD clusters. + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Clusters",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text","urn:alm:descriptor:com.tectonic.ui:advanced"} + Clusters ArgoCDClustersSpec `json:"clusters,omitempty"` + // ConfigManagementPlugins is used to specify additional config management plugins. //+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Config Management Plugins'",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text","urn:alm:descriptor:com.tectonic.ui:advanced"} ConfigManagementPlugins string `json:"configManagementPlugins,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index bceb4e4bf..ef118cd72 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -241,6 +241,22 @@ func (in *ArgoCDCertificateSpec) DeepCopy() *ArgoCDCertificateSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ArgoCDClustersSpec) DeepCopyInto(out *ArgoCDClustersSpec) { + *out = *in + out.Local = in.Local +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDClustersSpec. +func (in *ArgoCDClustersSpec) DeepCopy() *ArgoCDClustersSpec { + if in == nil { + return nil + } + out := new(ArgoCDClustersSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ArgoCDDexSpec) DeepCopyInto(out *ArgoCDDexSpec) { *out = *in @@ -431,6 +447,21 @@ func (in *ArgoCDList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ArgoCDLocalClusterSpec) DeepCopyInto(out *ArgoCDLocalClusterSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDLocalClusterSpec. +func (in *ArgoCDLocalClusterSpec) DeepCopy() *ArgoCDLocalClusterSpec { + if in == nil { + return nil + } + out := new(ArgoCDLocalClusterSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ArgoCDMonitoringSpec) DeepCopyInto(out *ArgoCDMonitoringSpec) { *out = *in @@ -877,6 +908,7 @@ func (in *ArgoCDSpec) DeepCopyInto(out *ArgoCDSpec) { *out = new(ArgoCDApplicationSet) (*in).DeepCopyInto(*out) } + out.Clusters = in.Clusters in.Controller.DeepCopyInto(&out.Controller) if in.ExtraConfig != nil { in, out := &in.ExtraConfig, &out.ExtraConfig diff --git a/bundle/manifests/argocd-operator.clusterserviceversion.yaml b/bundle/manifests/argocd-operator.clusterserviceversion.yaml index b64d71c75..e98d3e27b 100644 --- a/bundle/manifests/argocd-operator.clusterserviceversion.yaml +++ b/bundle/manifests/argocd-operator.clusterserviceversion.yaml @@ -247,7 +247,7 @@ metadata: capabilities: Deep Insights categories: Integration & Delivery certified: "false" - createdAt: "2024-09-27T05:27:12Z" + createdAt: "2024-10-04T06:48:03Z" description: Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. operators.operatorframework.io/builder: operator-sdk-v1.35.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v4 @@ -1051,6 +1051,13 @@ spec: - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Prometheus - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Server - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: Clusters defines specific cluster options for managing Argo CD + clusters. + displayName: Clusters + path: clusters + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: ConfigManagementPlugins is used to specify additional config management plugins. displayName: Config Management Plugins' diff --git a/bundle/manifests/argoproj.io_argocds.yaml b/bundle/manifests/argoproj.io_argocds.yaml index f38aefbc6..591e56431 100644 --- a/bundle/manifests/argoproj.io_argocds.yaml +++ b/bundle/manifests/argoproj.io_argocds.yaml @@ -7669,6 +7669,18 @@ spec: required: - content type: object + clusters: + description: Clusters defines specific cluster options for managing + Argo CD clusters. + properties: + local: + description: Local provides the configuration for the local cluster + properties: + name: + description: Name represents the name of the local cluster + type: string + type: object + type: object configManagementPlugins: description: ConfigManagementPlugins is used to specify additional config management plugins. diff --git a/config/crd/bases/argoproj.io_argocds.yaml b/config/crd/bases/argoproj.io_argocds.yaml index 30486dd91..0c6950391 100644 --- a/config/crd/bases/argoproj.io_argocds.yaml +++ b/config/crd/bases/argoproj.io_argocds.yaml @@ -7658,6 +7658,18 @@ spec: required: - content type: object + clusters: + description: Clusters defines specific cluster options for managing + Argo CD clusters. + properties: + local: + description: Local provides the configuration for the local cluster + properties: + name: + description: Name represents the name of the local cluster + type: string + type: object + type: object configManagementPlugins: description: ConfigManagementPlugins is used to specify additional config management plugins. diff --git a/config/manifests/bases/argocd-operator.clusterserviceversion.yaml b/config/manifests/bases/argocd-operator.clusterserviceversion.yaml index d3326ed9f..9e154d6cd 100644 --- a/config/manifests/bases/argocd-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/argocd-operator.clusterserviceversion.yaml @@ -289,6 +289,13 @@ spec: - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Prometheus - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Server - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: Clusters defines specific cluster options for managing Argo CD + clusters. + displayName: Clusters + path: clusters + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: ConfigManagementPlugins is used to specify additional config management plugins. displayName: Config Management Plugins' diff --git a/controllers/argocd/secret.go b/controllers/argocd/secret.go index b1f58a73e..b7333282d 100644 --- a/controllers/argocd/secret.go +++ b/controllers/argocd/secret.go @@ -406,9 +406,14 @@ func (r *ReconcileArgoCD) reconcileClusterPermissionsSecret(cr *argoproj.ArgoCD) } sort.Strings(namespaces) + localClusteName := "in-cluster" + if cr.Spec.Clusters.Local.Name != "" { + localClusteName = cr.Spec.Clusters.Local.Name + } + secret.Data = map[string][]byte{ "config": dataBytes, - "name": []byte("in-cluster"), + "name": []byte(localClusteName), "server": []byte(common.ArgoCDDefaultServer), "namespaces": []byte(strings.Join(namespaces, ",")), } @@ -440,6 +445,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(localClusteName) + return r.Client.Update(context.TODO(), &s) } } diff --git a/controllers/argocd/secret_test.go b/controllers/argocd/secret_test.go index 61834b98d..2610ad06f 100644 --- a/controllers/argocd/secret_test.go +++ b/controllers/argocd/secret_test.go @@ -550,4 +550,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.Clusters.Local.Name = 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.Clusters.Local.Name = "" + 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.13.0/argocd-operator.v0.13.0.clusterserviceversion.yaml b/deploy/olm-catalog/argocd-operator/0.13.0/argocd-operator.v0.13.0.clusterserviceversion.yaml index b64d71c75..e98d3e27b 100644 --- a/deploy/olm-catalog/argocd-operator/0.13.0/argocd-operator.v0.13.0.clusterserviceversion.yaml +++ b/deploy/olm-catalog/argocd-operator/0.13.0/argocd-operator.v0.13.0.clusterserviceversion.yaml @@ -247,7 +247,7 @@ metadata: capabilities: Deep Insights categories: Integration & Delivery certified: "false" - createdAt: "2024-09-27T05:27:12Z" + createdAt: "2024-10-04T06:48:03Z" description: Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. operators.operatorframework.io/builder: operator-sdk-v1.35.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v4 @@ -1051,6 +1051,13 @@ spec: - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Prometheus - urn:alm:descriptor:com.tectonic.ui:fieldGroup:Server - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: Clusters defines specific cluster options for managing Argo CD + clusters. + displayName: Clusters + path: clusters + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text + - urn:alm:descriptor:com.tectonic.ui:advanced - description: ConfigManagementPlugins is used to specify additional config management plugins. displayName: Config Management Plugins' diff --git a/deploy/olm-catalog/argocd-operator/0.13.0/argoproj.io_argocds.yaml b/deploy/olm-catalog/argocd-operator/0.13.0/argoproj.io_argocds.yaml index f38aefbc6..591e56431 100644 --- a/deploy/olm-catalog/argocd-operator/0.13.0/argoproj.io_argocds.yaml +++ b/deploy/olm-catalog/argocd-operator/0.13.0/argoproj.io_argocds.yaml @@ -7669,6 +7669,18 @@ spec: required: - content type: object + clusters: + description: Clusters defines specific cluster options for managing + Argo CD clusters. + properties: + local: + description: Local provides the configuration for the local cluster + properties: + name: + description: Name represents the name of the local cluster + type: string + type: object + type: object configManagementPlugins: description: ConfigManagementPlugins is used to specify additional config management plugins. diff --git a/docs/reference/argocd.md b/docs/reference/argocd.md index 212bc7cd0..f6cb902c0 100644 --- a/docs/reference/argocd.md +++ b/docs/reference/argocd.md @@ -13,6 +13,7 @@ Name | Default | Description --- | --- | --- [**ApplicationInstanceLabelKey**](#application-instance-label-key) | `mycompany.com/appname` | The metadata.label key name where Argo CD injects the app name as a tracking label. [**ApplicationSet**](#applicationset-controller-options) | [Object] | ApplicationSet controller configuration options. +[**Clusters**](#clusters) | `clusters` | Defines specific cluster options for managing Argo CD clusters. [**ConfigManagementPlugins**](#config-management-plugins) | [Empty] | Configuration to add a config management plugin. [**Controller**](#controller-options) | [Object] | Argo CD Application Controller options. [**DisableAdmin**](#disable-admin) | `false` | Disable the admin user. @@ -156,6 +157,25 @@ data: -----END CERTIFICATE----- ``` +## Clusters + +Defines options related to cluster management in Argo CD. Currently, it only allows customization of the local cluster's name. + +### Local 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: argocd +spec: + clusters: + local: + name: example-cluster +``` + ## Config Management Plugins Configuration to add a config management plugin. This property maps directly to the `configManagementPlugins` field in the `argocd-cm` ConfigMap. diff --git a/tests/k8s/1-044_validate_cluster_name/01-assert.yaml b/tests/k8s/1-044_validate_cluster_name/01-assert.yaml new file mode 100644 index 000000000..cf300f961 --- /dev/null +++ b/tests/k8s/1-044_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-044_validate_cluster_name/01-install.yaml b/tests/k8s/1-044_validate_cluster_name/01-install.yaml new file mode 100644 index 000000000..3ec153b5b --- /dev/null +++ b/tests/k8s/1-044_validate_cluster_name/01-install.yaml @@ -0,0 +1,8 @@ +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: argocd +spec: + clusters: + local: + name: test-cluster diff --git a/tests/k8s/1-044_validate_cluster_name/02-assert.yaml b/tests/k8s/1-044_validate_cluster_name/02-assert.yaml new file mode 100644 index 000000000..943d5eba5 --- /dev/null +++ b/tests/k8s/1-044_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-044_validate_cluster_name/02-install.yaml b/tests/k8s/1-044_validate_cluster_name/02-install.yaml new file mode 100644 index 000000000..2a4e8fa81 --- /dev/null +++ b/tests/k8s/1-044_validate_cluster_name/02-install.yaml @@ -0,0 +1,8 @@ +apiVersion: argoproj.io/v1beta1 +kind: ArgoCD +metadata: + name: argocd +spec: + clusters: + local: + name: another-test-cluster