-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
odo create namespace #5724
odo create namespace #5724
Conversation
✅ Deploy Preview for odo-docusaurus-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
dfabc11
to
b77c98c
Compare
sidebar_position: 3 | ||
--- | ||
|
||
`odo create namespace` lets you create a namespace/project on your cluster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain that it will create a Project resource when the resource type exists in the cluster (generally in OpenShift clusters), or a Namespace resource otherwise
✓ New namespace created and now using namespace: mynamespace | ||
``` | ||
|
||
Optionally, you can also use `project` as an alias to `namespace`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain that using Project or Namespace won't change the resource created in the cluster: only the existence of the Project resource type in the cluster will.
}) | ||
It("should fail when an existent namespace is created again", func() { | ||
helper.Cmd("odo", "create", "project", commonVar.Project).ShouldFail() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add specific tests for OpenShift/Kubernetes to check the created resource? A project should have been created on OpenShift, but not on Kubernetes.
helper.CommonAfterEach(commonVar) | ||
}) | ||
It("should successfully create the namespace", func() { | ||
helper.Cmd("odo", "create", "namespace", "my-namespace").ShouldPass() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to delete these namespaces after the tests, or they will stay in the cluster and make future tests fail
b77c98c
to
e71ed18
Compare
AfterEach(func() { | ||
commonVar.CliRunner.DeleteNamespaceProject(project) | ||
}) | ||
It("should successfully create the project", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see this test failing on Windows, but I'm not sure why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this test passing before? I don't remember.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests are failing because you are not using the wait flag. I don't know why (*), the Project resource is not created in an atomic way, and you have to wait for it to be created.
I can see that the specs don't talk about the wait flag, probably you could force to wait everytime we create a project
(*) after some code reading, the creation of a project is done by first creating a projectrequest
, and some operator will create a project later, asynchronously
AfterEach(func() { | ||
commonVar.CliRunner.DeleteNamespaceProject(project) | ||
}) | ||
It("should successfully create the project", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests are failing because you are not using the wait flag. I don't know why (*), the Project resource is not created in an atomic way, and you have to wait for it to be created.
I can see that the specs don't talk about the wait flag, probably you could force to wait everytime we create a project
(*) after some code reading, the creation of a project is done by first creating a projectrequest
, and some operator will create a project later, asynchronously
/retest-required |
}) | ||
It("should successfully create the project", func() { | ||
helper.Cmd("odo", "create", "project", project, "--wait").ShouldPass() | ||
Expect(commonVar.CliRunner.GetNamespaceProject()).To(ContainSubstring(project)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could try to run the command kubectl get project/namespace protjetname
instead of getting the full list of projects/namespaces
/retest-required |
85000e9
to
8efedf3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question after playing with the command: what is the expected behavior of the --kubeconfig
flag with this command ? I can see it mentioned in the help:
❯ odo help create namespace
Create a new namespace. This command directly performs actions on the cluster and doesn't require a push.
Usage:
odo create namespace [flags]
Aliases:
namespace, project
Examples:
# Create a new namespace
odo create namespace my-namespace
Flags:
-h, --help Help for namespace
-w, --wait Wait until the namespace is ready
Additional Flags:
--kubeconfig string Paths to a kubeconfig. Only required if out-of-cluster.
-v, --v Level Number for the log level verbosity. Level varies from 0 to 9 (default 0).
--vmodule moduleSpec Comma-separated list of pattern=N settings for file-filtered logging
But when running the command with this flag, it looks like it didn't read/update the specified kubeconfig
:
❯ odo create namespace test1 --kubeconfig /home/asoro/work/tmp/cluster-bot/cluster-bot.kubeconfig.txt --wait
✓ Waiting for namespace to come up [7ms]
✓ Namespace "test1" is ready for use
✓ New namespace created and now using namespace: test1
❯ kubectl --kubeconfig /home/asoro/work/tmp/cluster-bot/cluster-bot.kubeconfig.txt config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* admin ci-ln-yqzqj1t-72292 admin
It looks like it ignored the specified kubeconfig
and used the default one:
❯ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
admin@talos-default talos-default admin@talos-default default
asoro/api-crc-testing:6443/kubeadmin api-crc-testing:6443 kubeadmin/api-crc-testing:6443 asoro
crc-admin api-crc-testing:6443 kubeadmin default
crc-developer api-crc-testing:6443 developer default
default/api-crc-testing:6443/kubeadmin api-crc-testing:6443 kubeadmin/api-crc-testing:6443 default
* kind-local-k8s-cluster kind-local-k8s-cluster kind-local-k8s-cluster test1
Another point I just stumbled upon: maybe we should also validate the input namespace name, using the same Otherwise, we may be affected by #5652: I successfully created an all-numeric Kubernetes namespace using
|
docs/website/versioned_docs/version-3.0.0/command-reference/create-namespace.md
Show resolved
Hide resolved
helper.Cmd("odo", "create", "namespace", commonVar.Project).ShouldFail() | ||
}) | ||
By("using an invalid namespace name", func() { | ||
helper.Cmd("odo", "create", "namespace", "12345").ShouldFail() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the command did not pass, would it be possible to also check that:
- no namespace/project with this name has been created in the cluster
- the active namespace we had prior to running this command has not changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the first check is unnecessary here, it's being extra cautious. The second check makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the first check is unnecessary here, it's being extra cautious.
To me, the call to ShouldFail
just guarantees that an error occurred with the command, but at this point, you don't necessarily know what kind of error occurred.
If tomorrow, someone removes the code that validates the namespace name, and the command fails for any reason when setting the current active namespace, then this test would still pass, I think; and in this case, I think it would be nice to detect this.
But okay, that should be fine for now.
The fact that the |
Ohhhh. I didn't see this was happening. The logic of this code is simply copy pasted from v2, I didn't take a look at it 🙄. Thanks for creating the issue! |
/retest-required |
Signed-off-by: Parthvi Vala <[email protected]>
Signed-off-by: Parthvi Vala <[email protected]>
Signed-off-by: Parthvi Vala <[email protected]>
Signed-off-by: Parthvi Vala <[email protected]>
4e92967
to
abd914b
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/lgtm |
/retest-required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rm3l The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* odo create namespace * Add documentation Signed-off-by: Parthvi Vala <[email protected]> * Philippe's review Signed-off-by: Parthvi Vala <[email protected]> * Rename doc file * Attempt at fixing integration tests Signed-off-by: Parthvi Vala <[email protected]> * Second Attempt at fixing integration tests Signed-off-by: Parthvi Vala <[email protected]> * Arm3l review * Arm3l review part 2
What type of PR is this:
/kind feature
What does this PR do / why we need it:
Which issue(s) this PR fixes:
Fixes part of #5525
PR acceptance criteria:
Unit test
Integration test
Documentation
How to test changes / Special notes to the reviewer:
odo create namespace my-namespace
odo create project my-project
odo create
odo create namespace --help
Note: The main logic of this PR comes from https://github.com/valaparthvi/odo/blob/main/pkg/odo/cli/project/create.go.