diff --git a/Makefile b/Makefile index 17489321c5567113d5625b55e244d0c4b8f33840..a32f1940b63578d66867a35012ee99f39f5cfd20 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,9 @@ export GOPROXY=https://proxy.golang.org,direct export ENV=development -LDFLAGS+=-X k8s.io/client-go/pkg/version.gitVersion=v1.0.2 +LDFLAGS+=-X k8s.io/client-go/pkg/version.gitVersion=v1.2.2 LDFLAGS+=-X k8s.io/client-go/pkg/version.gitCommit=4f75300 -LDFLAGS+=-X github.com/openshift/oc/pkg/version.versionFromGit=v1.0.2 +LDFLAGS+=-X github.com/openshift/oc/pkg/version.versionFromGit=v1.2.2 LDFLAGS+=-X github.com/openshift/oc/pkg/version.commitFromGit=4f75300 build: go build -v -o $(ROOT)/bin/arvan -ldflags="$(LDFLAGS)" $(ROOT)/cmd/arvan/*.go diff --git a/go.mod b/go.mod index 5ab9b9833eaad451b9f15027a285a7db702c40d0..ab668ab69f24c4cbd72b9b3ed90b5ad708263f31 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/spf13/cobra v1.1.1 github.com/xeipuuv/gojsonschema v1.2.0 // indirect golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect + golang.org/x/text v0.3.4 gopkg.in/yaml.v2 v2.3.0 k8s.io/api v0.20.0-beta.2 k8s.io/apimachinery v0.20.0-beta.2 diff --git a/pkg/paas/migration.go b/pkg/paas/migration.go index 6c8ec087b4e0c305fdff52f4748ba5b0d6004184..0c315615f7066921d688b62750d546e5a4943bd5 100644 --- a/pkg/paas/migration.go +++ b/pkg/paas/migration.go @@ -23,9 +23,17 @@ import ( "github.com/olekukonko/tablewriter" "github.com/openshift/oc/pkg/helpers/term" "github.com/spf13/cobra" + "golang.org/x/text/cases" + "golang.org/x/text/language" "k8s.io/client-go/rest" ) +var ( + migrateLong = ` + Migration of user's namespaces from one region to another + ` +) + const ( migrationEndpoint = "/paas/v1/%s/migrate" redColor = "\033[31m" @@ -97,7 +105,7 @@ func NewCmdMigrate(in io.Reader, out, errout io.Writer) *cobra.Command { cmd := &cobra.Command{ Use: "migrate", Short: "Migrate namespaces to destination region", - Long: loginLong, + Long: migrateLong, Run: func(c *cobra.Command, args []string) { explainOut := term.NewResponsiveWriter(out) c.SetOutput(explainOut) @@ -129,7 +137,7 @@ func NewCmdMigrate(in io.Reader, out, errout io.Writer) *cobra.Command { } } - if response.State == Completed || response.State == Failed { + if response.StatusCode == http.StatusNotFound || response.State == Completed || response.State == Failed { project, err := getSelectedProject(in, explainOut) if err != nil { failureOutput(err.Error()) @@ -266,13 +274,13 @@ func sprintProjects(projects []string) string { // migrationConfirm gets confirmation of proceeding namespace migration by asking user to enter namespace's name. func migrationConfirm(project, region string, in io.Reader, writer io.Writer) bool { - explain := fmt.Sprintf("\nYou're about to migrate \"%s\" from region \"%s\" to \"%s\".\n", project, getCurrentRegion(), region) + explain := fmt.Sprintf("\nYou're about to migrate \"%s\" from region \"%s\" to \"%s\".\n\n"+yellowColor+"WARNING:\nThis will STOP applications during migration process. Your data would still be safe and available in source region. Migration is running in the background and may take a while. You can optionally detach(Ctrl+C) for now and continue monitoring the process after using 'arvan paas migrate'."+resetColor+"\n\n", project, getCurrentRegion(), region) _, err := fmt.Fprint(writer, explain) if err != nil { return false } - inputExplain := fmt.Sprintf(yellowColor+"\nWARNING:\nThis will STOP applications during migration process. Your data would still be safe and available in source region. Migration is running in the background and may take a while. You can optionally detach(Ctrl+C) for now and continue monitoring the process after using 'arvan paas migrate'."+resetColor+"\n\nPlease enter project's name [%s] to proceed: ", project) + inputExplain := fmt.Sprintf("Please enter project's name [%s] to proceed: ", project) defaultVal := "" @@ -362,7 +370,9 @@ func sprintResponse(response ProgressResponse, w io.Writer) error { detail = s.Data.Detail } - responseStr += fmt.Sprintf("\t%s \t\t\t%s\t%s\n", s.Title, strings.Title(s.State), detail) + caser := cases.Title(language.English) + + responseStr += fmt.Sprintf("\t%s \t\t\t%s\t%s\n", s.Title, caser.String(s.State), detail) } fmt.Fprintf(w, "%s", responseStr) @@ -456,6 +466,7 @@ func httpGet(endpoint string) (*ProgressResponse, error) { var response ProgressResponse err = json.Unmarshal(responseBody, &response) if err != nil { + failureOutput("Migration is running in the background. You can continue monitoring the process using 'arvan paas migrate'.") return nil, err } @@ -521,9 +532,7 @@ func successOutput(data StepData) { } nonFreeDomainTable.Render() - } - if len(freeSourceDomains) > 0 { gatewayTable := tablewriter.NewWriter(os.Stdout) gatewayTable.SetHeader([]string{"old gateway", "new gateway"})