From ca0540d6c99867a433bfcd48f1ae220cdeb40c00 Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Thu, 22 Jun 2023 16:26:54 +0530 Subject: [PATCH 1/5] List namespace right after namespace has been created Signed-off-by: Parthvi Vala --- pkg/odo/cli/create/namespace/namespace.go | 28 +++++++++++++++++++++-- tests/integration/cmd_namespace_test.go | 14 ++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pkg/odo/cli/create/namespace/namespace.go b/pkg/odo/cli/create/namespace/namespace.go index e71acddf59a..929b72e7a38 100644 --- a/pkg/odo/cli/create/namespace/namespace.go +++ b/pkg/odo/cli/create/namespace/namespace.go @@ -3,7 +3,10 @@ package namespace import ( "context" "fmt" + "github.com/redhat-developer/odo/pkg/project" + "k8s.io/klog" "os" + "time" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -105,7 +108,28 @@ func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { if err != nil { return err } - + if nco.waitFlag { + var timeOut = time.After(nco.clientset.PreferenceClient.GetTimeout()) + L: + for { + select { + case <-timeOut: + log.Warningf("Timeout while waiting for %s %q; it may take a while to appear", nco.commandName, nco.namespaceName) + return nil + 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 + } + } + } + } + } log.Successf("New %[1]s created and now using %[1]s: %v", nco.commandName, nco.namespaceName) return nil @@ -134,7 +158,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 diff --git a/tests/integration/cmd_namespace_test.go b/tests/integration/cmd_namespace_test.go index 672bbc7dc81..75b6d9198c7 100644 --- a/tests/integration/cmd_namespace_test.go +++ b/tests/integration/cmd_namespace_test.go @@ -25,6 +25,20 @@ var _ = Describe("odo create/delete/list/set namespace/project tests", func() { AfterEach(func() { helper.CommonAfterEach(commonVar) }) + + When("namespace is created with -w", func() { + // Ref: https://github.com/redhat-developer/odo/issues/6827 + var namespace string + BeforeEach(func() { + namespace = helper.GetProjectName() + helper.Cmd("odo", "create", "namespace", namespace, "--wait").ShouldPass() + }) + It("should list the new namespace when listing namespace", func() { + out := helper.Cmd("odo", "list", "namespace").ShouldPass().Out() + Expect(out).To(ContainSubstring(namespace)) + }) + }) + for _, commandName := range []string{"namespace", "project"} { // this is a workaround to ensure that the for loop works with `It` blocks commandName := commandName From 080a25a6d2e2a9ea1268bac2b3e53193dfaec7f7 Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Fri, 23 Jun 2023 14:33:02 +0530 Subject: [PATCH 2/5] Add sleep after listing namespaces Signed-off-by: Parthvi Vala --- pkg/odo/cli/create/namespace/namespace.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/odo/cli/create/namespace/namespace.go b/pkg/odo/cli/create/namespace/namespace.go index 929b72e7a38..581e185db35 100644 --- a/pkg/odo/cli/create/namespace/namespace.go +++ b/pkg/odo/cli/create/namespace/namespace.go @@ -127,6 +127,7 @@ func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { break L } } + time.Sleep(50 * time.Millisecond) } } } From 11f4cb51071780cccb71e72fae037a7b19a55cad Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Tue, 27 Jun 2023 10:24:39 +0530 Subject: [PATCH 3/5] Error out when timeout is reached Signed-off-by: Parthvi Vala --- pkg/odo/cli/create/namespace/namespace.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/odo/cli/create/namespace/namespace.go b/pkg/odo/cli/create/namespace/namespace.go index 581e185db35..68563d5de3d 100644 --- a/pkg/odo/cli/create/namespace/namespace.go +++ b/pkg/odo/cli/create/namespace/namespace.go @@ -4,13 +4,12 @@ import ( "context" "fmt" "github.com/redhat-developer/odo/pkg/project" + "golang.org/x/text/cases" + "golang.org/x/text/language" "k8s.io/klog" "os" "time" - "golang.org/x/text/cases" - "golang.org/x/text/language" - dfutil "github.com/devfile/library/v2/pkg/util" "github.com/spf13/cobra" ktemplates "k8s.io/kubectl/pkg/util/templates" @@ -99,10 +98,6 @@ func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { } s.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) - // Set the current namespace when created err = nco.clientset.ProjectClient.SetCurrent(nco.namespaceName) if err != nil { @@ -114,8 +109,7 @@ func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { for { select { case <-timeOut: - log.Warningf("Timeout while waiting for %s %q; it may take a while to appear", nco.commandName, nco.namespaceName) - return nil + return fmt.Errorf("timeout while waiting for %s %q to be ready; you can change the timeout preference by running `odo preference set timeout `", nco.commandName, nco.namespaceName) default: var nsList project.ProjectList nsList, err = nco.clientset.ProjectClient.List() @@ -131,6 +125,9 @@ func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { } } } + 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 From d292f6a93d2553b050cb66bbb4b9d059796a26ca Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Tue, 27 Jun 2023 14:28:35 +0530 Subject: [PATCH 4/5] Modify spinner messages Signed-off-by: Parthvi Vala --- pkg/odo/cli/create/namespace/namespace.go | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/pkg/odo/cli/create/namespace/namespace.go b/pkg/odo/cli/create/namespace/namespace.go index 68563d5de3d..7cb24ff95fc 100644 --- a/pkg/odo/cli/create/namespace/namespace.go +++ b/pkg/odo/cli/create/namespace/namespace.go @@ -82,29 +82,21 @@ 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) - // Set the current namespace when created - err = nco.clientset.ProjectClient.SetCurrent(nco.namespaceName) - if err != nil { - return err - } + // If the --wait parameter has been passed, we add a spinner.. if nco.waitFlag { - var timeOut = time.After(nco.clientset.PreferenceClient.GetTimeout()) + 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 { @@ -124,6 +116,13 @@ func (nco *NamespaceCreateOptions) Run(ctx context.Context) (err error) { 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) From 14b846b4394c27b8f083775b7eeb602f4bbde89b Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Tue, 27 Jun 2023 17:12:36 +0530 Subject: [PATCH 5/5] Attempt at fixing doc tests Signed-off-by: Parthvi Vala --- .../docs-mdx/create-namespace/create_namespace.mdx | 1 + .../docs-mdx/create-namespace/create_project.mdx | 1 + .../quickstart/docs-mdx/create_namespace_output.mdx | 1 + .../user-guides/quickstart/docs-mdx/create_project_output.mdx | 1 + tests/helper/helper_documentation.go | 4 +++- 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/website/docs/command-reference/docs-mdx/create-namespace/create_namespace.mdx b/docs/website/docs/command-reference/docs-mdx/create-namespace/create_namespace.mdx index 2baff5ffb35..f798259abb1 100644 --- a/docs/website/docs/command-reference/docs-mdx/create-namespace/create_namespace.mdx +++ b/docs/website/docs/command-reference/docs-mdx/create-namespace/create_namespace.mdx @@ -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 ``` \ No newline at end of file diff --git a/docs/website/docs/command-reference/docs-mdx/create-namespace/create_project.mdx b/docs/website/docs/command-reference/docs-mdx/create-namespace/create_project.mdx index 3ac119d7f7b..488da4e0347 100644 --- a/docs/website/docs/command-reference/docs-mdx/create-namespace/create_project.mdx +++ b/docs/website/docs/command-reference/docs-mdx/create-namespace/create_project.mdx @@ -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 ``` \ No newline at end of file diff --git a/docs/website/docs/user-guides/quickstart/docs-mdx/create_namespace_output.mdx b/docs/website/docs/user-guides/quickstart/docs-mdx/create_namespace_output.mdx index 5534c628825..e03877af021 100644 --- a/docs/website/docs/user-guides/quickstart/docs-mdx/create_namespace_output.mdx +++ b/docs/website/docs/user-guides/quickstart/docs-mdx/create_namespace_output.mdx @@ -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 ``` \ No newline at end of file diff --git a/docs/website/docs/user-guides/quickstart/docs-mdx/create_project_output.mdx b/docs/website/docs/user-guides/quickstart/docs-mdx/create_project_output.mdx index 941df0820db..6019d4db4ef 100644 --- a/docs/website/docs/user-guides/quickstart/docs-mdx/create_project_output.mdx +++ b/docs/website/docs/user-guides/quickstart/docs-mdx/create_project_output.mdx @@ -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 ``` \ No newline at end of file diff --git a/tests/helper/helper_documentation.go b/tests/helper/helper_documentation.go index 3c041b96469..a42716a8edd 100644 --- a/tests/helper/helper_documentation.go +++ b/tests/helper/helper_documentation.go @@ -41,7 +41,9 @@ func StripSpinner(docString string) (returnString string) { if (strings.HasPrefix(line, "• Downloading") || strings.HasPrefix(line, "• Syncing") || strings.HasPrefix(line, "• Building") || - strings.HasPrefix(line, "• Waiting for the application")) && + strings.HasPrefix(line, "• Waiting for the application") || + strings.HasPrefix(line, "• Creating the namespace") || + strings.HasPrefix(line, "• Creating the project")) && strings.HasSuffix(line, "...") { continue }