Skip to content

Commit f3ec079

Browse files
committed
Scope to fallback allowed namespaces by default
Signed-off-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com>
1 parent ca6887d commit f3ec079

File tree

3 files changed

+23
-210
lines changed

3 files changed

+23
-210
lines changed

pkg/kapp/cmd/app/resource_types_flags.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func (s *ResourceTypesFlags) Set(cmd *cobra.Command) {
2020
false, "Allow to ignore failing APIServices")
2121

2222
cmd.Flags().BoolVar(&s.ScopeToFallbackAllowedNamespaces, "dangerous-scope-to-fallback-allowed-namespaces",
23-
false, "Scope resource searching to fallback allowed namespaces")
23+
true, "Scope resource searching to fallback allowed namespaces")
24+
25+
cmd.Flags().MarkDeprecated("dangerous-scope-to-fallback-allowed-namespaces", "The default and recommended behavior is to use this fallback mechanism now")
2426
}
2527

2628
func (s *ResourceTypesFlags) FailingAPIServicePolicy() *FailingAPIServicesPolicy {

test/e2e/fallback_allowed_ns_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ data:
232232
NewPresentClusterResource("configmap", "cm-3", testNamespace, kubectl)
233233
})
234234

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

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

247247
// Should get the newly added configmap
248248
expectedResources := []map[string]string{{
@@ -279,13 +279,13 @@ data:
279279
"reconcile_state": "ok",
280280
}}
281281

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

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

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

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

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

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

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

334334
NewMissingClusterResource(t, "configmap", "cm-1", env.Namespace, kubectl)
335335
NewMissingClusterResource(t, "configmap", "cm-2", testNamespace, kubectl)
@@ -356,3 +356,15 @@ func ScopedContext(t *testing.T, kubectl Kubectl, _, contextName, userName strin
356356
kubectl.Run([]string{"config", "delete-user", userName})
357357
}
358358
}
359+
360+
func removeCobraFlagDeprecationWarning(output, flag string) string {
361+
newOut := ""
362+
lines := strings.Split(output, "\n")
363+
for _, line := range lines {
364+
if strings.Contains(line, fmt.Sprintf("Flag --%s has been deprecated", flag)) {
365+
continue
366+
}
367+
newOut += line + "\n"
368+
}
369+
return newOut
370+
}

vendor/github.com/openshift/crd-schema-checker/LICENSE

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)