You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2020/12/16 04:36:44 UTC

[camel-k] branch master updated: feat(uninstall): add --skip-registry-secret option and make uninstall remove registry secret #1859

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2ff604d  feat(uninstall): add --skip-registry-secret option and make uninstall remove registry secret #1859
2ff604d is described below

commit 2ff604d930bafd2c75234e42a7bde491200b9131
Author: Tadayoshi Sato <sa...@gmail.com>
AuthorDate: Mon Dec 14 19:32:48 2020 +0900

    feat(uninstall): add --skip-registry-secret option and make uninstall remove registry secret #1859
---
 pkg/cmd/uninstall.go  | 27 +++++++++++++++++++++++++++
 pkg/install/secret.go |  3 +++
 2 files changed, 30 insertions(+)

diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go
index d165f97..21eb32a 100644
--- a/pkg/cmd/uninstall.go
+++ b/pkg/cmd/uninstall.go
@@ -56,6 +56,7 @@ func newCmdUninstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *uninstall
 	cmd.Flags().Bool("skip-integration-platform", false, "Do not uninstall the Camel K Integration Platform in the current namespace")
 	cmd.Flags().Bool("skip-service-accounts", false, "Do not uninstall the Camel K Service Accounts in the current namespace")
 	cmd.Flags().Bool("skip-config-maps", false, "Do not uninstall the Camel K Config Maps in the current namespace")
+	cmd.Flags().Bool("skip-registry-secret", false, "Do not uninstall the Camel K Registry Secret in the current namespace")
 	cmd.Flags().Bool("global", false, "Indicates that a global installation is going to be uninstalled (affects OLM)")
 	cmd.Flags().Bool("olm", true, "Try to uninstall via OLM (Operator Lifecycle Manager) if available")
 	cmd.Flags().String("olm-operator-name", olm.DefaultOperatorName, "Name of the Camel K operator in the OLM source or marketplace")
@@ -78,6 +79,7 @@ type uninstallCmdOptions struct {
 	SkipIntegrationPlatform bool `mapstructure:"skip-integration-platform"`
 	SkipServiceAccounts     bool `mapstructure:"skip-service-accounts"`
 	SkipConfigMaps          bool `mapstructure:"skip-config-maps"`
+	SkipRegistrySecret      bool `mapstructure:"skip-registry-secret"`
 	Global                  bool `mapstructure:"global"`
 	OlmEnabled              bool `mapstructure:"olm"`
 	UninstallAll            bool `mapstructure:"all"`
@@ -246,6 +248,13 @@ func (o *uninstallCmdOptions) uninstallNamespaceResources(ctx context.Context, c
 		fmt.Printf("Camel K Config Maps removed from namespace %s\n", o.Namespace)
 	}
 
+	if !o.SkipRegistrySecret {
+		if err := o.uninstallRegistrySecret(ctx, c); err != nil {
+			return err
+		}
+		fmt.Printf("Camel K Registry Secret removed from namespace %s\n", o.Namespace)
+	}
+
 	return nil
 }
 
@@ -397,6 +406,24 @@ func (o *uninstallCmdOptions) uninstallConfigMaps(ctx context.Context, c client.
 	return nil
 }
 
+func (o *uninstallCmdOptions) uninstallRegistrySecret(ctx context.Context, c client.Client) error {
+	api := c.CoreV1()
+
+	secretsList, err := api.Secrets(o.Namespace).List(ctx, defaultListOptions)
+	if err != nil {
+		return err
+	}
+
+	for _, secret := range secretsList.Items {
+		err := api.Secrets(o.Namespace).Delete(ctx, secret.Name, metav1.DeleteOptions{})
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+}
+
 func createActionNotAuthorizedError() error {
 	fmt.Println("Current user is not authorized to remove cluster-wide objects like custom resource definitions or cluster roles")
 	msg := `login as cluster-admin and execute "kamel uninstall" or use flags "--skip-crd --skip-cluster-roles --skip-cluster-role-bindings"`
diff --git a/pkg/install/secret.go b/pkg/install/secret.go
index 9fe4fc5..1020ad7 100644
--- a/pkg/install/secret.go
+++ b/pkg/install/secret.go
@@ -60,6 +60,9 @@ func registrySecretFromDataOrCollect(ctx context.Context, c client.Client, names
 		ObjectMeta: metav1.ObjectMeta{
 			Name:      registrySecretName,
 			Namespace: namespace,
+			Labels: map[string]string{
+				"app": "camel-k",
+			},
 		},
 		Type: v1.SecretTypeDockerConfigJson,
 		Data: map[string][]byte{