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

View File

@ -12,7 +12,7 @@
limitations under the License. limitations under the License.
*/ */
package bootstrap package baremetal
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -21,15 +21,15 @@ import (
"opendev.org/airship/airshipctl/pkg/environment" "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 { func NewISOGenCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
imageGen := &cobra.Command{ cmd := &cobra.Command{
Use: "isogen", Use: "isogen",
Short: "Generate bootstrap ISO image", Short: "Generate baremetal host ISO image",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return isogen.GenerateBootstrapIso(rootSettings) return isogen.GenerateBootstrapIso(rootSettings)
}, },
} }
return imageGen return cmd
} }

View File

@ -12,7 +12,7 @@
limitations under the License. limitations under the License.
*/ */
package bootstrap package baremetal
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -25,9 +25,9 @@ import (
// NewRemoteDirectCommand provides a command with the capability to perform remote direct operations. // NewRemoteDirectCommand provides a command with the capability to perform remote direct operations.
func NewRemoteDirectCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { func NewRemoteDirectCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
remoteDirect := &cobra.Command{ cmd := &cobra.Command{
Use: "remotedirect", Use: "remotedirect",
Short: "Bootstrap ephemeral node", Short: "Bootstrap the ephemeral host",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
manager, err := remote.NewManager(rootSettings, manager, err := remote.NewManager(rootSettings,
config.BootstrapPhase, 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. limitations under the License.
*/ */
package bootstrap_test package baremetal_test
import ( import (
"testing" "testing"
"opendev.org/airship/airshipctl/cmd/bootstrap" "opendev.org/airship/airshipctl/cmd/baremetal"
"opendev.org/airship/airshipctl/testutil" "opendev.org/airship/airshipctl/testutil"
) )
func TestBootstrap(t *testing.T) { func TestBaremetal(t *testing.T) {
tests := []*testutil.CmdTest{ tests := []*testutil.CmdTest{
{ {
Name: "bootstrap-isogen-cmd-with-help", Name: "isogen",
CmdLine: "isogen --help", CmdLine: "-h",
Cmd: bootstrap.NewBootstrapCommand(nil), Cmd: baremetal.NewISOGenCommand(nil),
},
{
Name: "remotedirect",
CmdLine: "-h",
Cmd: baremetal.NewRemoteDirectCommand(nil),
}, },
} }
for _, tt := range tests { for _, tt := range tests {
testutil.RunTest(t, tt) 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: Usage:
remotedirect [flags] 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. // Import to initialize client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "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/cluster"
"opendev.org/airship/airshipctl/cmd/completion" "opendev.org/airship/airshipctl/cmd/completion"
"opendev.org/airship/airshipctl/cmd/config" "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 // AddDefaultAirshipCTLCommands is a convenience function for adding all of the
// default commands to airshipctl // default commands to airshipctl
func AddDefaultAirshipCTLCommands(cmd *cobra.Command, settings *environment.AirshipCTLSettings) *cobra.Command { 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(cluster.NewClusterCommand(settings))
cmd.AddCommand(completion.NewCompletionCommand()) cmd.AddCommand(completion.NewCompletionCommand())
cmd.AddCommand(document.NewDocumentCommand(settings)) cmd.AddCommand(document.NewDocumentCommand(settings))

View File

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

View File

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

View File

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

View File

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

View File

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