Skip to content

Commit

Permalink
Add a .status.managed_cache_enabled field
Browse files Browse the repository at this point in the history
This field will be helpful to avoid running the cache deprovisioning
task in every reconciliation loop.
[noissue]
  • Loading branch information
git-hyagi committed Dec 20, 2023
1 parent 9318af5 commit a6aed50
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bundle/manifests/pulp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bundle/manifests/repo-manager.pulpproject.org_pulps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/repo-manager.pulpproject.org_pulps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions controllers/repo_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions controllers/repo_manager/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions controllers/repo_manager/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit a6aed50

Please sign in to comment.