You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2020/03/27 17:11:34 UTC
[camel-k] branch master updated: Fix #1356: remove namespace
resources on uninstall and fix maven-settings override
This is an automated email from the ASF dual-hosted git repository.
nferraro 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 99e82c0 Fix #1356: remove namespace resources on uninstall and fix maven-settings override
99e82c0 is described below
commit 99e82c0acbb2daceb7df80bd8bcc033028ab1211
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Fri Mar 27 16:17:57 2020 +0100
Fix #1356: remove namespace resources on uninstall and fix maven-settings override
---
e2e/uninstall_test.go | 2 +-
pkg/cmd/uninstall.go | 79 ++++++++++++++++++++++++----------------
pkg/platform/defaults.go | 22 +++++++++++
pkg/util/maven/maven_settings.go | 27 +++++++++++---
4 files changed, 93 insertions(+), 37 deletions(-)
diff --git a/e2e/uninstall_test.go b/e2e/uninstall_test.go
index 92d29db..21d7c0e 100644
--- a/e2e/uninstall_test.go
+++ b/e2e/uninstall_test.go
@@ -38,7 +38,7 @@ func TestBasicUninstall(t *testing.T) {
Eventually(role(ns)).Should(BeNil())
Eventually(rolebinding(ns)).Should(BeNil())
Eventually(configmap(ns, "camel-k-maven-settings")).Should(BeNil())
- Eventually(serviceaccount(ns, "camel-k-maven-settings")).Should(BeNil())
+ Eventually(serviceaccount(ns, "camel-k-operator")).Should(BeNil())
Eventually(operatorPod(ns)).Should(BeNil())
})
}
diff --git a/pkg/cmd/uninstall.go b/pkg/cmd/uninstall.go
index 6ffb87e..aa60548 100644
--- a/pkg/cmd/uninstall.go
+++ b/pkg/cmd/uninstall.go
@@ -46,14 +46,14 @@ func newCmdUninstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *uninstall
RunE: options.uninstall,
}
- cmd.Flags().Bool("skip-operator", false, "Do not uninstall the Camel-K Operator in the current namespace")
- cmd.Flags().Bool("skip-crd", false, "Do not uninstall the Camel-k Custom Resource Definitions (CRD) in the current namespace")
- cmd.Flags().Bool("skip-role-bindings", false, "Do not uninstall the Camel-K Role Bindings in the current namespace")
- cmd.Flags().Bool("skip-roles", false, "Do not uninstall the Camel-K Roles in the current namespace")
- cmd.Flags().Bool("skip-cluster-roles", false, "Do not uninstall the Camel-K Cluster Roles in the current namespace")
- 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-operator", false, "Do not uninstall the Camel K Operator in the current namespace")
+ cmd.Flags().Bool("skip-crd", true, "Do not uninstall the Camel-k Custom Resource Definitions (CRD)")
+ cmd.Flags().Bool("skip-role-bindings", false, "Do not uninstall the Camel K Role Bindings in the current namespace")
+ cmd.Flags().Bool("skip-roles", false, "Do not uninstall the Camel K Roles in the current namespace")
+ cmd.Flags().Bool("skip-cluster-roles", true, "Do not uninstall the Camel K Cluster Roles")
+ 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("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")
@@ -120,7 +120,7 @@ func (o *uninstallCmdOptions) uninstall(cmd *cobra.Command, _ []string) error {
if o.Global {
where = "globally"
}
- fmt.Fprintf(cmd.OutOrStdout(), "Camel-K OLM service removed %s\n", where)
+ fmt.Fprintf(cmd.OutOrStdout(), "Camel K OLM service removed %s\n", where)
}
}
@@ -128,22 +128,31 @@ func (o *uninstallCmdOptions) uninstall(cmd *cobra.Command, _ []string) error {
if err = o.uninstallIntegrationPlatform(); err != nil {
return err
}
- fmt.Fprintf(cmd.OutOrStdout(), "Camel-K Integration Platform removed from namespace %s\n", o.Namespace)
+ fmt.Fprintf(cmd.OutOrStdout(), "Camel K Integration Platform removed from namespace %s\n", o.Namespace)
}
- if !uninstallViaOLM {
- if err = o.uninstallClusterWideResources(c); err != nil {
- return err
- }
- fmt.Fprintf(cmd.OutOrStdout(), "Camel-K Cluster Wide Resources removed from namespace %s\n", o.Namespace)
+ if err = o.uninstallNamespaceResources(c); err != nil {
+ return err
+ }
+ if !uninstallViaOLM {
if !o.SkipOperator {
if err = o.uninstallOperator(c); err != nil {
return err
}
- fmt.Fprintf(cmd.OutOrStdout(), "Camel-K Operator removed from namespace %s\n", o.Namespace)
+ fmt.Fprintf(cmd.OutOrStdout(), "Camel K Operator removed from namespace %s\n", o.Namespace)
+ }
+
+ if err = o.uninstallNamespaceRoles(c); err != nil {
+ return err
}
+
+ if err = o.uninstallClusterWideResources(c); err != nil {
+ return err
+ }
+
}
+
return nil
}
@@ -173,45 +182,53 @@ func (o *uninstallCmdOptions) uninstallClusterWideResources(c client.Client) err
}
return err
}
- fmt.Printf("Camel-K Custom Resource Definitions removed from namespace %s\n", o.Namespace)
+ fmt.Printf("Camel K Custom Resource Definitions removed from cluster\n")
}
- if !o.SkipRoleBindings {
- if err := o.uninstallRoleBindings(c); err != nil {
+ if !o.SkipClusterRoles {
+ if err := o.uninstallClusterRoles(c); err != nil {
+ if k8serrors.IsForbidden(err) {
+ return createActionNotAuthorizedError()
+ }
return err
}
- fmt.Printf("Camel-K Role Bindings removed from namespace %s\n", o.Namespace)
+ fmt.Printf("Camel K Cluster Roles removed from cluster\n")
}
- if !o.SkipRoles {
- if err := o.uninstallRoles(c); err != nil {
+ return nil
+}
+
+func (o *uninstallCmdOptions) uninstallNamespaceRoles(c client.Client) error {
+ if !o.SkipRoleBindings {
+ if err := o.uninstallRoleBindings(c); err != nil {
return err
}
- fmt.Printf("Camel-K Roles removed from namespace %s\n", o.Namespace)
+ fmt.Printf("Camel K Role Bindings removed from namespace %s\n", o.Namespace)
}
- if !o.SkipClusterRoles {
- if err := o.uninstallClusterRoles(c); err != nil {
- if k8serrors.IsForbidden(err) {
- return createActionNotAuthorizedError()
- }
+ if !o.SkipRoles {
+ if err := o.uninstallRoles(c); err != nil {
return err
}
- fmt.Printf("Camel-K Cluster Roles removed from namespace %s\n", o.Namespace)
+ fmt.Printf("Camel K Roles removed from namespace %s\n", o.Namespace)
}
if !o.SkipServiceAccounts {
if err := o.uninstallServiceAccounts(c); err != nil {
return err
}
- fmt.Printf("Camel-K Service Accounts removed from namespace %s\n", o.Namespace)
+ fmt.Printf("Camel K Service Accounts removed from namespace %s\n", o.Namespace)
}
+ return nil
+}
+
+func (o *uninstallCmdOptions) uninstallNamespaceResources(c client.Client) error {
if !o.SkipConfigMaps {
if err := o.uninstallConfigMaps(c); err != nil {
return err
}
- fmt.Printf("Camel-K Config Maps removed from namespace %s\n", o.Namespace)
+ fmt.Printf("Camel K Config Maps removed from namespace %s\n", o.Namespace)
}
return nil
diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go
index 8b50ec8..27063b9 100644
--- a/pkg/platform/defaults.go
+++ b/pkg/platform/defaults.go
@@ -23,6 +23,7 @@ import (
"strings"
"time"
+ "github.com/apache/camel-k/pkg/util/patch"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
@@ -263,6 +264,27 @@ func createDefaultMavenSettingsConfigMap(ctx context.Context, client client.Clie
err = client.Create(ctx, cm)
if err != nil && !k8serrors.IsAlreadyExists(err) {
return err
+ } else if k8serrors.IsAlreadyExists(err) {
+ key, err := k8sclient.ObjectKeyFromObject(cm)
+ if err != nil {
+ return err
+ }
+
+ cmCopy := cm.DeepCopyObject()
+ err = client.Get(ctx, key, cmCopy)
+ if err != nil {
+ return err
+ }
+
+ p, err := patch.PositiveMergePatch(cmCopy, cm)
+ if err != nil {
+ return err
+ } else if len(p) != 0 {
+ err = client.Patch(ctx, cm, k8sclient.ConstantPatch(types.MergePatchType, p))
+ if err != nil {
+ return errors.Wrap(err, "error during patch resource")
+ }
+ }
}
return nil
diff --git a/pkg/util/maven/maven_settings.go b/pkg/util/maven/maven_settings.go
index 1111e26..4bdf282 100644
--- a/pkg/util/maven/maven_settings.go
+++ b/pkg/util/maven/maven_settings.go
@@ -19,6 +19,7 @@ package maven
import (
"encoding/xml"
+ "strings"
"github.com/apache/camel-k/pkg/util"
@@ -26,6 +27,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
+// DefaultMavenRepositories is a comma separated list of default maven repositories
+// This variable can be overridden at build time
+var DefaultMavenRepositories = "https://repo.maven.apache.org/maven2@id=central"
+
// NewSettings --
func NewSettings() Settings {
return Settings{
@@ -40,9 +45,14 @@ func NewSettings() Settings {
func NewDefaultSettings(repositories []Repository) Settings {
settings := NewSettings()
- if !containsMvnCentral(repositories) {
- repository := NewRepository("https://repo.maven.apache.org/maven2@id=central")
- repositories = append([]Repository{repository}, repositories...)
+ var additionalRepos []Repository
+ for _, defaultRepo := range getDefaultMavenRepositories() {
+ if !containsRepo(repositories, defaultRepo.ID) {
+ additionalRepos = append(additionalRepos, defaultRepo)
+ }
+ }
+ if len(additionalRepos) > 0 {
+ repositories = append(additionalRepos, repositories...)
}
settings.Profiles = []Profile{
@@ -86,9 +96,16 @@ func CreateSettingsConfigMap(namespace string, name string, settings Settings) (
return cm, nil
}
-func containsMvnCentral(repositories []Repository) bool {
+func getDefaultMavenRepositories() (repos []Repository) {
+ for _, repoDesc := range strings.Split(DefaultMavenRepositories, ",") {
+ repos = append(repos, NewRepository(repoDesc))
+ }
+ return
+}
+
+func containsRepo(repositories []Repository, id string) bool {
for _, r := range repositories {
- if r.ID == "central" {
+ if r.ID == id {
return true
}
}