Move bootstrap cmd functionality to baremetal cmd

Early airshipctl usage has identified the need to control the power of
remote hosts directly from airshipctl. This functionality is typically
required during the bootstrapping phase of airshipctl; however, the
functionality could be used anytime. A logical home for this
functionality would be in a baremetal command, not a bootstrap command.
Since all functionality performed by the bootstrap command is performed on
baremetal hosts, a natural need has developed to group this
functionality together under one baremetal command.

This change moves all functionality from the bootstrap command to a new
baremetal command.

airshipctl baremetal isogen         generate ephemeral node ISO
airshipctl baremetal remotedirect   bootstrap ephemeral node

Change-Id: Ia615224686d97c95d78c3773c2b9f41df9d06ed6
Signed-off-by: Drew Walters <andrew.walters@att.com>
This commit is contained in:
Drew Walters 2020-04-10 20:39:24 +00:00
parent 995538829e
commit e34edc0ce2
14 changed files with 47 additions and 74 deletions

View File

@ -12,7 +12,7 @@
limitations under the License.
*/
package bootstrap
package baremetal
import (
"github.com/spf13/cobra"
@ -20,18 +20,18 @@ import (
"opendev.org/airship/airshipctl/pkg/environment"
)
// NewBootstrapCommand creates a new command for bootstrapping airshipctl
func NewBootstrapCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
bootstrapRootCmd := &cobra.Command{
Use: "bootstrap",
Short: "Bootstrap ephemeral Kubernetes cluster",
// NewBaremetalCommand creates a new command for interacting with baremetal using airshipctl.
func NewBaremetalCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
cmd := &cobra.Command{
Use: "baremetal",
Short: "Perform actions on baremetal hosts",
}
isoGenCmd := NewISOGenCommand(rootSettings)
bootstrapRootCmd.AddCommand(isoGenCmd)
cmd.AddCommand(isoGenCmd)
remoteDirectCmd := NewRemoteDirectCommand(rootSettings)
bootstrapRootCmd.AddCommand(remoteDirectCmd)
cmd.AddCommand(remoteDirectCmd)
return bootstrapRootCmd
return cmd
}

View File

@ -12,7 +12,7 @@
limitations under the License.
*/
package bootstrap
package baremetal
import (
"github.com/spf13/cobra"
@ -21,15 +21,15 @@ import (
"opendev.org/airship/airshipctl/pkg/environment"
)
// NewISOGenCommand creates a new command for ISO image creation
// NewISOGenCommand creates a new command with the capability to generate the ephemeral node ISO image.
func NewISOGenCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
imageGen := &cobra.Command{
cmd := &cobra.Command{
Use: "isogen",
Short: "Generate bootstrap ISO image",
Short: "Generate baremetal host ISO image",
RunE: func(cmd *cobra.Command, args []string) error {
return isogen.GenerateBootstrapIso(rootSettings)
},
}
return imageGen
return cmd
}

View File

@ -12,7 +12,7 @@
limitations under the License.
*/
package bootstrap
package baremetal
import (
"github.com/spf13/cobra"
@ -25,9 +25,9 @@ import (
// NewRemoteDirectCommand provides a command with the capability to perform remote direct operations.
func NewRemoteDirectCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
remoteDirect := &cobra.Command{
cmd := &cobra.Command{
Use: "remotedirect",
Short: "Bootstrap ephemeral node",
Short: "Bootstrap the ephemeral host",
RunE: func(cmd *cobra.Command, args []string) error {
manager, err := remote.NewManager(rootSettings,
config.BootstrapPhase,
@ -45,5 +45,5 @@ func NewRemoteDirectCommand(rootSettings *environment.AirshipCTLSettings) *cobra
},
}
return remoteDirect
return cmd
}

View File

@ -12,23 +12,29 @@
limitations under the License.
*/
package bootstrap_test
package baremetal_test
import (
"testing"
"opendev.org/airship/airshipctl/cmd/bootstrap"
"opendev.org/airship/airshipctl/cmd/baremetal"
"opendev.org/airship/airshipctl/testutil"
)
func TestBootstrap(t *testing.T) {
func TestBaremetal(t *testing.T) {
tests := []*testutil.CmdTest{
{
Name: "bootstrap-isogen-cmd-with-help",
CmdLine: "isogen --help",
Cmd: bootstrap.NewBootstrapCommand(nil),
Name: "isogen",
CmdLine: "-h",
Cmd: baremetal.NewISOGenCommand(nil),
},
{
Name: "remotedirect",
CmdLine: "-h",
Cmd: baremetal.NewRemoteDirectCommand(nil),
},
}
for _, tt := range tests {
testutil.RunTest(t, tt)
}

View File

@ -0,0 +1,7 @@
Generate baremetal host ISO image
Usage:
isogen [flags]
Flags:
-h, --help help for isogen

View File

@ -1,4 +1,4 @@
Bootstrap ephemeral node
Bootstrap the ephemeral host
Usage:
remotedirect [flags]

View File

@ -1,34 +0,0 @@
/*
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
https://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 bootstrap
import (
"testing"
"opendev.org/airship/airshipctl/testutil"
)
func TestRemoteDirect(t *testing.T) {
tests := []*testutil.CmdTest{
{
Name: "remotedirect-cmd-with-help",
CmdLine: "remotedirect --help",
Cmd: NewRemoteDirectCommand(nil),
},
}
for _, tt := range tests {
testutil.RunTest(t, tt)
}
}

View File

@ -1,7 +0,0 @@
Generate bootstrap ISO image
Usage:
bootstrap isogen [flags]
Flags:
-h, --help help for isogen

View File

@ -22,7 +22,7 @@ import (
// Import to initialize client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"opendev.org/airship/airshipctl/cmd/bootstrap"
"opendev.org/airship/airshipctl/cmd/baremetal"
"opendev.org/airship/airshipctl/cmd/cluster"
"opendev.org/airship/airshipctl/cmd/completion"
"opendev.org/airship/airshipctl/cmd/config"
@ -66,7 +66,7 @@ func NewRootCommand(out io.Writer) (*cobra.Command, *environment.AirshipCTLSetti
// AddDefaultAirshipCTLCommands is a convenience function for adding all of the
// default commands to airshipctl
func AddDefaultAirshipCTLCommands(cmd *cobra.Command, settings *environment.AirshipCTLSettings) *cobra.Command {
cmd.AddCommand(bootstrap.NewBootstrapCommand(settings))
cmd.AddCommand(baremetal.NewBaremetalCommand(settings))
cmd.AddCommand(cluster.NewClusterCommand(settings))
cmd.AddCommand(completion.NewCompletionCommand())
cmd.AddCommand(document.NewDocumentCommand(settings))

View File

@ -23,7 +23,7 @@ import (
"github.com/stretchr/testify/require"
"opendev.org/airship/airshipctl/cmd"
"opendev.org/airship/airshipctl/cmd/bootstrap"
"opendev.org/airship/airshipctl/cmd/baremetal"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/testutil"
)
@ -105,7 +105,8 @@ func getDefaultRootCommand(t *testing.T) *cobra.Command {
}
func getSpecializedRootCommand(t *testing.T) *cobra.Command {
t.Helper()
rootCmd := getVanillaRootCommand(t)
rootCmd.AddCommand(bootstrap.NewBootstrapCommand(&environment.AirshipCTLSettings{}))
rootCmd.AddCommand(baremetal.NewBaremetalCommand(&environment.AirshipCTLSettings{}))
return rootCmd
}

View File

@ -4,7 +4,7 @@ Usage:
airshipctl [command]
Available Commands:
bootstrap Bootstrap ephemeral Kubernetes cluster
baremetal Perform actions on baremetal hosts
cluster Manage Kubernetes clusters
completion Generate completion script for the specified shell (bash or zsh)
config Manage the airshipctl config file

View File

@ -4,7 +4,7 @@ Usage:
airshipctl [command]
Available Commands:
bootstrap Bootstrap ephemeral Kubernetes cluster
baremetal Perform actions on baremetal hosts
help Help about any command
version Show the version number of airshipctl

View File

@ -19,7 +19,7 @@
become: true
- name: build ephemeral node iso
command: airshipctl bootstrap isogen
command: airshipctl baremetal isogen
environment:
http_proxy: "{{ proxy.http }}"
https_proxy: "{{ proxy.http }}"

View File

@ -12,7 +12,7 @@
- name: deploy ephemeral node using redfish
command: >-
airshipctl bootstrap remotedirect
airshipctl baremetal remotedirect
- name: check kubectl version
command: >-