Skip to content

Commit

Permalink
Scope to fallback allowed namespaces by default
Browse files Browse the repository at this point in the history
Signed-off-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com>
  • Loading branch information
praveenrewar committed Oct 9, 2024
1 parent ca6887d commit f3ec079
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 210 deletions.
4 changes: 3 additions & 1 deletion pkg/kapp/cmd/app/resource_types_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func (s *ResourceTypesFlags) Set(cmd *cobra.Command) {
false, "Allow to ignore failing APIServices")

cmd.Flags().BoolVar(&s.ScopeToFallbackAllowedNamespaces, "dangerous-scope-to-fallback-allowed-namespaces",
false, "Scope resource searching to fallback allowed namespaces")
true, "Scope resource searching to fallback allowed namespaces")

cmd.Flags().MarkDeprecated("dangerous-scope-to-fallback-allowed-namespaces", "The default and recommended behavior is to use this fallback mechanism now")
}

func (s *ResourceTypesFlags) FailingAPIServicePolicy() *FailingAPIServicesPolicy {
Expand Down
28 changes: 20 additions & 8 deletions test/e2e/fallback_allowed_ns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ data:
NewPresentClusterResource("configmap", "cm-3", testNamespace, kubectl)
})

logger.Section("inspect app without scope-to-fallback-allowed-namespaces", func() {
logger.Section("inspect app with scope-to-fallback-allowed-namespaces false", func() {
const appLabelKey string = "kapp.k14s.io/app"
NewClusterResource(t, "ns", testNamespace2, "", kubectl)
NewClusterResource(t, "cm", "cm-4", testNamespace2, kubectl)
Expand All @@ -242,7 +242,7 @@ data:
patch := fmt.Sprintf(`[{ "op": "add", "path": "/metadata/labels", "value": {%s: "%s"}}]`, appLabelKey, appLabel)
PatchClusterResource("cm", "cm-4", testNamespace2, patch, kubectl)

out := kapp.Run([]string{"inspect", "-a", appName, "--json"})
out := kapp.Run([]string{"inspect", "-a", appName, "--json", "--dangerous-scope-to-fallback-allowed-namespaces=false"})

// Should get the newly added configmap
expectedResources := []map[string]string{{
Expand Down Expand Up @@ -279,13 +279,13 @@ data:
"reconcile_state": "ok",
}}

resp := uitest.JSONUIFromBytes(t, []byte(out))
resp := uitest.JSONUIFromBytes(t, []byte(removeCobraFlagDeprecationWarning(out, "dangerous-scope-to-fallback-allowed-namespaces")))

require.Equalf(t, expectedResources, replaceAge((resp.Tables[0].Rows)), "Expected resources to match")
})

logger.Section("inspect app with scope-to-fallback-allowed-namespaces", func() {
out := kapp.Run([]string{"inspect", "-a", appName, "--json", "--dangerous-scope-to-fallback-allowed-namespaces"})
logger.Section("inspect app without scope-to-fallback-allowed-namespaces", func() {
out := kapp.Run([]string{"inspect", "-a", appName, "--json"})

// Shouldn't get the newly added configmap
expectedResources := []map[string]string{{
Expand Down Expand Up @@ -319,8 +319,8 @@ data:
require.Equalf(t, expectedResources, replaceAge((resp.Tables[0].Rows)), "Expected resources to match")
})

logger.Section("delete one configmap and deploy again with scope-to-fallback-allowed-namespaces", func() {
kapp.RunWithOpts([]string{"deploy", "-a", appName, "-f", "-", "--dangerous-scope-to-fallback-allowed-namespaces"},
logger.Section("delete one configmap and deploy again without", func() {
kapp.RunWithOpts([]string{"deploy", "-a", appName, "-f", "-"},
RunOpts{StdinReader: strings.NewReader(yaml2)})

NewPresentClusterResource("configmap", "cm-1", env.Namespace, kubectl)
Expand All @@ -329,7 +329,7 @@ data:
})

logger.Section("delete app", func() {
kapp.Run([]string{"delete", "-a", appName, "--dangerous-scope-to-fallback-allowed-namespaces"})
kapp.Run([]string{"delete", "-a", appName})

NewMissingClusterResource(t, "configmap", "cm-1", env.Namespace, kubectl)
NewMissingClusterResource(t, "configmap", "cm-2", testNamespace, kubectl)
Expand All @@ -356,3 +356,15 @@ func ScopedContext(t *testing.T, kubectl Kubectl, _, contextName, userName strin
kubectl.Run([]string{"config", "delete-user", userName})
}
}

func removeCobraFlagDeprecationWarning(output, flag string) string {
newOut := ""
lines := strings.Split(output, "\n")
for _, line := range lines {
if strings.Contains(line, fmt.Sprintf("Flag --%s has been deprecated", flag)) {
continue
}
newOut += line + "\n"
}
return newOut
}
201 changes: 0 additions & 201 deletions vendor/github.com/openshift/crd-schema-checker/LICENSE

This file was deleted.

0 comments on commit f3ec079

Please sign in to comment.