This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 29c1a72  Fix #2487: do not directly delete owned integrations on reset 
(#2603)
29c1a72 is described below

commit 29c1a72bbbf04c0dc3b2e19b37b1c2f8fae44647
Author: Nicola Ferraro <[email protected]>
AuthorDate: Fri Aug 27 16:56:38 2021 +0200

    Fix #2487: do not directly delete owned integrations on reset (#2603)
---
 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
+}

Reply via email to