From 669c43ba47a5147263924b306c883f1e22186103 Mon Sep 17 00:00:00 2001 From: ishitasequeira Date: Wed, 18 Oct 2023 23:23:39 -0400 Subject: [PATCH] allow enabling ArgoCD workloads independently Signed-off-by: ishitasequeira --- api/v1alpha1/argocd_types.go | 7 ++++ api/v1alpha1/zz_generated.deepcopy.go | 10 ++++++ api/v1beta1/argocd_types.go | 16 ++++++++++ api/v1beta1/zz_generated.deepcopy.go | 25 +++++++++++++++ bundle/manifests/argoproj.io_argocds.yaml | 28 ++++++++++++++++ config/crd/bases/argoproj.io_argocds.yaml | 28 ++++++++++++++++ controllers/argocd/deployment.go | 32 +++++++++++++++++++ controllers/argocd/statefulset.go | 19 +++++++++-- controllers/argocd/util.go | 4 +++ .../0.8.0/argoproj.io_argocds.yaml | 28 ++++++++++++++++ 10 files changed, 195 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/argocd_types.go b/api/v1alpha1/argocd_types.go index ae5ef8326..cea61837a 100644 --- a/api/v1alpha1/argocd_types.go +++ b/api/v1alpha1/argocd_types.go @@ -407,6 +407,10 @@ type ArgoCDRedisSpec struct { // The value specified here can currently be: // - openshift - Use the OpenShift service CA to request TLS config AutoTLS string `json:"autotls,omitempty"` + + // Enabled is the flag to enable Redis during ArgoCD installation. (optional, default `true`) + // +optional + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDRepoSpec defines the desired state for the Argo CD repo server component. @@ -467,6 +471,9 @@ type ArgoCDRepoSpec struct { // SidecarContainers defines the list of sidecar containers for the repo server deployment SidecarContainers []corev1.Container `json:"sidecarContainers,omitempty"` + + // Enabled is the flag to enable Repo Server during ArgoCD installation. (optional, default `true`) + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDRouteSpec defines the desired state for an OpenShift Route. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index cbd6307b8..af5898d4a 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -632,6 +632,11 @@ func (in *ArgoCDRedisSpec) DeepCopyInto(out *ArgoCDRedisSpec) { *out = new(v1.ResourceRequirements) (*in).DeepCopyInto(*out) } + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDRedisSpec. @@ -702,6 +707,11 @@ func (in *ArgoCDRepoSpec) DeepCopyInto(out *ArgoCDRepoSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDRepoSpec. diff --git a/api/v1beta1/argocd_types.go b/api/v1beta1/argocd_types.go index 5c55851f4..79784ee70 100644 --- a/api/v1beta1/argocd_types.go +++ b/api/v1beta1/argocd_types.go @@ -108,6 +108,9 @@ type ArgoCDApplicationControllerSpec struct { // Env lets you specify environment for application controller pods Env []corev1.EnvVar `json:"env,omitempty"` + + // Enabled is the flag to enable the Application Controller during ArgoCD installation. (optional, default `true`) + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDApplicationControllerShardSpec defines the options available for enabling sharding for the Application Controller component. @@ -162,6 +165,9 @@ type ArgoCDApplicationSet struct { // SCMRootCAConfigMap is the name of the config map that stores the Gitlab SCM Provider's TLS certificate which will be mounted on the ApplicationSet Controller (optional). SCMRootCAConfigMap string `json:"scmRootCAConfigMap,omitempty"` + + // Enabled is the flag to enable the Application Set Controller during ArgoCD installation. (optional, default `true`) + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDCASpec defines the CA options for ArgCD. @@ -410,6 +416,10 @@ type ArgoCDRedisSpec struct { // The value specified here can currently be: // - openshift - Use the OpenShift service CA to request TLS config AutoTLS string `json:"autotls,omitempty"` + + // Enabled is the flag to enable Redis during ArgoCD installation. (optional, default `true`) + // +optional + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDRepoSpec defines the desired state for the Argo CD repo server component. @@ -470,6 +480,9 @@ type ArgoCDRepoSpec struct { // SidecarContainers defines the list of sidecar containers for the repo server deployment SidecarContainers []corev1.Container `json:"sidecarContainers,omitempty"` + + // Enabled is the flag to enable Repo Server during ArgoCD installation. (optional, default `true`) + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDRouteSpec defines the desired state for an OpenShift Route. @@ -560,6 +573,9 @@ type ArgoCDServerSpec struct { // ExtraCommandArgs will not be added, if one of these commands is already part of the server command // with same or different value. ExtraCommandArgs []string `json:"extraCommandArgs,omitempty"` + + // Enabled is the flag to enable ArgoCD Server during ArgoCD installation. (optional, default `true`) + Enabled *bool `json:"enabled,omitempty"` } // ArgoCDServerServiceSpec defines the Service options for Argo CD Server component. diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 864d81bca..6c2bb62eb 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -114,6 +114,11 @@ func (in *ArgoCDApplicationControllerSpec) DeepCopyInto(out *ArgoCDApplicationCo (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDApplicationControllerSpec. @@ -147,6 +152,11 @@ func (in *ArgoCDApplicationSet) DeepCopyInto(out *ArgoCDApplicationSet) { (*in).DeepCopyInto(*out) } in.WebhookServer.DeepCopyInto(&out.WebhookServer) + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDApplicationSet. @@ -513,6 +523,11 @@ func (in *ArgoCDRedisSpec) DeepCopyInto(out *ArgoCDRedisSpec) { *out = new(v1.ResourceRequirements) (*in).DeepCopyInto(*out) } + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDRedisSpec. @@ -583,6 +598,11 @@ func (in *ArgoCDRepoSpec) DeepCopyInto(out *ArgoCDRepoSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDRepoSpec. @@ -740,6 +760,11 @@ func (in *ArgoCDServerSpec) DeepCopyInto(out *ArgoCDServerSpec) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.Enabled != nil { + in, out := &in.Enabled, &out.Enabled + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ArgoCDServerSpec. diff --git a/bundle/manifests/argoproj.io_argocds.yaml b/bundle/manifests/argoproj.io_argocds.yaml index f0a7218e7..137ba9033 100644 --- a/bundle/manifests/argoproj.io_argocds.yaml +++ b/bundle/manifests/argoproj.io_argocds.yaml @@ -1356,6 +1356,10 @@ spec: description: DisableTLSVerification defines whether redis server API should be accessed using strict TLS validation type: boolean + enabled: + description: Enabled is the flag to enable Redis during ArgoCD + installation. (optional, default `true`) + type: boolean image: description: Image is the Redis container image. type: string @@ -1399,6 +1403,10 @@ spec: can currently be: - openshift - Use the OpenShift service CA to request TLS config' type: string + enabled: + description: Enabled is the flag to enable Repo Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for repo server pods @@ -6500,6 +6508,10 @@ spec: description: ArgoCDApplicationSet defines whether the Argo CD ApplicationSet controller should be installed. properties: + enabled: + description: Enabled is the flag to enable the Application Set + Controller during ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for applicationSet controller pods @@ -6829,6 +6841,10 @@ spec: to a duration, e.g. 10m or 600s to control the synchronisation frequency." type: string + enabled: + description: Enabled is the flag to enable the Application Controller + during ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for application controller pods @@ -7753,6 +7769,10 @@ spec: description: DisableTLSVerification defines whether redis server API should be accessed using strict TLS validation type: boolean + enabled: + description: Enabled is the flag to enable Redis during ArgoCD + installation. (optional, default `true`) + type: boolean image: description: Image is the Redis container image. type: string @@ -7796,6 +7816,10 @@ spec: can currently be: - openshift - Use the OpenShift service CA to request TLS config' type: string + enabled: + description: Enabled is the flag to enable Repo Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for repo server pods @@ -12200,6 +12224,10 @@ spec: required: - enabled type: object + enabled: + description: Enabled is the flag to enable ArgoCD Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for API server pods items: diff --git a/config/crd/bases/argoproj.io_argocds.yaml b/config/crd/bases/argoproj.io_argocds.yaml index c00bc7677..eb6f00131 100644 --- a/config/crd/bases/argoproj.io_argocds.yaml +++ b/config/crd/bases/argoproj.io_argocds.yaml @@ -1347,6 +1347,10 @@ spec: description: DisableTLSVerification defines whether redis server API should be accessed using strict TLS validation type: boolean + enabled: + description: Enabled is the flag to enable Redis during ArgoCD + installation. (optional, default `true`) + type: boolean image: description: Image is the Redis container image. type: string @@ -1390,6 +1394,10 @@ spec: can currently be: - openshift - Use the OpenShift service CA to request TLS config' type: string + enabled: + description: Enabled is the flag to enable Repo Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for repo server pods @@ -6491,6 +6499,10 @@ spec: description: ArgoCDApplicationSet defines whether the Argo CD ApplicationSet controller should be installed. properties: + enabled: + description: Enabled is the flag to enable the Application Set + Controller during ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for applicationSet controller pods @@ -6820,6 +6832,10 @@ spec: to a duration, e.g. 10m or 600s to control the synchronisation frequency." type: string + enabled: + description: Enabled is the flag to enable the Application Controller + during ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for application controller pods @@ -7744,6 +7760,10 @@ spec: description: DisableTLSVerification defines whether redis server API should be accessed using strict TLS validation type: boolean + enabled: + description: Enabled is the flag to enable Redis during ArgoCD + installation. (optional, default `true`) + type: boolean image: description: Image is the Redis container image. type: string @@ -7787,6 +7807,10 @@ spec: can currently be: - openshift - Use the OpenShift service CA to request TLS config' type: string + enabled: + description: Enabled is the flag to enable Repo Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for repo server pods @@ -12191,6 +12215,10 @@ spec: required: - enabled type: object + enabled: + description: Enabled is the flag to enable ArgoCD Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for API server pods items: diff --git a/controllers/argocd/deployment.go b/controllers/argocd/deployment.go index 6b247c9c8..0608a83ab 100644 --- a/controllers/argocd/deployment.go +++ b/controllers/argocd/deployment.go @@ -624,6 +624,11 @@ func (r *ReconcileArgoCD) reconcileRedisDeployment(cr *argoproj.ArgoCD, useTLS b existing := newDeploymentWithSuffix("redis", "redis", cr) if argoutil.IsObjectFound(r.Client, cr.Namespace, existing.Name, existing) { + if !IsComponentEnabled(cr.Spec.Redis.Enabled) { + // Deployment exists but component enabled flag has been set to false, delete the Deployment + log.Info("Redis exists but should be disabled. Deleting existing redis.") + return r.Client.Delete(context.TODO(), deploy) + } if cr.Spec.HA.Enabled { // Deployment exists but HA enabled flag has been set to true, delete the Deployment return r.Client.Delete(context.TODO(), deploy) @@ -660,6 +665,11 @@ func (r *ReconcileArgoCD) reconcileRedisDeployment(cr *argoproj.ArgoCD, useTLS b return nil // Deployment found with nothing to do, move along... } + if !IsComponentEnabled(cr.Spec.Redis.Enabled) { + log.Info("Redis disabled. Skipping starting redis.") + return nil + } + if cr.Spec.HA.Enabled { return nil // HA enabled, do nothing. } @@ -1103,6 +1113,13 @@ func (r *ReconcileArgoCD) reconcileRepoDeployment(cr *argoproj.ArgoCD, useTLSFor existing := newDeploymentWithSuffix("repo-server", "repo-server", cr) if argoutil.IsObjectFound(r.Client, cr.Namespace, existing.Name, existing) { + + if !IsComponentEnabled(cr.Spec.Repo.Enabled) { + log.Info("Existing ArgoCD Repo Server found but should be disabled. Deleting Repo Server") + // Delete existing deployment for ArgoCD Repo Server, if any .. + return nil + } + changed := false actualImage := existing.Spec.Template.Spec.Containers[0].Image desiredImage := getRepoServerContainerImage(cr) @@ -1171,6 +1188,11 @@ func (r *ReconcileArgoCD) reconcileRepoDeployment(cr *argoproj.ArgoCD, useTLSFor return nil // Deployment found with nothing to do, move along... } + if !IsComponentEnabled(cr.Spec.Repo.Enabled) { + log.Info("ArgoCD Repo disabled. Skipping starting ArgoCD Repo.") + return nil + } + if err := controllerutil.SetControllerReference(cr, deploy, r.Scheme); err != nil { return err } @@ -1292,6 +1314,11 @@ func (r *ReconcileArgoCD) reconcileServerDeployment(cr *argoproj.ArgoCD, useTLSF existing := newDeploymentWithSuffix("server", "server", cr) if argoutil.IsObjectFound(r.Client, cr.Namespace, existing.Name, existing) { + if !IsComponentEnabled(cr.Spec.Server.Enabled) { + log.Info("Existing ArgoCD Server found but should be disabled. Deleting ArgoCD Server") + // Delete existing deployment for ArgoCD Server, if any .. + return nil + } actualImage := existing.Spec.Template.Spec.Containers[0].Image desiredImage := getArgoContainerImage(cr) changed := false @@ -1337,6 +1364,11 @@ func (r *ReconcileArgoCD) reconcileServerDeployment(cr *argoproj.ArgoCD, useTLSF return nil // Deployment found with nothing to do, move along... } + if !IsComponentEnabled(cr.Spec.Controller.Enabled) { + log.Info("ArgoCD Repo Server disabled. Skipping starting repo server.") + return nil + } + if err := controllerutil.SetControllerReference(cr, deploy, r.Scheme); err != nil { return err } diff --git a/controllers/argocd/statefulset.go b/controllers/argocd/statefulset.go index 0cefa8463..463b70b8e 100644 --- a/controllers/argocd/statefulset.go +++ b/controllers/argocd/statefulset.go @@ -391,8 +391,8 @@ func (r *ReconcileArgoCD) reconcileRedisStatefulSet(cr *argoproj.ArgoCD) error { existing := newStatefulSetWithSuffix("redis-ha-server", "redis", cr) if argoutil.IsObjectFound(r.Client, cr.Namespace, existing.Name, existing) { - if !cr.Spec.HA.Enabled { - // StatefulSet exists but HA enabled flag has been set to false, delete the StatefulSet + if !(cr.Spec.HA.Enabled && IsComponentEnabled(cr.Spec.Redis.Enabled)) { + // StatefulSet exists but either HA or component enabled flag has been set to false, delete the StatefulSet return r.Client.Delete(context.TODO(), existing) } @@ -424,6 +424,11 @@ func (r *ReconcileArgoCD) reconcileRedisStatefulSet(cr *argoproj.ArgoCD) error { return nil // StatefulSet found, do nothing } + if !IsComponentEnabled(cr.Spec.Redis.Enabled) { + log.Info("Redis disabled. Skipping starting Redis.") // Redis not enabled, do nothing. + return nil + } + if !cr.Spec.HA.Enabled { return nil // HA not enabled, do nothing. } @@ -649,6 +654,11 @@ func (r *ReconcileArgoCD) reconcileApplicationControllerStatefulSet(cr *argoproj existing := newStatefulSetWithSuffix("application-controller", "application-controller", cr) if argoutil.IsObjectFound(r.Client, cr.Namespace, existing.Name, existing) { + if !IsComponentEnabled(cr.Spec.Controller.Enabled) { + log.Info("Existing application controller found but should be disabled. Deleting Application Controller") + // Delete existing deployment for Application Controller, if any .. + return r.Client.Delete(context.TODO(), existing) + } actualImage := existing.Spec.Template.Spec.Containers[0].Image desiredImage := getArgoContainerImage(cr) changed := false @@ -696,6 +706,11 @@ func (r *ReconcileArgoCD) reconcileApplicationControllerStatefulSet(cr *argoproj return nil // StatefulSet found with nothing to do, move along... } + if !IsComponentEnabled(cr.Spec.Controller.Enabled) { + log.Info("Application Controller disabled. Skipping starting application controller.") + return nil + } + // Delete existing deployment for Application Controller, if any .. deploy := newDeploymentWithSuffix("application-controller", "application-controller", cr) if argoutil.IsObjectFound(r.Client, deploy.Namespace, deploy.Name, deploy) { diff --git a/controllers/argocd/util.go b/controllers/argocd/util.go index 17680c131..63a7a0ae5 100644 --- a/controllers/argocd/util.go +++ b/controllers/argocd/util.go @@ -1602,3 +1602,7 @@ func getApplicationSetHTTPServerHost(cr *argoproj.ArgoCD) string { } return host } + +func IsComponentEnabled(enabled *bool) bool { + return enabled == nil || (enabled != nil && *enabled == true) +} diff --git a/deploy/olm-catalog/argocd-operator/0.8.0/argoproj.io_argocds.yaml b/deploy/olm-catalog/argocd-operator/0.8.0/argoproj.io_argocds.yaml index f0a7218e7..137ba9033 100644 --- a/deploy/olm-catalog/argocd-operator/0.8.0/argoproj.io_argocds.yaml +++ b/deploy/olm-catalog/argocd-operator/0.8.0/argoproj.io_argocds.yaml @@ -1356,6 +1356,10 @@ spec: description: DisableTLSVerification defines whether redis server API should be accessed using strict TLS validation type: boolean + enabled: + description: Enabled is the flag to enable Redis during ArgoCD + installation. (optional, default `true`) + type: boolean image: description: Image is the Redis container image. type: string @@ -1399,6 +1403,10 @@ spec: can currently be: - openshift - Use the OpenShift service CA to request TLS config' type: string + enabled: + description: Enabled is the flag to enable Repo Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for repo server pods @@ -6500,6 +6508,10 @@ spec: description: ArgoCDApplicationSet defines whether the Argo CD ApplicationSet controller should be installed. properties: + enabled: + description: Enabled is the flag to enable the Application Set + Controller during ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for applicationSet controller pods @@ -6829,6 +6841,10 @@ spec: to a duration, e.g. 10m or 600s to control the synchronisation frequency." type: string + enabled: + description: Enabled is the flag to enable the Application Controller + during ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for application controller pods @@ -7753,6 +7769,10 @@ spec: description: DisableTLSVerification defines whether redis server API should be accessed using strict TLS validation type: boolean + enabled: + description: Enabled is the flag to enable Redis during ArgoCD + installation. (optional, default `true`) + type: boolean image: description: Image is the Redis container image. type: string @@ -7796,6 +7816,10 @@ spec: can currently be: - openshift - Use the OpenShift service CA to request TLS config' type: string + enabled: + description: Enabled is the flag to enable Repo Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for repo server pods @@ -12200,6 +12224,10 @@ spec: required: - enabled type: object + enabled: + description: Enabled is the flag to enable ArgoCD Server during + ArgoCD installation. (optional, default `true`) + type: boolean env: description: Env lets you specify environment for API server pods items: