This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch 2487-fix-reset in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 560b640fd05eeb05d18237c0af9ae652797ea16b Author: nicolaferraro <[email protected]> AuthorDate: Fri Aug 27 14:28:59 2021 +0200 Fix #2487: do not directly delete owned integrations on reset --- pkg/cmd/reset.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/cmd/reset.go b/pkg/cmd/reset.go index 5831d85..9f717d7 100644 --- a/pkg/cmd/reset.go +++ b/pkg/cmd/reset.go @@ -25,6 +25,7 @@ import ( "github.com/apache/camel-k/pkg/client" "github.com/pkg/errors" "github.com/spf13/cobra" + "k8s.io/apimachinery/pkg/runtime/schema" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -100,6 +101,10 @@ func (o *resetCmdOptions) deleteAllIntegrations(c client.Client) (int, error) { } for _, i := range list.Items { it := i + if isIntegrationOwned(it) { + // Deleting it directly is ineffective, deleting the controller will delete it + continue + } if err := c.Delete(o.Context, &it); err != nil { return 0, errors.Wrap(err, fmt.Sprintf("could not delete integration %s from namespace %s", it.Name, it.Namespace)) } @@ -150,3 +155,16 @@ func (o *resetCmdOptions) resetIntegrationPlatform(c client.Client) error { platform.Status = v1.IntegrationPlatformStatus{} return c.Status().Update(o.Context, &platform) } + +func isIntegrationOwned(it v1.Integration) bool { + for _, ref := range it.OwnerReferences { + gv, err := schema.ParseGroupVersion(ref.APIVersion) + if err != nil { + continue + } + if gv.Group == v1.SchemeGroupVersion.Group && ref.BlockOwnerDeletion != nil && *ref.BlockOwnerDeletion { + return true + } + } + return false +}
