From c58862e17eafb08265f54f92d533b8b015c10858 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Mon, 30 Sep 2019 16:13:04 -0500 Subject: [PATCH] [AIR-97] Adding base airshipctl cluster command New subcommands will be added later, this commit is a simple base for other commits related to airshipctl cluster command Change-Id: I77057c291b88bae3b8fca08ddf56bdf6d183fd24 --- cmd/cluster/cluster.go | 24 +++++++++++++++++++ cmd/cluster/cluster_test.go | 21 ++++++++++++++++ .../cluster-cmd-with-defaults.golden | 2 ++ cmd/root.go | 2 ++ .../rootCmd-with-defaults.golden | 3 +++ 5 files changed, 52 insertions(+) create mode 100644 cmd/cluster/cluster.go create mode 100644 cmd/cluster/cluster_test.go create mode 100644 cmd/cluster/testdata/TestNewClusterCommandReturnGoldenOutput/cluster-cmd-with-defaults.golden diff --git a/cmd/cluster/cluster.go b/cmd/cluster/cluster.go new file mode 100644 index 000000000..72a9fb919 --- /dev/null +++ b/cmd/cluster/cluster.go @@ -0,0 +1,24 @@ +package cluster + +import ( + "github.com/spf13/cobra" + + "opendev.org/airship/airshipctl/pkg/environment" +) + +var ( + // ClusterUse subcommand string + ClusterUse = "cluster" +) + +// NewClusterCommand returns cobra command object of the airshipctl cluster and adds it's subcommands. +func NewClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { + clusterRootCmd := &cobra.Command{ + Use: ClusterUse, + // TODO: (kkalynovskyi) Add more description when more subcommands are added + Short: "Control kubernetes cluster", + Long: "Interactions with kubernetes cluster, such as get status, deploy initial infrastructure", + } + + return clusterRootCmd +} diff --git a/cmd/cluster/cluster_test.go b/cmd/cluster/cluster_test.go new file mode 100644 index 000000000..c045a5135 --- /dev/null +++ b/cmd/cluster/cluster_test.go @@ -0,0 +1,21 @@ +package cluster_test + +import ( + "testing" + + "opendev.org/airship/airshipctl/cmd/cluster" + "opendev.org/airship/airshipctl/testutil" +) + +func TestNewClusterCommandReturn(t *testing.T) { + tests := []*testutil.CmdTest{ + { + Name: "cluster-cmd-with-defaults", + CmdLine: "", + Cmd: cluster.NewClusterCommand(nil), + }, + } + for _, testcase := range tests { + testutil.RunTest(t, testcase) + } +} diff --git a/cmd/cluster/testdata/TestNewClusterCommandReturnGoldenOutput/cluster-cmd-with-defaults.golden b/cmd/cluster/testdata/TestNewClusterCommandReturnGoldenOutput/cluster-cmd-with-defaults.golden new file mode 100644 index 000000000..bc7b484cc --- /dev/null +++ b/cmd/cluster/testdata/TestNewClusterCommandReturnGoldenOutput/cluster-cmd-with-defaults.golden @@ -0,0 +1,2 @@ +Interactions with kubernetes cluster, such as get status, deploy initial infrastructure + diff --git a/cmd/root.go b/cmd/root.go index d56ee115f..018e3c4ce 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,6 +13,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" "opendev.org/airship/airshipctl/cmd/bootstrap" + "opendev.org/airship/airshipctl/cmd/cluster" "opendev.org/airship/airshipctl/cmd/completion" "opendev.org/airship/airshipctl/cmd/document" "opendev.org/airship/airshipctl/pkg/environment" @@ -51,6 +52,7 @@ func NewRootCmd(out io.Writer) (*cobra.Command, *environment.AirshipCTLSettings, func AddDefaultAirshipCTLCommands(cmd *cobra.Command, settings *environment.AirshipCTLSettings) *cobra.Command { cmd.AddCommand(argo.NewCommand()) cmd.AddCommand(bootstrap.NewBootstrapCommand(settings)) + cmd.AddCommand(cluster.NewClusterCommand(settings)) cmd.AddCommand(completion.NewCompletionCommand()) cmd.AddCommand(document.NewDocumentCommand(settings)) cmd.AddCommand(kubectl.NewDefaultKubectlCommand()) diff --git a/cmd/testdata/TestRootGoldenOutput/rootCmd-with-defaults.golden b/cmd/testdata/TestRootGoldenOutput/rootCmd-with-defaults.golden index 91771afdc..4b455106c 100644 --- a/cmd/testdata/TestRootGoldenOutput/rootCmd-with-defaults.golden +++ b/cmd/testdata/TestRootGoldenOutput/rootCmd-with-defaults.golden @@ -17,4 +17,7 @@ Flags: --debug enable verbose output -h, --help help for airshipctl +Additional help topics: + airshipctl cluster Control kubernetes cluster + Use "airshipctl [command] --help" for more information about a command.