Skip to content

Commit 4c7b43a

Browse files
authored
Merge pull request #962 from dmvolod/issue-959
✨ Migrate controllerutil AddFinalizer and RemoveFinalizer to controllerutil.Object and deprecate *WithError functions
2 parents 2f1457b + 0222c26 commit 4c7b43a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

pkg/controller/controllerutil/controllerutil.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ func mutate(f MutateFn, key client.ObjectKey, obj runtime.Object) error {
237237
// MutateFn is a function which mutates the existing object into it's desired state.
238238
type MutateFn func() error
239239

240-
// AddFinalizer accepts a metav1 object and adds the provided finalizer if not present.
241-
func AddFinalizer(o metav1.Object, finalizer string) {
240+
// AddFinalizer accepts an Object and adds the provided finalizer if not present.
241+
func AddFinalizer(o Object, finalizer string) {
242242
f := o.GetFinalizers()
243243
for _, e := range f {
244244
if e == finalizer {
@@ -250,17 +250,19 @@ func AddFinalizer(o metav1.Object, finalizer string) {
250250

251251
// AddFinalizerWithError tries to convert a runtime object to a metav1 object and add the provided finalizer.
252252
// It returns an error if the provided object cannot provide an accessor.
253+
//
254+
// Deprecated: Use AddFinalizer instead. Check is performing on compile time.
253255
func AddFinalizerWithError(o runtime.Object, finalizer string) error {
254256
m, err := meta.Accessor(o)
255257
if err != nil {
256258
return err
257259
}
258-
AddFinalizer(m, finalizer)
260+
AddFinalizer(m.(Object), finalizer)
259261
return nil
260262
}
261263

262-
// RemoveFinalizer accepts a metav1 object and removes the provided finalizer if present.
263-
func RemoveFinalizer(o metav1.Object, finalizer string) {
264+
// RemoveFinalizer accepts an Object and removes the provided finalizer if present.
265+
func RemoveFinalizer(o Object, finalizer string) {
264266
f := o.GetFinalizers()
265267
for i := 0; i < len(f); i++ {
266268
if f[i] == finalizer {
@@ -273,16 +275,18 @@ func RemoveFinalizer(o metav1.Object, finalizer string) {
273275

274276
// RemoveFinalizerWithError tries to convert a runtime object to a metav1 object and remove the provided finalizer.
275277
// It returns an error if the provided object cannot provide an accessor.
278+
//
279+
// Deprecated: Use RemoveFinalizer instead. Check is performing on compile time.
276280
func RemoveFinalizerWithError(o runtime.Object, finalizer string) error {
277281
m, err := meta.Accessor(o)
278282
if err != nil {
279283
return err
280284
}
281-
RemoveFinalizer(m, finalizer)
285+
RemoveFinalizer(m.(Object), finalizer)
282286
return nil
283287
}
284288

285-
// ContainsFinalizer checks a metav1 object that the provided finalizer is present.
289+
// ContainsFinalizer checks an Object that the provided finalizer is present.
286290
func ContainsFinalizer(o Object, finalizer string) bool {
287291
f := o.GetFinalizers()
288292
for _, e := range f {

0 commit comments

Comments
 (0)