Skip to content

Commit

Permalink
feat: Add option to customize in-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 Jan 12, 2024
1 parent acee651 commit ea64f57
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/v1beta1/argocd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 7 additions & 0 deletions bundle/manifests/argocd-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions bundle/manifests/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/argoproj.io_argocds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 9 additions & 1 deletion controllers/argocd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")),
}
Expand Down Expand Up @@ -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)
}
}
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 @@ -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"]))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions docs/reference/argocd.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 `<argocd-name>-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.
Expand Down
17 changes: 17 additions & 0 deletions tests/k8s/1-036_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
6 changes: 6 additions & 0 deletions tests/k8s/1-036_validate_cluster_name/01-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd
spec:
inClusterName: test-cluster
17 changes: 17 additions & 0 deletions tests/k8s/1-036_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
6 changes: 6 additions & 0 deletions tests/k8s/1-036_validate_cluster_name/02-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: argoproj.io/v1beta1
kind: ArgoCD
metadata:
name: argocd
spec:
inClusterName: another-test-cluster

0 comments on commit ea64f57

Please sign in to comment.