Skip to content

Commit

Permalink
Arm3l review
Browse files Browse the repository at this point in the history
  • Loading branch information
valaparthvi committed May 12, 2022
1 parent 006708e commit 4514e6a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>`:
```shell
odo create namespace mynamespace
Expand Down
3 changes: 2 additions & 1 deletion pkg/odo/cli/create/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"context"

dfutil "github.com/devfile/library/pkg/util"
"github.com/spf13/cobra"
ktemplates "k8s.io/kubectl/pkg/util/templates"

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/helper/helper_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/helper/helper_kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
4 changes: 4 additions & 0 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
10 changes: 8 additions & 2 deletions tests/integration/cmd_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})

0 comments on commit 4514e6a

Please sign in to comment.