mirror of
https://github.com/rancher/cli.git
synced 2026-02-05 09:48:36 +01:00
Wait for namespace to be ready
Problem: An app creates a namespace to deploy into and depending on the system it might not be ready when attempting to install the app Solution: Poll the namespace to ensure it's active before proceeding with installing the app
This commit is contained in:
committed by
Craig Jellick
parent
221e9254b7
commit
9b191d3983
21
cmd/app.go
21
cmd/app.go
@@ -16,6 +16,7 @@ import (
|
||||
clusterClient "github.com/rancher/types/client/cluster/v3"
|
||||
managementClient "github.com/rancher/types/client/management/v3"
|
||||
projectClient "github.com/rancher/types/client/project/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -687,10 +688,28 @@ func createNamespace(c *cliclient.MasterClient, n string) error {
|
||||
ProjectID: c.UserConfig.Project,
|
||||
}
|
||||
|
||||
_, err = c.ClusterClient.Namespace.Create(newNamespace)
|
||||
ns, err := c.ClusterClient.Namespace.Create(newNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
for {
|
||||
logrus.Debug(fmt.Sprintf("Namespace create wait - Name: %s, State: %s, Transitioning: %s", ns.Name, ns.State, ns.Transitioning))
|
||||
if time.Since(startTime)/time.Second > 30 {
|
||||
return fmt.Errorf("timed out waiting for new namespace %s", ns.Name)
|
||||
}
|
||||
ns, err = c.ClusterClient.Namespace.ByID(ns.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ns.State == "active" {
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
} else {
|
||||
if namespaces.Data[0].ProjectID != c.UserConfig.Project {
|
||||
return fmt.Errorf("namespace %s already exists", n)
|
||||
|
||||
@@ -19,6 +19,9 @@ func NamespaceCommand() cli.Command {
|
||||
Aliases: []string{"namespace"},
|
||||
Usage: "Operations on namespaces",
|
||||
Action: defaultAction(namespaceLs),
|
||||
Flags: []cli.Flag{
|
||||
quietFlag,
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "ls",
|
||||
|
||||
Reference in New Issue
Block a user