@@ -66,15 +66,15 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
66
66
// The object is not being deleted, so if it does not have our finalizer,
67
67
// then lets add the finalizer and update the object. This is equivalent
68
68
// registering our finalizer.
69
- if ! containsString ( cronJob . GetFinalizers () , myFinalizerName ) {
69
+ if ! controllerutil . ContainsFinalizer ( cronJob , myFinalizerName ) {
70
70
controllerutil .AddFinalizer (cronJob , myFinalizerName )
71
71
if err := r .Update (ctx , cronJob ); err != nil {
72
72
return ctrl.Result {}, err
73
73
}
74
74
}
75
75
} else {
76
76
// The object is being deleted
77
- if containsString ( cronJob . GetFinalizers () , myFinalizerName ) {
77
+ if controllerutil . ContainsFinalizer ( cronJob , myFinalizerName ) {
78
78
// our finalizer is present, so lets handle any external dependency
79
79
if err := r .deleteExternalResources (cronJob ); err != nil {
80
80
// if fail to delete the external dependency here, return with error
@@ -106,12 +106,3 @@ func (r *Reconciler) deleteExternalResources(cronJob *batch.CronJob) error {
106
106
// multiple times for same object.
107
107
}
108
108
109
- // Helper functions to check and remove string from a slice of strings.
110
- func containsString (slice []string , s string ) bool {
111
- for _ , item := range slice {
112
- if item == s {
113
- return true
114
- }
115
- }
116
- return false
117
- }
0 commit comments