Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Avoid printing deprecation notices on KVM (#615)
Browse files Browse the repository at this point in the history
* Add utility function to format deprecation notice

* Only display deprecation notices for non-kvm installations

* Move provider checking logic to 'GetDeprecatedNotice' utility function and add tests

* Print deprecated notice

* Highlight command literals with yellow and remove double quotes

* Also remove quotes from test output
  • Loading branch information
kuosandys committed Feb 1, 2022
1 parent 67c2be4 commit 50be06f
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 30 deletions.
7 changes: 3 additions & 4 deletions commands/create/cluster/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/giantswarm/gsctl/commands/types"
"github.com/giantswarm/gsctl/flags"
"github.com/giantswarm/gsctl/formatting"
"github.com/giantswarm/gsctl/util"
)

// Arguments contains all possible input parameter needed
Expand Down Expand Up @@ -201,10 +202,6 @@ suppress the creation of the default node pool by setting the flag
gsctl create cluster \
--owner acme \
--create-default-nodepool=false
`,
Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs template cluster' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/template-cluster/
`,
PreRun: printValidation,
Run: printResult,
Expand Down Expand Up @@ -236,6 +233,8 @@ func initFlags() {
// If errors occur, error info is printed to STDOUT/STDERR
// and the program will exit with non-zero exit codes.
func printValidation(cmd *cobra.Command, positionalArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "create cluster", "template cluster", "https://docs.giantswarm.io/ui-api/kubectl-gs/template-cluster/"))

arguments = collectArguments(cmd)

headline := ""
Expand Down
6 changes: 2 additions & 4 deletions commands/create/keypair/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ var (
Use: "keypair",
Short: "Create key pair",
Long: `Creates a new key pair for a cluster
`,
Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs login' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/login/
`,
PreRun: printValidation,
Run: printResult,
Expand Down Expand Up @@ -131,6 +127,8 @@ func init() {
}

func printValidation(cmd *cobra.Command, cmdLineArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "create keypair", "login", "https://docs.giantswarm.io/ui-api/kubectl-gs/login/"))

var argsErr error

arguments, argsErr = collectArguments()
Expand Down
6 changes: 2 additions & 4 deletions commands/create/kubeconfig/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ Examples:
gsctl create kubeconfig -c my0c3 --ttl 3h -d "Key pair living for only 3 hours"
gsctl create kubeconfig -c "Development cluster" --certificate-organizations system:masters
`,
Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs login' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/login/
`,
PreRun: createKubeconfigPreRunOutput,
Run: createKubeconfigRunOutput,
Expand Down Expand Up @@ -239,6 +235,8 @@ func init() {

// createKubeconfigPreRunOutput shows our pre-check results
func createKubeconfigPreRunOutput(cmd *cobra.Command, cmdLineArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "create kubeconfig", "login", "https://docs.giantswarm.io/ui-api/kubectl-gs/login/"))

var argsErr error

arguments, argsErr = collectArguments(cmd)
Expand Down
9 changes: 3 additions & 6 deletions commands/create/nodepool/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/giantswarm/gsctl/commands/errors"
"github.com/giantswarm/gsctl/flags"
"github.com/giantswarm/gsctl/pkg/provider"
"github.com/giantswarm/gsctl/util"
)

var (
Expand Down Expand Up @@ -130,12 +131,6 @@ Examples:
to the on-demand price of the instance.
`,

Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs template nodepool' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/template-nodepool/
`,

// PreRun checks a few general things, like authentication.
PreRun: printValidation,

Expand Down Expand Up @@ -346,6 +341,8 @@ func verifyPreconditions(args Arguments) error {
}

func printValidation(cmd *cobra.Command, positionalArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "create nodepool", "template nodepool", "https://docs.giantswarm.io/ui-api/kubectl-gs/template-nodepool/"))

var err error

arguments, err = collectArguments(cmd, positionalArgs)
Expand Down
6 changes: 2 additions & 4 deletions commands/list/clusters/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ Examples:
gsctl list clusters --selector environment=testing
gsctl list clusters --sort org
`,
Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs get clusters' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/get-clusters/
`,
PreRun: printValidation,
Run: printResult,
Expand Down Expand Up @@ -125,6 +121,8 @@ func collectArguments() Arguments {
}

func printValidation(cmd *cobra.Command, cmdLineArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "list clusters", "get clusters", "https://docs.giantswarm.io/ui-api/kubectl-gs/get-clusters/"))

arguments = collectArguments()
err := verifyListClusterPreconditions(arguments)

Expand Down
7 changes: 3 additions & 4 deletions commands/list/nodepools/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/cobra"

"github.com/giantswarm/gsctl/clustercache"
"github.com/giantswarm/gsctl/util"

"github.com/giantswarm/gsctl/client"
"github.com/giantswarm/gsctl/commands/errors"
Expand Down Expand Up @@ -57,10 +58,6 @@ columns:
To see all available details for a cluster, use 'gsctl show nodepool <cluster-id>/<nodepool-id>'.
To list all clusters you have access to, use 'gsctl list clusters'.
`,
Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs get nodepools' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/get-nodepools/
`,
PreRun: printValidation,
Run: printResult,
Expand Down Expand Up @@ -121,6 +118,8 @@ func verifyPreconditions(args Arguments, positionalArgs []string) error {
}

func printValidation(cmd *cobra.Command, positionalArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "list nodepools", "get nodepools", "https://docs.giantswarm.io/ui-api/kubectl-gs/get-nodepools/"))

arguments = collectArguments(positionalArgs)
err := verifyPreconditions(arguments, positionalArgs)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions commands/list/releases/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ Output
- COREDNS: The CodeDNS version provided.
- CALICO: The Project Calico version provided.
`,
Deprecated: `gsctl is being phased out in favour of our 'kubectl gs' plugin.
We recommend you familiarize yourself with the 'kubectl gs get releases' command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/get-releases/
`,
PreRun: printValidation,
Run: printResult,
Expand Down Expand Up @@ -112,6 +108,8 @@ func collectArguments() Arguments {
// printValidation does our pre-checks and shows errors, in case
// something is missing.
func printValidation(cmd *cobra.Command, extraArgs []string) {
fmt.Print(util.GetDeprecatedNotice(config.Config.Provider, "list releases", "get releases", "https://docs.giantswarm.io/ui-api/kubectl-gs/get-releases/"))

arguments = collectArguments()
err := listReleasesPreconditions(&arguments)

Expand Down
20 changes: 20 additions & 0 deletions util/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package util

import (
"fmt"

"github.com/fatih/color"
p "github.com/giantswarm/gsctl/pkg/provider"
)

func GetDeprecatedNotice(provider, gsctlCmd, kubectlgsCmd, docsURL string) string {
if provider == p.KVM {
return ""
}

return fmt.Sprintf(`Command %s is deprecated, gsctl is being phased out in favor of our kubectl-gs plugin.
We recommend you familiarize yourself with the %s command as a replacement for this.
For more details see: %s
`, color.YellowString(gsctlCmd), color.YellowString("kubectl gs "+kubectlgsCmd), docsURL)
}
54 changes: 54 additions & 0 deletions util/deprecated_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package util

import (
"testing"

"github.com/giantswarm/gsctl/pkg/provider"
)

func TestGetDeprecatedNotice(t *testing.T) {
var testCases = []struct {
provider string
gsctlCmd string
kubectlgsCmd string
docsURL string
output string
}{
{
provider: provider.AWS,
gsctlCmd: "list something",
kubectlgsCmd: "get something",
docsURL: "https://docs.giantswarm.io/ui-api/kubectl-gs/get-something/",
output: `Command list something is deprecated, gsctl is being phased out in favor of our kubectl-gs plugin.
We recommend you familiarize yourself with the kubectl gs get something command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/get-something/
`,
},
{
provider: provider.Azure,
gsctlCmd: "list something",
kubectlgsCmd: "get something",
docsURL: "https://docs.giantswarm.io/ui-api/kubectl-gs/get-something/",
output: `Command list something is deprecated, gsctl is being phased out in favor of our kubectl-gs plugin.
We recommend you familiarize yourself with the kubectl gs get something command as a replacement for this.
For more details see: https://docs.giantswarm.io/ui-api/kubectl-gs/get-something/
`,
},
{
provider: provider.KVM,
gsctlCmd: "list anotherthing",
kubectlgsCmd: "get anotherthing",
docsURL: "https://docs.giantswarm.io/ui-api/kubectl-gs/get-anotherthing/",
output: "",
},
}

for _, tc := range testCases {
notice := GetDeprecatedNotice(tc.provider, tc.gsctlCmd, tc.kubectlgsCmd, tc.docsURL)
if notice != tc.output {
t.Errorf("Got '%s', wanted '%s'", notice, tc.output)
}
}
}

0 comments on commit 50be06f

Please sign in to comment.