-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unblock app deletion when namespace is terminating
and app resources are in the same namespace only Signed-off-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com>
- Loading branch information
1 parent
8e7185d
commit cf316da
Showing
7 changed files
with
227 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package kappcontroller | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/vmware-tanzu/carvel-kapp-controller/test/e2e" | ||
) | ||
|
||
func Test_NamespaceDelete_AppWithResourcesInSameNamespace(t *testing.T) { | ||
env := e2e.BuildEnv(t) | ||
logger := e2e.Logger{} | ||
kapp := e2e.Kapp{t, env.Namespace, logger} | ||
kubectl := e2e.Kubectl{t, env.Namespace, logger} | ||
|
||
nsName := "ns-delete" | ||
name := "resources-in-same-namespace" | ||
|
||
namespaceYAML := fmt.Sprintf(`--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: %v`, nsName) | ||
|
||
appYAML := fmt.Sprintf(`--- | ||
apiVersion: kappctrl.k14s.io/v1alpha1 | ||
kind: App | ||
metadata: | ||
name: %s | ||
spec: | ||
serviceAccountName: kappctrl-e2e-ns-sa | ||
fetch: | ||
- inline: | ||
paths: | ||
file.yml: | | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: configmap | ||
namespace: %s | ||
data: | ||
key: value | ||
template: | ||
- ytt: {} | ||
deploy: | ||
- kapp: {}`, name, nsName) + e2e.ServiceAccounts{nsName}.ForNamespaceYAML() | ||
|
||
cleanUp := func() { | ||
kapp.Run([]string{"delete", "-a", name}) | ||
kapp.Run([]string{"delete", "-a", nsName}) | ||
} | ||
|
||
cleanUp() | ||
defer cleanUp() | ||
|
||
logger.Section("create namespace and deploy App", func() { | ||
kapp.RunWithOpts([]string{"deploy", "-a", nsName, "-f", "-"}, e2e.RunOpts{StdinReader: strings.NewReader(namespaceYAML)}) | ||
kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name, "--into-ns", nsName}, e2e.RunOpts{StdinReader: strings.NewReader(appYAML)}) | ||
}) | ||
|
||
logger.Section("delete namespace", func() { | ||
kubectl.Run([]string{"delete", "ns", nsName, "--timeout=1m"}) | ||
}) | ||
} | ||
|
||
func Test_NamespaceDelete_AppWithResourcesInDifferentNamespaces(t *testing.T) { | ||
env := e2e.BuildEnv(t) | ||
logger := e2e.Logger{} | ||
kapp := e2e.Kapp{t, env.Namespace, logger} | ||
kubectl := e2e.Kubectl{t, env.Namespace, logger} | ||
|
||
nsName := "ns-delete" | ||
name := "resources-in-different-namespaces" | ||
|
||
namespaceYAML := fmt.Sprintf(`--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: %v`, nsName) | ||
|
||
appYaml := fmt.Sprintf(`--- | ||
apiVersion: kappctrl.k14s.io/v1alpha1 | ||
kind: App | ||
metadata: | ||
name: %s | ||
spec: | ||
serviceAccountName: kappctrl-e2e-ns-sa | ||
fetch: | ||
- inline: | ||
paths: | ||
file.yml: | | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: configmap | ||
namespace: %s | ||
data: | ||
key: value | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: configmap | ||
namespace: %s | ||
data: | ||
key: value | ||
template: | ||
- ytt: {} | ||
deploy: | ||
- kapp: {}`, name, nsName, env.Namespace) + e2e.ServiceAccounts{nsName}.ForClusterYAML() | ||
|
||
cleanUp := func() { | ||
kapp.Run([]string{"delete", "-a", name}) | ||
} | ||
|
||
cleanUpTestNamespace := func() { | ||
kubectl.Run([]string{"delete", "configmap", "configmap"}) | ||
kubectl.RunWithOpts([]string{"patch", "App", name, "--type=json", "--patch", `[{ "op": "replace", "path": "/spec/noopDelete", "value": true}]`, | ||
"-n", nsName}, e2e.RunOpts{NoNamespace: true}) | ||
kapp.Run([]string{"delete", "-a", nsName}) | ||
} | ||
|
||
cleanUp() | ||
defer cleanUp() | ||
defer cleanUpTestNamespace() | ||
|
||
logger.Section("create namespace and deploy App", func() { | ||
kapp.RunWithOpts([]string{"deploy", "-a", nsName, "-f", "-"}, e2e.RunOpts{StdinReader: strings.NewReader(namespaceYAML)}) | ||
kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name, "--into-ns", nsName}, e2e.RunOpts{StdinReader: strings.NewReader(appYaml)}) | ||
}) | ||
|
||
logger.Section("delete namespace", func() { | ||
// delete SA first to reduce flakiness, sometimes SA deletion happens after app is deleted | ||
kubectl.RunWithOpts([]string{"delete", "serviceaccount", "kappctrl-e2e-ns-sa", "-n", nsName}, | ||
e2e.RunOpts{NoNamespace: true}) | ||
_, err := kubectl.RunWithOpts([]string{"delete", "ns", nsName, "--timeout=30s"}, | ||
e2e.RunOpts{AllowError: true}) | ||
assert.Error(t, err, "Expected to get time out error, but did not") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters