Skip to content

Commit 5e1cd22

Browse files
black-dragon74mergify[bot]
authored andcommitted
controller: remove the shim for GCing old resources
This patch removes the shim layer that was responsible for cleanup of old style named reclaimspace/Keyrotation resources in the cluster. Note: We do not yet enforce StorageClass as the precedence upstream. If we choose to do that someday, the changes reverted in this patch would be required for migration (in a doc maybe?) Reverts: 0b93f39 Signed-off-by: Niraj Yadav <niryadav@redhat.com>
1 parent b158773 commit 5e1cd22

3 files changed

Lines changed: 0 additions & 93 deletions

File tree

internal/controller/csiaddons/pvc_new_controller.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,6 @@ func (r *PVCReconiler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
115115
},
116116
}
117117

118-
// FIXME: This is a shim and should be removed in later releases
119-
// along with the field indexers on child objects
120-
if requeue, err := utils.CleanOldJobs(ctx,
121-
r.Client,
122-
logger,
123-
req,
124-
&csiaddonsv1alpha1.EncryptionKeyRotationCronJobList{},
125-
keyRotationName); err != nil || requeue {
126-
return ctrl.Result{Requeue: requeue}, err
127-
}
128-
129118
if err := r.reconcileFeature(ctx, logger, pvc, keyRotationChild, keyRotationSched, keyRotationEnabled); err != nil {
130119
return ctrl.Result{}, err
131120
}
@@ -140,17 +129,6 @@ func (r *PVCReconiler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
140129
},
141130
}
142131

143-
// FIXME: This is a shim and should be removed in later releases
144-
// along with the field indexers on child objects
145-
if requeue, err := utils.CleanOldJobs(ctx,
146-
r.Client,
147-
logger,
148-
req,
149-
&csiaddonsv1alpha1.ReclaimSpaceCronJobList{},
150-
reclaimSpaceName); err != nil || requeue {
151-
return ctrl.Result{Requeue: requeue}, err
152-
}
153-
154132
if err := r.reconcileFeature(ctx, logger, pvc, reclaimSpaceChild, reclaimSpaceSched, "true"); err != nil {
155133
return ctrl.Result{}, err
156134
}

internal/controller/utils/predicates.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package utils
1919
import (
2020
"context"
2121

22-
csiaddonsv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/csiaddons/v1alpha1"
23-
2422
corev1 "k8s.io/api/core/v1"
2523
storagev1 "k8s.io/api/storage/v1"
2624
"k8s.io/apimachinery/pkg/types"
@@ -108,18 +106,6 @@ func SetupPVCControllerIndexers(mgr ctrl.Manager) error {
108106
return []string{*pvc.Spec.StorageClassName}
109107
},
110108
},
111-
// FIXME: Remove this shim in later releases
112-
{
113-
obj: &csiaddonsv1alpha1.ReclaimSpaceCronJob{},
114-
field: JobOwnerKey,
115-
indexFn: ExtractOwnerNameFromPVCObj[*csiaddonsv1alpha1.ReclaimSpaceCronJob],
116-
},
117-
// FIXME: Remove this shim in later releases
118-
{
119-
obj: &csiaddonsv1alpha1.EncryptionKeyRotationCronJob{},
120-
field: JobOwnerKey,
121-
indexFn: ExtractOwnerNameFromPVCObj[*csiaddonsv1alpha1.EncryptionKeyRotationCronJob],
122-
},
123109
}
124110

125111
for _, index := range indices {

internal/controller/utils/reclaimspace_keyrotation.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ limitations under the License.
1717
package utils
1818

1919
import (
20-
"context"
2120
"errors"
2221

2322
csiaddonsv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/api/csiaddons/v1alpha1"
2423

25-
"github.com/go-logr/logr"
26-
"k8s.io/apimachinery/pkg/api/meta"
2724
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28-
ctrl "sigs.k8s.io/controller-runtime"
2925
"sigs.k8s.io/controller-runtime/pkg/client"
3026
)
3127

@@ -132,56 +128,3 @@ func ExtractOwnerNameFromPVCObj[T client.Object](rawObj client.Object) []string
132128

133129
return []string{owner.Name}
134130
}
135-
136-
func CleanOldJobs(
137-
ctx context.Context,
138-
c client.Client,
139-
log logr.Logger,
140-
req ctrl.Request,
141-
objList client.ObjectList,
142-
expectedName string,
143-
) (bool, error) {
144-
// We need to find all the CronJobs in the namespace of the PVC which
145-
// are owned by this controller and remove it if it doesn't match the expected name
146-
shouldRequeue := false
147-
148-
if err := c.List(ctx, objList, client.InNamespace(req.Namespace), client.MatchingFields{JobOwnerKey: req.Name}); client.IgnoreNotFound(err) != nil {
149-
return shouldRequeue, err
150-
}
151-
152-
items, err := meta.ExtractList(objList)
153-
if err != nil {
154-
return shouldRequeue, err
155-
}
156-
157-
for _, item := range items {
158-
obj, ok := item.(client.Object)
159-
if !ok {
160-
// As long as objList is a k8s object
161-
// we will never hit this
162-
continue
163-
}
164-
objName := obj.GetName()
165-
166-
// Only delete what we might have created
167-
if owner := metav1.GetControllerOf(obj); owner == nil ||
168-
owner.Kind != "PersistentVolumeClaim" ||
169-
owner.Name != req.Name {
170-
log.Info("Found an object without any owner", "jobName", objName)
171-
172-
continue
173-
}
174-
175-
// If the name does not match, delete the resource
176-
if objName != expectedName {
177-
if err := c.Delete(ctx, obj); client.IgnoreNotFound(err) != nil {
178-
return shouldRequeue, err
179-
}
180-
181-
shouldRequeue = true
182-
log.Info("Deleted old job", "jobName", objName)
183-
}
184-
}
185-
186-
return shouldRequeue, nil
187-
}

0 commit comments

Comments
 (0)