You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2024/03/08 16:00:26 UTC
(camel-k) branch main updated: fix(cmd): delete KameletBinding until they exists
This is an automated email from the ASF dual-hosted git repository.
pcongiusti 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 3866625ca fix(cmd): delete KameletBinding until they exists
3866625ca is described below
commit 3866625ca67193f874e2c5841bef635c19f228bd
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 8 13:17:18 2024 +0100
fix(cmd): delete KameletBinding until they exists
Closes #5156
---
pkg/cmd/delete.go | 40 +++++++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/pkg/cmd/delete.go b/pkg/cmd/delete.go
index 5ce21e727..927d7a763 100644
--- a/pkg/cmd/delete.go
+++ b/pkg/cmd/delete.go
@@ -24,6 +24,7 @@ import (
"strconv"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/v2/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/v2/pkg/client"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
@@ -136,13 +137,22 @@ func getIntegration(ctx context.Context, c client.Client, name string, namespace
}
func deleteIntegration(ctx context.Context, cmd *cobra.Command, c client.Client, integration *v1.Integration) error {
- deleted, binding, err := deletePipeIfExists(ctx, c, integration)
+ deletedPipes, pipe, err := deletePipeIfExists(ctx, c, integration)
if err != nil {
return err
}
- if deleted {
+ if deletedPipes {
// Deleting Pipe will automatically clean up the integration
- fmt.Fprintln(cmd.OutOrStdout(), "Pipe "+binding+" deleted")
+ fmt.Fprintln(cmd.OutOrStdout(), "Pipe "+pipe+" deleted")
+ return nil
+ }
+ deletedKameletBindings, klb, err := deleteKameletBindingIfExists(ctx, c, integration)
+ if err != nil {
+ return err
+ }
+ if deletedKameletBindings {
+ // Deleting KameletBinding will automatically clean up the integration
+ fmt.Fprintln(cmd.OutOrStdout(), "KameletBinding "+klb+" deleted")
return nil
}
return c.Delete(ctx, integration)
@@ -172,6 +182,30 @@ func deletePipeIfExists(ctx context.Context, c client.Client, integration *v1.In
return err == nil, name, err
}
+func deleteKameletBindingIfExists(ctx context.Context, c client.Client, integration *v1.Integration) (bool, string, error) {
+ kind, name := findCreator(integration)
+ if kind != v1alpha1.KameletBindingKind || name == "" {
+ return false, "", nil
+ }
+
+ binding := v1alpha1.KameletBinding{
+ TypeMeta: metav1.TypeMeta{
+ Kind: kind,
+ APIVersion: v1.SchemeGroupVersion.String(),
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: integration.Namespace,
+ Name: name,
+ },
+ }
+ err := c.Delete(ctx, &binding)
+ if k8errors.IsNotFound(err) {
+ // Simply skip if binding doesn't exist (could be deleted already)
+ return false, name, nil
+ }
+ return err == nil, name, err
+}
+
func findCreator(integration *v1.Integration) (string, string) {
kind := integration.GetLabels()[kubernetes.CamelCreatorLabelKind]
name := integration.GetLabels()[kubernetes.CamelCreatorLabelName]