Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#38: add uninstall command #891

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion e2e/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"errors"
"fmt"
"io/ioutil"
rbacv1 "k8s.io/api/rbac/v1"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -378,7 +379,7 @@ func configmap(ns string, name string) func() *corev1.ConfigMap {
cm := corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: metav1.SchemeGroupVersion.String(),
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Expand Down Expand Up @@ -556,6 +557,98 @@ func scaleOperator(ns string, replicas int32) func() error {
}
}

func role(ns string) func() *rbacv1.Role {
return func() *rbacv1.Role {
lst := rbacv1.RoleList{
TypeMeta: metav1.TypeMeta{
Kind: "Role",
APIVersion: rbacv1.SchemeGroupVersion.String(),
},
}
err := testClient.List(testContext, &lst,
k8sclient.InNamespace(ns),
k8sclient.MatchingLabels{
"app": "camel-k",
})
if err != nil {
panic(err)
}
if len(lst.Items) == 0 {
return nil
}
return &lst.Items[0]
}
}

func rolebinding(ns string) func() *rbacv1.RoleBinding {
return func() *rbacv1.RoleBinding {
lst := rbacv1.RoleBindingList{
TypeMeta: metav1.TypeMeta{
Kind: "RoleBinding",
APIVersion: metav1.SchemeGroupVersion.String(),
},
}
err := testClient.List(testContext, &lst,
k8sclient.InNamespace(ns),
k8sclient.MatchingLabels{
"app": "camel-k",
})
if err != nil {
panic(err)
}
if len(lst.Items) == 0 {
return nil
}
return &lst.Items[0]
}
}

func clusterrole(ns string) func() *rbacv1.ClusterRole {
return func() *rbacv1.ClusterRole {
lst := rbacv1.ClusterRoleList{
TypeMeta: metav1.TypeMeta{
Kind: "ClusterRole",
APIVersion: rbacv1.SchemeGroupVersion.String(),
},
}
err := testClient.List(testContext, &lst,
k8sclient.InNamespace(ns),
k8sclient.MatchingLabels{
"app": "camel-k",
})
if err != nil {
panic(err)
}
if len(lst.Items) == 0 {
return nil
}
return &lst.Items[0]
}
}

func serviceaccount(ns, name string) func() *corev1.ServiceAccount {
return func() *corev1.ServiceAccount {
lst := corev1.ServiceAccountList{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceAccount",
APIVersion: corev1.SchemeGroupVersion.String(),
},
}
err := testClient.List(testContext, &lst,
k8sclient.InNamespace(ns),
k8sclient.MatchingLabels{
"app": "camel-k",
})
if err != nil {
panic(err)
}
if len(lst.Items) == 0 {
return nil
}
return &lst.Items[0]
}
}

/*
Tekton
*/
Expand Down
112 changes: 112 additions & 0 deletions e2e/uninstall_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// +build integration

// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"

/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"testing"

. "github.com/onsi/gomega"
)

func TestBasicUninstall(t *testing.T) {
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// should be completely removed on uninstall
Expect(kamel("uninstall", "-n", ns).Execute()).Should(BeNil())
Eventually(role(ns)).Should(BeNil())
Eventually(rolebinding(ns)).Should(BeNil())
Eventually(configmap(ns,"camel-k-maven-settings")).Should(BeNil())
Eventually(clusterrole(ns)).Should(BeNil())
Eventually(serviceaccount(ns,"camel-k-maven-settings")).Should(BeNil())
Eventually(operatorPod(ns)).Should(BeNil())
})
}

func TestUninstallSkipOperator(t *testing.T) {
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// on uninstall it should remove everything except operator
Expect(kamel("uninstall", "-n", ns,"--skip-operator").Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
})
}

func TestUninstallSkipRole(t *testing.T) {
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// on uninstall it should remove everything except roles
Expect(kamel("uninstall", "-n", ns,"--skip-roles").Execute()).Should(BeNil())
Eventually(role(ns)).ShouldNot(BeNil())
})
}

func TestUninstallSkipRoleBinding(t *testing.T) {
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// on uninstall it should remove everything except role-bindings
Expect(kamel("uninstall", "-n", ns,"--skip-role-bindings").Execute()).Should(BeNil())
Eventually(rolebinding(ns)).ShouldNot(BeNil())
})
}

func TestUninstallSkipClusterRoles(t *testing.T) {
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// on uninstall it should remove everything except cluster-roles
Expect(kamel("uninstall", "-n", ns,"--skip-cluster-roles").Execute()).Should(BeNil())
Eventually(clusterrole(ns)).ShouldNot(BeNil())
})
}

func TestUninstallSkipServiceAccounts(t *testing.T) {
//t.Skip("inconsistent test results ")
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// on uninstall it should remove everything except cluster-roles
Expect(kamel("uninstall", "-n", ns,"--skip-service-accounts").Execute()).Should(BeNil())
Eventually(serviceaccount(ns, "camel-k-operator")).ShouldNot(BeNil())
})
}

func TestUninstallSkipIntegrationPlatform(t *testing.T) {
withNewTestNamespace(t, func(ns string) {
// a successful new installation
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())
Eventually(operatorPod(ns)).ShouldNot(BeNil())
// on uninstall it should remove everything except cluster-roles
// NOTE: skip CRDs is also required in addition to skip integration platform
Expect(kamel("uninstall", "-n", ns,"--skip-crd","--skip-integration-platform").Execute()).Should(BeNil())
Eventually(platform(ns)).ShouldNot(BeNil())
})
}
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func addKamelSubcommands(cmd *cobra.Command, options *RootCmdOptions) {
cmd.AddCommand(cmdOnly(newCmdGet(options)))
cmd.AddCommand(cmdOnly(newCmdDelete(options)))
cmd.AddCommand(cmdOnly(newCmdInstall(options)))
cmd.AddCommand(cmdOnly(newCmdUninstall(options)))
cmd.AddCommand(cmdOnly(newCmdLog(options)))
cmd.AddCommand(newCmdKit(options))
cmd.AddCommand(cmdOnly(newCmdReset(options)))
Expand Down
Loading