This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch release-1.5.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/release-1.5.x by this push:
new b50dc93 Fix #2487: do not directly delete owned integrations on reset
(#2603) (#2604)
b50dc93 is described below
commit b50dc93df7c7182bade1e7a3b11e7498b3cbf1a9
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Aug 27 17:00:09 2021 +0200
Fix #2487: do not directly delete owned integrations on reset (#2603)
(#2604)
Co-authored-by: Nicola Ferraro <[email protected]>
---
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
+}