diff --git a/cmd/cluster/cluster.go b/cmd/cluster/cluster.go index c514bb9d5..fd51bd6c1 100644 --- a/cmd/cluster/cluster.go +++ b/cmd/cluster/cluster.go @@ -37,6 +37,7 @@ func NewClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comm } clusterRootCmd.AddCommand(NewInitInfraCommand(rootSettings)) + clusterRootCmd.AddCommand(NewInitCommand(rootSettings)) return clusterRootCmd } diff --git a/cmd/cluster/cluster_test.go b/cmd/cluster/cluster_test.go index ccb522ad5..79415d862 100644 --- a/cmd/cluster/cluster_test.go +++ b/cmd/cluster/cluster_test.go @@ -35,6 +35,11 @@ func TestNewClusterCommand(t *testing.T) { CmdLine: "--help", Cmd: cluster.NewClusterCommand(fakeRootSettings), }, + { + Name: "cluster-init-cmd-with-help", + CmdLine: "--help", + Cmd: cluster.NewInitCommand(fakeRootSettings), + }, } for _, testcase := range tests { testutil.RunTest(t, testcase) diff --git a/cmd/cluster/init.go b/cmd/cluster/init.go new file mode 100644 index 000000000..47cf61837 --- /dev/null +++ b/cmd/cluster/init.go @@ -0,0 +1,89 @@ +/* +Copyright 2014 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cluster + +import ( + "github.com/spf13/cobra" + + clusterctlcmd "opendev.org/airship/airshipctl/pkg/clusterctl/cmd" + "opendev.org/airship/airshipctl/pkg/environment" +) + +const ( + initLong = ` +Initialize cluster-api providers based on airshipctl document set. +document set must contain document of Kind: Clusterctl in phase initinfra. +Path to initinfra phase is built based on airshipctl config +//ephemeral/initinfra. +Clusterctl document example: +--- +apiVersion: airshipit.org/v1alpha1 +kind: Clusterctl +metadata: + labels: + airshipit.org/deploy-k8s: "false" + name: clusterctl-v1 +init-options: + core-provider: "cluster-api:v0.3.3" + bootstrap-providers: + - "kubeadm:v0.3.3" + infrastructure-providers: + - "metal3:v0.3.1" + control-plane-providers: + - "kubeadm:v0.3.3" +providers: + - name: "metal3" + type: "InfrastructureProvider" + versions: + v0.3.1: manifests/function/capm3/v0.3.1 + - name: "kubeadm" + type: "BootstrapProvider" + versions: + v0.3.3: manifests/function/cabpk/v0.3.3 + - name: "cluster-api" + type: "CoreProvider" + versions: + v0.3.3: manifests/function/capi/v0.3.3 + - name: "kubeadm" + type: "ControlPlaneProvider" + versions: + v0.3.3: manifests/function/cacpk/v0.3.3 +` + + initExample = ` +# Initialize clusterctl providers and components +airshipctl cluster init +` +) + +// NewInitCommand creates a command to deploy cluster-api +func NewInitCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { + initCmd := &cobra.Command{ + Use: "init", + Short: "Deploy cluster-api provider components", + Long: initLong, + Example: initExample, + RunE: func(cmd *cobra.Command, args []string) error { + command, err := clusterctlcmd.NewCommand(rootSettings) + if err != nil { + return err + } + return command.Init() + }, + } + return initCmd +} diff --git a/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-cmd-with-help.golden b/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-cmd-with-help.golden index 8a68ecb62..23e5a1173 100644 --- a/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-cmd-with-help.golden +++ b/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-cmd-with-help.golden @@ -6,6 +6,7 @@ Usage: Available Commands: help Help about any command + init Deploy cluster-api provider components initinfra Deploy initinfra components to cluster Flags: diff --git a/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-init-cmd-with-help.golden b/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-init-cmd-with-help.golden new file mode 100644 index 000000000..688373a41 --- /dev/null +++ b/cmd/cluster/testdata/TestNewClusterCommandGoldenOutput/cluster-init-cmd-with-help.golden @@ -0,0 +1,50 @@ + +Initialize cluster-api providers based on airshipctl document set. +document set must contain document of Kind: Clusterctl in phase initinfra. +Path to initinfra phase is built based on airshipctl config +//ephemeral/initinfra. +Clusterctl document example: +--- +apiVersion: airshipit.org/v1alpha1 +kind: Clusterctl +metadata: + labels: + airshipit.org/deploy-k8s: "false" + name: clusterctl-v1 +init-options: + core-provider: "cluster-api:v0.3.3" + bootstrap-providers: + - "kubeadm:v0.3.3" + infrastructure-providers: + - "metal3:v0.3.1" + control-plane-providers: + - "kubeadm:v0.3.3" +providers: + - name: "metal3" + type: "InfrastructureProvider" + versions: + v0.3.1: manifests/function/capm3/v0.3.1 + - name: "kubeadm" + type: "BootstrapProvider" + versions: + v0.3.3: manifests/function/cabpk/v0.3.3 + - name: "cluster-api" + type: "CoreProvider" + versions: + v0.3.3: manifests/function/capi/v0.3.3 + - name: "kubeadm" + type: "ControlPlaneProvider" + versions: + v0.3.3: manifests/function/cacpk/v0.3.3 + +Usage: + init [flags] + +Examples: + +# Initialize clusterctl providers and components +airshipctl cluster init + + +Flags: + -h, --help help for init