-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/action: various operator uninstall and catalog improvements (#15)
- new helper to get object key from object - new helper to re-use code that waits for object deletion - operator uninstall: add DeleteOperatorGroupNames option that is used to filter which operator groups are deleted. - operator uninstall: always wait for objects to be deleted.
- Loading branch information
1 parent
5ac9c8d
commit 25407c3
Showing
5 changed files
with
95 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package action | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
func objectKeyForObject(obj controllerutil.Object) types.NamespacedName { | ||
return types.NamespacedName{ | ||
Namespace: obj.GetNamespace(), | ||
Name: obj.GetName(), | ||
} | ||
} | ||
|
||
func waitForDeletion(ctx context.Context, cl client.Client, objs ...controllerutil.Object) error { | ||
for _, obj := range objs { | ||
obj := obj | ||
lowerKind := strings.ToLower(obj.GetObjectKind().GroupVersionKind().Kind) | ||
key := objectKeyForObject(obj) | ||
if err := wait.PollImmediateUntil(250*time.Millisecond, func() (bool, error) { | ||
if err := cl.Get(ctx, key, obj); apierrors.IsNotFound(err) { | ||
return true, nil | ||
} else if err != nil { | ||
return false, err | ||
} | ||
return false, nil | ||
}, ctx.Done()); err != nil { | ||
return fmt.Errorf("wait for %s %q deleted: %v", lowerKind, key.Name, err) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters