From a6aed505f588ff2be7be8e5b6be1c58c25d1f6b3 Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Wed, 20 Dec 2023 08:43:37 -0300 Subject: [PATCH] Add a .status.managed_cache_enabled field This field will be helpful to avoid running the cache deprovisioning task in every reconciliation loop. [noissue] --- .../v1beta2/pulp_types.go | 2 ++ .../pulp-operator.clusterserviceversion.yaml | 2 +- .../repo-manager.pulpproject.org_pulps.yaml | 3 +++ .../bases/repo-manager.pulpproject.org_pulps.yaml | 3 +++ controllers/repo_manager/README.md | 1 + controllers/repo_manager/controller.go | 6 ++++-- controllers/repo_manager/redis.go | 15 +++++++++++++++ 7 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go b/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go index 031108d19..6959cae4b 100644 --- a/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go +++ b/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go @@ -948,6 +948,8 @@ type PulpStatus struct { AllowedContentChecksums string `json:"allowed_content_checksums,omitempty"` // Controller status to keep tracking of deployment updates LastDeploymentUpdate string `json:"last_deployment_update,omitempty"` + // Cache deployed by pulp-operator enabled + ManagedCacheEnabled bool `json:"managed_cache_enabled,omitempty"` } // +kubebuilder:object:root=true diff --git a/bundle/manifests/pulp-operator.clusterserviceversion.yaml b/bundle/manifests/pulp-operator.clusterserviceversion.yaml index 9d33511b4..9d980df57 100644 --- a/bundle/manifests/pulp-operator.clusterserviceversion.yaml +++ b/bundle/manifests/pulp-operator.clusterserviceversion.yaml @@ -168,7 +168,7 @@ metadata: capabilities: Full Lifecycle categories: Integration & Delivery containerImage: quay.io/pulp/pulp-operator:devel - createdAt: "2023-12-05T11:18:07Z" + createdAt: "2023-12-20T11:42:34Z" description: Pulp is a platform for managing repositories of software packages and making them available to a large number of consumers. operators.operatorframework.io/builder: operator-sdk-v1.29.0 diff --git a/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml b/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml index 899bb6afb..85db2532e 100644 --- a/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml +++ b/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml @@ -10015,6 +10015,9 @@ spec: last_deployment_update: description: Controller status to keep tracking of deployment updates type: string + managed_cache_enabled: + description: Cache deployed by pulp-operator enabled + type: boolean object_storage_azure_secret: description: The secret for Azure compliant object storage configuration. type: string diff --git a/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml b/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml index 2e8b9f0ed..8fb1751c1 100644 --- a/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml +++ b/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml @@ -10016,6 +10016,9 @@ spec: last_deployment_update: description: Controller status to keep tracking of deployment updates type: string + managed_cache_enabled: + description: Cache deployed by pulp-operator enabled + type: boolean object_storage_azure_secret: description: The secret for Azure compliant object storage configuration. type: string diff --git a/controllers/repo_manager/README.md b/controllers/repo_manager/README.md index 3225da45f..8f18ccbe7 100644 --- a/controllers/repo_manager/README.md +++ b/controllers/repo_manager/README.md @@ -263,6 +263,7 @@ PulpStatus defines the observed state of Pulp | pulp_secret_key | Name of the Secret to provide Django cryptographic signing. | string | false | | allowed_content_checksums | List of allowed checksum algorithms used to verify repository's integrity. | string | false | | last_deployment_update | Controller status to keep tracking of deployment updates | string | false | +| managed_cache_enabled | Cache deployed by pulp-operator enabled | bool | false | [Back to Custom Resources](#custom-resources) diff --git a/controllers/repo_manager/controller.go b/controllers/repo_manager/controller.go index 1553181aa..f7f76882b 100644 --- a/controllers/repo_manager/controller.go +++ b/controllers/repo_manager/controller.go @@ -290,8 +290,10 @@ func cacheTasks(ctx context.Context, pulp *repomanagerpulpprojectorgv1beta2.Pulp return &pulpController, err } - // remove redis resources if cache is not enabled - } else { + } + + // remove redis resources if cache is not enabled anymore + if managedCacheDisabled(pulp) { pulpController, err := r.deprovisionCache(ctx, pulp, log) if needsRequeue(err, pulpController) { return &pulpController, err diff --git a/controllers/repo_manager/redis.go b/controllers/repo_manager/redis.go index 6533a77bf..301df66b1 100644 --- a/controllers/repo_manager/redis.go +++ b/controllers/repo_manager/redis.go @@ -131,6 +131,10 @@ func (r *RepoManagerReconciler) pulpCacheController(ctx context.Context, pulp *r return ctrl.Result{Requeue: requeue}, err } + // Update managedCache status + pulp.Status.ManagedCacheEnabled = pulp.Spec.Cache.Enabled + r.Status().Update(ctx, pulp) + r.recorder.Event(pulp, corev1.EventTypeNormal, "RedisReady", "All Redis tasks ran successfully") return ctrl.Result{}, nil @@ -402,6 +406,10 @@ func (r *RepoManagerReconciler) deprovisionCache(ctx context.Context, pulp *repo r.Delete(ctx, deploymentFound) } + // Update managedCache status + pulp.Status.ManagedCacheEnabled = pulp.Spec.Cache.Enabled + r.Status().Update(ctx, pulp) + return ctrl.Result{}, nil } @@ -410,3 +418,10 @@ func (r *RepoManagerReconciler) deprovisionCache(ctx context.Context, pulp *repo func labelsForCache(m *repomanagerpulpprojectorgv1beta2.Pulp) map[string]string { return settings.PulpcoreLabels(*m, "cache") } + +// managedCacheDisabled returns true if +// * there is no definition for external cache +// * the managed cache (deployed by pulp-operator) has a different definition than the status +func managedCacheDisabled(pulp *repomanagerpulpprojectorgv1beta2.Pulp) bool { + return len(pulp.Spec.Cache.ExternalCacheSecret) == 0 && pulp.Spec.Cache.Enabled != pulp.Status.ManagedCacheEnabled +}