diff --git a/test/extended/images/prune.go b/test/extended/images/prune.go index 1166645bb996..b32ff0ece429 100644 --- a/test/extended/images/prune.go +++ b/test/extended/images/prune.go @@ -41,7 +41,7 @@ var _ = g.Describe("[images] prune images", func() { o.Expect(err).NotTo(o.HaveOccurred()) g.By(fmt.Sprintf("give a user %s a right to prune images with %s role", oc.Username(), "system:image-pruner")) - err = oc.AsAdmin().Run("adm").Args("policy", "add-cluster-role-to-user", "system:image-pruner", oc.Username()).Execute() + err = oc.AsAdmin().WithoutNamespace().Run("adm").Args("policy", "add-cluster-role-to-user", "system:image-pruner", oc.Username()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) }) @@ -126,7 +126,7 @@ func testPruneImages(oc *exutil.CLI, schemaVersion int) { o.Expect(imgKeep.DockerImageManifestMediaType).To(o.Equal(mediaType)) g.By("prune the first image uploaded (dry-run)") - output, err := oc.Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0").Output() + output, err := oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0").Output() g.By("verify images, layers and configs about to be pruned") o.Expect(output).To(o.ContainSubstring(imgPruneName)) @@ -154,7 +154,7 @@ func testPruneImages(oc *exutil.CLI, schemaVersion int) { o.Expect(noConfirmSize).To(o.Equal(keepSize)) g.By("prune the first image uploaded (confirm)") - output, err = oc.Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm").Output() + output, err = oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm").Output() g.By("verify images, layers and configs about to be pruned") o.Expect(output).To(o.ContainSubstring(imgPruneName)) diff --git a/test/extended/util/cli.go b/test/extended/util/cli.go index 1a6ea8331d94..4efbf717e74d 100644 --- a/test/extended/util/cli.go +++ b/test/extended/util/cli.go @@ -32,21 +32,22 @@ import ( // CLI provides function to call the OpenShift CLI and Kubernetes and OpenShift // REST clients. type CLI struct { - execPath string - verb string - configPath string - adminConfigPath string - username string - outputDir string - globalArgs []string - commandArgs []string - finalArgs []string - stdin *bytes.Buffer - stdout io.Writer - stderr io.Writer - verbose bool - cmd *cobra.Command - kubeFramework *e2e.Framework + execPath string + verb string + configPath string + adminConfigPath string + username string + outputDir string + globalArgs []string + commandArgs []string + finalArgs []string + stdin *bytes.Buffer + stdout io.Writer + stderr io.Writer + verbose bool + withoutNamespace bool + cmd *cobra.Command + kubeFramework *e2e.Framework } // NewCLI initialize the upstream E2E framework and set the namespace to match @@ -129,6 +130,12 @@ func (c *CLI) SetNamespace(ns string) *CLI { return c } +// WithoutNamespace instructs the command should be invoked without adding --namespace parameter +func (c *CLI) WithoutNamespace() *CLI { + c.withoutNamespace = true + return c +} + // SetOutputDir change the default output directory for temporary files func (c *CLI) SetOutputDir(dir string) *CLI { c.outputDir = dir @@ -239,10 +246,12 @@ func (c *CLI) Run(commands ...string) *CLI { username: c.username, outputDir: c.outputDir, globalArgs: append(commands, []string{ - fmt.Sprintf("--namespace=%s", c.Namespace()), fmt.Sprintf("--config=%s", c.configPath), }...), } + if !c.withoutNamespace { + nc.globalArgs = append(nc.globalArgs, fmt.Sprintf("--namespace=%s", c.Namespace())) + } nc.stdin, nc.stdout, nc.stderr = in, out, errout return nc.setOutput(c.stdout) }