-
Notifications
You must be signed in to change notification settings - Fork 246
List namespace right after namespace has been created #6922
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
Merged
openshift-merge-robot
merged 5 commits into
redhat-developer:main
from
valaparthvi:6827-w-flag-for-odo-create-namespace-doesn-t-work-as-expected-on-crc-2.18-and-2.19
Jun 27, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ca0540d
List namespace right after namespace has been created
valaparthvi 080a25a
Add sleep after listing namespaces
valaparthvi 11f4cb5
Error out when timeout is reached
valaparthvi d292f6a
Modify spinner messages
valaparthvi 14b846b
Attempt at fixing doc tests
valaparthvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
docs/website/docs/command-reference/docs-mdx/create-namespace/create_namespace.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| ```console | ||
| $ odo create namespace odo-dev | ||
| ✓ Creating the namespace "odo-dev" [1s] | ||
| ✓ Namespace "odo-dev" is ready for use | ||
| ✓ New namespace created and now using namespace: odo-dev | ||
| ``` |
1 change: 1 addition & 0 deletions
1
docs/website/docs/command-reference/docs-mdx/create-namespace/create_project.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| ```console | ||
| $ odo create project odo-dev | ||
| ✓ Creating the project "odo-dev" [1s] | ||
| ✓ Project "odo-dev" is ready for use | ||
| ✓ New project created and now using project: odo-dev | ||
| ``` |
1 change: 1 addition & 0 deletions
1
docs/website/docs/user-guides/quickstart/docs-mdx/create_namespace_output.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| ```console | ||
| $ odo create namespace odo-dev | ||
| ✓ Creating the namespace "odo-dev" [1s] | ||
| ✓ Namespace "odo-dev" is ready for use | ||
| ✓ New namespace created and now using namespace: odo-dev | ||
| ``` |
1 change: 1 addition & 0 deletions
1
docs/website/docs/user-guides/quickstart/docs-mdx/create_project_output.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| ```console | ||
| $ odo create project odo-dev | ||
| ✓ Creating the project "odo-dev" [1s] | ||
| ✓ Project "odo-dev" is ready for use | ||
| ✓ New project created and now using project: odo-dev | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,12 @@ package namespace | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/redhat-developer/odo/pkg/project" | ||
| "golang.org/x/text/cases" | ||
| "golang.org/x/text/language" | ||
| "k8s.io/klog" | ||
| "os" | ||
| "time" | ||
|
|
||
| dfutil "github.com/devfile/library/v2/pkg/util" | ||
| "github.com/spf13/cobra" | ||
|
|
@@ -80,32 +82,51 @@ func (nco *NamespaceCreateOptions) Validate(ctx context.Context) error { | |
|
|
||
| // Run runs the namespace create command | ||
| func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { | ||
| // Create the "spinner" | ||
| s := &log.Status{} | ||
|
|
||
| // If the --wait parameter has been passed, we add a spinner.. | ||
| if nco.waitFlag { | ||
| s = log.Spinnerf("Waiting for %s to come up", nco.commandName) | ||
| defer s.End(false) | ||
| } | ||
| createSpinner := log.Spinnerf("Creating the %s %q", nco.commandName, nco.namespaceName) | ||
| defer createSpinner.End(false) | ||
|
|
||
| // Create the namespace & end the spinner (if there is any..) | ||
| err = nco.clientset.ProjectClient.Create(nco.namespaceName, nco.waitFlag) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| s.End(true) | ||
| createSpinner.End(true) | ||
|
|
||
| caser := cases.Title(language.Und) | ||
| successMessage := fmt.Sprintf(`%s %q is ready for use`, caser.String(nco.commandName), nco.namespaceName) | ||
| log.Successf(successMessage) | ||
| // If the --wait parameter has been passed, we add a spinner.. | ||
| if nco.waitFlag { | ||
| waitSpinner := log.Spinnerf("Waiting for the %s to come up", nco.commandName) | ||
| defer waitSpinner.End(false) | ||
| timeOut := time.After(nco.clientset.PreferenceClient.GetTimeout()) | ||
| L: | ||
| for { | ||
| select { | ||
| case <-timeOut: | ||
| return fmt.Errorf("timeout while waiting for %s %q to be ready; you can change the timeout preference by running `odo preference set timeout <duration>`", nco.commandName, nco.namespaceName) | ||
| default: | ||
| var nsList project.ProjectList | ||
| nsList, err = nco.clientset.ProjectClient.List() | ||
| if err != nil { | ||
| klog.V(4).Infof("Failed to list %ss", nco.commandName) | ||
| } | ||
| for _, ns := range nsList.Items { | ||
| if ns.Name == nco.namespaceName { | ||
| break L | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a sleep for let's say 50ms at this point, to not respawn the List operation too fast
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea. |
||
| time.Sleep(50 * time.Millisecond) | ||
| } | ||
| } | ||
| waitSpinner.End(true) | ||
| } | ||
|
|
||
| // Set the current namespace when created | ||
| err = nco.clientset.ProjectClient.SetCurrent(nco.namespaceName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| caser := cases.Title(language.Und) | ||
| successMessage := fmt.Sprintf(`%s %q is ready for use`, caser.String(nco.commandName), nco.namespaceName) | ||
| log.Successf(successMessage) | ||
| log.Successf("New %[1]s created and now using %[1]s: %v", nco.commandName, nco.namespaceName) | ||
|
|
||
| return nil | ||
|
|
@@ -134,7 +155,7 @@ func NewCmdNamespaceCreate(name, fullName string, testClientset clientset.Client | |
|
|
||
| namespaceCreateCmd.Flags().BoolVarP(&o.waitFlag, "wait", "w", false, "Wait until the namespace is ready") | ||
|
|
||
| clientset.Add(namespaceCreateCmd, clientset.KUBERNETES, clientset.PROJECT) | ||
| clientset.Add(namespaceCreateCmd, clientset.KUBERNETES, clientset.PROJECT, clientset.PREFERENCE) | ||
| util.SetCommandGroup(namespaceCreateCmd, util.MainGroup) | ||
|
|
||
| return namespaceCreateCmd | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.