Skip to content

Commit

Permalink
feat: Add option to customize local cluster name
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Huber <[email protected]>
  • Loading branch information
ItsKev authored Oct 4, 2024
1 parent 3334487 commit 92127a8
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 3 deletions.
18 changes: 18 additions & 0 deletions api/v1beta1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,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 {
Expand All @@ -778,6 +792,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"`
Expand Down
32 changes: 32 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion bundle/manifests/argocd-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ metadata:
capabilities: Deep Insights
categories: Integration & Delivery
certified: "false"
createdAt: "2024-09-16T21:29:22Z"
createdAt: "2024-10-04T06:51:46Z"
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
Expand Down Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions bundle/manifests/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7679,6 +7679,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.
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7668,6 +7668,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 9 additions & 1 deletion controllers/argocd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")),
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
14 changes: 14 additions & 0 deletions controllers/argocd/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ metadata:
capabilities: Deep Insights
categories: Integration & Delivery
certified: "false"
createdAt: "2024-09-16T21:29:22Z"
createdAt: "2024-10-04T06:51:46Z"
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
Expand Down Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions deploy/olm-catalog/argocd-operator/0.13.0/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7679,6 +7679,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.
Expand Down
20 changes: 20 additions & 0 deletions docs/reference/argocd.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 `<argocd-name>-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.
Expand Down
17 changes: 17 additions & 0 deletions tests/k8s/1-044_validate_cluster_name/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/k8s/1-044_validate_cluster_name/01-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd
spec:
clusters:
local:
name: test-cluster
17 changes: 17 additions & 0 deletions tests/k8s/1-044_validate_cluster_name/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/k8s/1-044_validate_cluster_name/02-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd
spec:
clusters:
local:
name: another-test-cluster

0 comments on commit 92127a8

Please sign in to comment.