diff --git a/docs/website/versioned_docs/version-3.0.0/command-reference/create-namespace.md b/docs/website/versioned_docs/version-3.0.0/command-reference/create-namespace.md index a338e431352..a0e9e9768fe 100644 --- a/docs/website/versioned_docs/version-3.0.0/command-reference/create-namespace.md +++ b/docs/website/versioned_docs/version-3.0.0/command-reference/create-namespace.md @@ -5,6 +5,8 @@ sidebar_position: 3 `odo create namespace` lets you create a namespace/project on your cluster. If you are on a Kubernetes cluster, running the command will create a Namespace resource for you, and for an OpenShift cluster, it will create a Project resource. +Any new namespace created with this command will also be set as the current active namespace, this applies to project as well. + To create a namespace you can run `odo create namespace `: ```shell odo create namespace mynamespace diff --git a/pkg/odo/cli/create/namespace/namespace.go b/pkg/odo/cli/create/namespace/namespace.go index 987ac36e36c..e03f74992b0 100644 --- a/pkg/odo/cli/create/namespace/namespace.go +++ b/pkg/odo/cli/create/namespace/namespace.go @@ -7,6 +7,7 @@ import ( "context" + dfutil "github.com/devfile/library/pkg/util" "github.com/spf13/cobra" ktemplates "k8s.io/kubectl/pkg/util/templates" @@ -74,7 +75,7 @@ func (nco *NamespaceCreateOptions) Complete(cmdline cmdline.Cmdline, args []stri // Validate validates the parameters of the NamespaceCreateOptions func (nco *NamespaceCreateOptions) Validate() error { - return nil + return dfutil.ValidateK8sResourceName("namespace name", nco.namespaceName) } // Run runs the namespace create command diff --git a/tests/helper/helper_cli.go b/tests/helper/helper_cli.go index a6568a14b0e..6a95b650072 100644 --- a/tests/helper/helper_cli.go +++ b/tests/helper/helper_cli.go @@ -20,6 +20,7 @@ type CliRunner interface { DeletePod(podName string, projectName string) GetNamespaceProject() string CheckNamespaceProjectExists(name string) bool + GetActiveNamespace() string GetEnvsDevFileDeployment(componentName, appName, projectName string) map[string]string GetEnvRefNames(componentName, appName, projectName string) []string GetPVCSize(compName, storageName, namespace string) string diff --git a/tests/helper/helper_kubectl.go b/tests/helper/helper_kubectl.go index d8cb1370d1b..3ea2302db6e 100644 --- a/tests/helper/helper_kubectl.go +++ b/tests/helper/helper_kubectl.go @@ -386,3 +386,7 @@ func (kubectl KubectlRunner) GetNamespaceProject() string { func (kubectl KubectlRunner) CheckNamespaceProjectExists(name string) bool { return Cmd(kubectl.path, "get", "namespace", name).ShouldPass().pass } + +func (kubectl KubectlRunner) GetActiveNamespace() string { + return Cmd(kubectl.path, "config", "view", "--minify", "-ojsonpath={..namespace}").ShouldPass().Out() +} diff --git a/tests/helper/helper_oc.go b/tests/helper/helper_oc.go index 674fc3693a1..826c3d707d4 100644 --- a/tests/helper/helper_oc.go +++ b/tests/helper/helper_oc.go @@ -578,3 +578,7 @@ func (oc OcRunner) GetNamespaceProject() string { func (oc OcRunner) CheckNamespaceProjectExists(name string) bool { return Cmd(oc.path, "get", "project", name).ShouldPass().pass } + +func (oc OcRunner) GetActiveNamespace() string { + return Cmd(oc.path, "config", "view", "--minify", "-ojsonpath={..namespace}").ShouldPass().Out() +} diff --git a/tests/integration/cmd_namespace_test.go b/tests/integration/cmd_namespace_test.go index 0a27f8bc394..04df943c0e4 100644 --- a/tests/integration/cmd_namespace_test.go +++ b/tests/integration/cmd_namespace_test.go @@ -30,12 +30,18 @@ var _ = Describe("create/delete/list/get/set namespace tests", func() { }) It(fmt.Sprintf("should successfully create the %s", command), func() { Expect(commonVar.CliRunner.CheckNamespaceProjectExists(namespace)).To(BeTrue()) + Expect(commonVar.CliRunner.GetActiveNamespace()).To(Equal(namespace)) }) }) } - It("should fail to create an existent namespace", func() { - helper.Cmd("odo", "create", "namespace", commonVar.Project).ShouldFail() + It("should fail to create namespace", func() { + By("using an existent namespace name", func() { + helper.Cmd("odo", "create", "namespace", commonVar.Project).ShouldFail() + }) + By("using an invalid namespace name", func() { + helper.Cmd("odo", "create", "namespace", "12345").ShouldFail() + }) }) })