From 4e7b4efa8f23a72e86a6b51a54826429f7503b0f Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Fri, 22 Jan 2021 20:21:44 +0000 Subject: [PATCH] Add inventory interface and cmd line integration Change-Id: If15ea99372358ea97c3b35b01781427e06400db1 --- cmd/baremetal/baremetal.go | 122 ++---------------- cmd/baremetal/baremetal_test.go | 30 +---- cmd/baremetal/ejectmedia.go | 6 +- cmd/baremetal/poweroff.go | 6 +- cmd/baremetal/poweron.go | 6 +- cmd/baremetal/powerstatus.go | 5 +- cmd/baremetal/reboot.go | 6 +- cmd/baremetal/remotedirect.go | 11 +- .../baremetal-ejectmedia-with-help.golden | 9 +- .../baremetal-poweroff-with-help.golden | 9 +- .../baremetal-poweron-with-help.golden | 9 +- .../baremetal-powerstatus-with-help.golden | 9 +- .../baremetal-reboot-with-help.golden | 9 +- .../baremetal-remotedirect-with-help.golden | 7 +- .../cli/airshipctl_baremetal_ejectmedia.md | 9 +- .../cli/airshipctl_baremetal_poweroff.md | 9 +- .../cli/airshipctl_baremetal_poweron.md | 9 +- .../cli/airshipctl_baremetal_powerstatus.md | 9 +- .../source/cli/airshipctl_baremetal_reboot.md | 9 +- .../cli/airshipctl_baremetal_remotedirect.md | 7 +- docs/source/cli/airshipctl_image_build.md | 2 +- .../host-inventory/ephemeral-patch.yaml | 20 +++ .../hostgenerator/host-generation.yaml | 14 ++ .../hostgenerator/kustomization.yaml | 10 ++ .../hostgenerator/patchesstrategicmerge.yaml | 41 ++++++ .../host-inventory/kustomization.yaml | 8 ++ manifests/site/test-site/metadata.yaml | 2 + .../test-site/target/catalogues/hosts.yaml | 15 ++- tools/deployment/25_deploy_ephemeral_node.sh | 5 +- .../31_deploy_initinfra_target_node.sh | 1 - 30 files changed, 221 insertions(+), 193 deletions(-) create mode 100644 manifests/site/test-site/host-inventory/ephemeral-patch.yaml create mode 100644 manifests/site/test-site/host-inventory/hostgenerator/host-generation.yaml create mode 100644 manifests/site/test-site/host-inventory/hostgenerator/kustomization.yaml create mode 100644 manifests/site/test-site/host-inventory/hostgenerator/patchesstrategicmerge.yaml create mode 100644 manifests/site/test-site/host-inventory/kustomization.yaml diff --git a/cmd/baremetal/baremetal.go b/cmd/baremetal/baremetal.go index 29d085fa0..c60254790 100644 --- a/cmd/baremetal/baremetal.go +++ b/cmd/baremetal/baremetal.go @@ -15,14 +15,12 @@ package baremetal import ( - "context" - "fmt" - "io" + "time" "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" - "opendev.org/airship/airshipctl/pkg/remote" + "opendev.org/airship/airshipctl/pkg/inventory" ) // Action type is used to perform specific baremetal action @@ -34,30 +32,19 @@ const ( flagLabelDescription = "Label(s) to filter desired baremetal host documents" flagName = "name" - flagNameShort = "n" flagNameDescription = "Name to filter desired baremetal host document" - flagPhase = "phase" - flagPhaseDescription = "airshipctl phase that contains the desired baremetal host document(s)" + flagNamespace = "namespace" + flagNamespaceSort = "n" + flagNamespaceDescription = "airshipctl phase that contains the desired baremetal host document(s)" - ejectAction Action = iota - powerOffAction - powerOnAction - powerStatusAction - rebootAction - remoteDirectAction + flagTimeout = "timeout" + flagTimeoutDescription = "timeout on baremetal action" ) -// CommonOptions is used to store common variables from cmd flags for baremetal command group -type CommonOptions struct { - labels string - name string - phase string -} - // NewBaremetalCommand creates a new command for interacting with baremetal using airshipctl. func NewBaremetalCommand(cfgFactory config.Factory) *cobra.Command { - options := &CommonOptions{} + options := inventory.NewOptions(inventory.NewInventory(cfgFactory)) baremetalRootCmd := &cobra.Command{ Use: "baremetal", Short: "Perform actions on baremetal hosts", @@ -73,93 +60,10 @@ func NewBaremetalCommand(cfgFactory config.Factory) *cobra.Command { return baremetalRootCmd } -func initFlags(options *CommonOptions, cmd *cobra.Command) { +func initFlags(options *inventory.CommandOptions, cmd *cobra.Command) { flags := cmd.Flags() - flags.StringVarP(&options.labels, flagLabel, flagLabelShort, "", flagLabelDescription) - flags.StringVarP(&options.name, flagName, flagNameShort, "", flagNameDescription) - flags.StringVar(&options.phase, flagPhase, config.BootstrapPhase, flagPhaseDescription) -} - -func performAction(cfgFactory config.Factory, options *CommonOptions, action Action, writer io.Writer) error { - cfg, err := cfgFactory() - if err != nil { - return err - } - - selectors := GetHostSelections(options.name, options.labels) - m, err := remote.NewManager(cfg, options.phase, selectors...) - if err != nil { - return err - } - - return selectAction(m, cfg, action, writer) -} - -func selectAction(m *remote.Manager, cfg *config.Config, action Action, writer io.Writer) error { - if action == remoteDirectAction { - if len(m.Hosts) != 1 { - return remote.NewRemoteDirectErrorf("more than one node defined as the ephemeral node") - } - - ephemeralHost := m.Hosts[0] - return ephemeralHost.DoRemoteDirect(cfg) - } - - ctx := context.Background() - for _, host := range m.Hosts { - switch action { - case ejectAction: - if err := host.EjectVirtualMedia(ctx); err != nil { - return err - } - - fmt.Fprintf(writer, "All media ejected from host '%s'.\n", host.HostName) - case powerOffAction: - if err := host.SystemPowerOff(ctx); err != nil { - return err - } - - fmt.Fprintf(writer, "Powered off host '%s'.\n", host.HostName) - case powerOnAction: - if err := host.SystemPowerOn(ctx); err != nil { - return err - } - - fmt.Fprintf(writer, "Powered on host '%s'.\n", host.HostName) - case powerStatusAction: - powerStatus, err := host.SystemPowerStatus(ctx) - if err != nil { - return err - } - - fmt.Fprintf(writer, "Host '%s' has power status: '%s'\n", - host.HostName, powerStatus) - case rebootAction: - if err := host.RebootSystem(ctx); err != nil { - return err - } - - fmt.Fprintf(writer, "Rebooted host '%s'.\n", host.HostName) - } - } - return nil -} - -// GetHostSelections builds a list of selectors that can be passed to a manager -// using the name and label flags passed to airshipctl. -func GetHostSelections(name string, labels string) []remote.HostSelector { - var selectors []remote.HostSelector - if name != "" { - selectors = append(selectors, remote.ByName(name)) - } - - if labels != "" { - selectors = append(selectors, remote.ByLabel(labels)) - } - - if len(selectors) == 0 { - selectors = append(selectors, remote.All()) - } - - return selectors + flags.StringVarP(&options.Labels, flagLabel, flagLabelShort, "", flagLabelDescription) + flags.StringVar(&options.Name, flagName, "", flagNameDescription) + flags.StringVarP(&options.Namespace, flagNamespace, flagNamespaceSort, "", flagNamespaceDescription) + flags.DurationVar(&options.Timeout, flagTimeout, 10*time.Minute, flagTimeoutDescription) } diff --git a/cmd/baremetal/baremetal_test.go b/cmd/baremetal/baremetal_test.go index 19e4835a6..c13f72e6b 100644 --- a/cmd/baremetal/baremetal_test.go +++ b/cmd/baremetal/baremetal_test.go @@ -17,9 +17,8 @@ package baremetal_test import ( "testing" - "github.com/stretchr/testify/assert" - "opendev.org/airship/airshipctl/cmd/baremetal" + "opendev.org/airship/airshipctl/pkg/inventory" "opendev.org/airship/airshipctl/testutil" ) @@ -33,32 +32,32 @@ func TestBaremetal(t *testing.T) { { Name: "baremetal-ejectmedia-with-help", CmdLine: "-h", - Cmd: baremetal.NewEjectMediaCommand(nil, &baremetal.CommonOptions{}), + Cmd: baremetal.NewEjectMediaCommand(nil, &inventory.CommandOptions{}), }, { Name: "baremetal-poweroff-with-help", CmdLine: "-h", - Cmd: baremetal.NewPowerOffCommand(nil, &baremetal.CommonOptions{}), + Cmd: baremetal.NewPowerOffCommand(nil, &inventory.CommandOptions{}), }, { Name: "baremetal-poweron-with-help", CmdLine: "-h", - Cmd: baremetal.NewPowerOnCommand(nil, &baremetal.CommonOptions{}), + Cmd: baremetal.NewPowerOnCommand(nil, &inventory.CommandOptions{}), }, { Name: "baremetal-powerstatus-with-help", CmdLine: "-h", - Cmd: baremetal.NewPowerStatusCommand(nil, &baremetal.CommonOptions{}), + Cmd: baremetal.NewPowerStatusCommand(nil, &inventory.CommandOptions{}), }, { Name: "baremetal-reboot-with-help", CmdLine: "-h", - Cmd: baremetal.NewRebootCommand(nil, &baremetal.CommonOptions{}), + Cmd: baremetal.NewRebootCommand(nil, &inventory.CommandOptions{}), }, { Name: "baremetal-remotedirect-with-help", CmdLine: "-h", - Cmd: baremetal.NewRemoteDirectCommand(nil, &baremetal.CommonOptions{}), + Cmd: baremetal.NewRemoteDirectCommand(nil, &inventory.CommandOptions{}), }, } @@ -66,18 +65,3 @@ func TestBaremetal(t *testing.T) { testutil.RunTest(t, tt) } } - -func TestGetHostSelectionsOneSelector(t *testing.T) { - selectors := baremetal.GetHostSelections("node0", "") - assert.Len(t, selectors, 1) -} - -func TestGetHostSelectionsBothSelectors(t *testing.T) { - selectors := baremetal.GetHostSelections("node0", "airshipit.org/ephemeral-node=true") - assert.Len(t, selectors, 2) -} - -func TestGetHostSelectionsNone(t *testing.T) { - selectors := baremetal.GetHostSelections("", "") - assert.Len(t, selectors, 1) -} diff --git a/cmd/baremetal/ejectmedia.go b/cmd/baremetal/ejectmedia.go index 5bdf6f167..212cf1d62 100644 --- a/cmd/baremetal/ejectmedia.go +++ b/cmd/baremetal/ejectmedia.go @@ -18,16 +18,18 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" + "opendev.org/airship/airshipctl/pkg/inventory" + "opendev.org/airship/airshipctl/pkg/inventory/ifc" ) // NewEjectMediaCommand provides a command to eject media attached to a baremetal host. -func NewEjectMediaCommand(cfgFactory config.Factory, options *CommonOptions) *cobra.Command { +func NewEjectMediaCommand(cfgFactory config.Factory, options *inventory.CommandOptions) *cobra.Command { cmd := &cobra.Command{ Use: "ejectmedia", Short: "Eject media attached to a baremetal host", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return performAction(cfgFactory, options, ejectAction, cmd.OutOrStdout()) + return options.BMHAction(ifc.BaremetalOperationEjectVirtualMedia) }, } diff --git a/cmd/baremetal/poweroff.go b/cmd/baremetal/poweroff.go index a7cd09a18..efee2bbf3 100644 --- a/cmd/baremetal/poweroff.go +++ b/cmd/baremetal/poweroff.go @@ -18,16 +18,18 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" + "opendev.org/airship/airshipctl/pkg/inventory" + "opendev.org/airship/airshipctl/pkg/inventory/ifc" ) // NewPowerOffCommand provides a command to shutdown a remote host. -func NewPowerOffCommand(cfgFactory config.Factory, options *CommonOptions) *cobra.Command { +func NewPowerOffCommand(cfgFactory config.Factory, options *inventory.CommandOptions) *cobra.Command { cmd := &cobra.Command{ Use: "poweroff", Short: "Shutdown a baremetal host", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return performAction(cfgFactory, options, powerOffAction, cmd.OutOrStdout()) + return options.BMHAction(ifc.BaremetalOperationPowerOff) }, } diff --git a/cmd/baremetal/poweron.go b/cmd/baremetal/poweron.go index a46026cda..b014ab79c 100644 --- a/cmd/baremetal/poweron.go +++ b/cmd/baremetal/poweron.go @@ -18,16 +18,18 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" + "opendev.org/airship/airshipctl/pkg/inventory" + "opendev.org/airship/airshipctl/pkg/inventory/ifc" ) // NewPowerOnCommand provides a command with the capability to power on baremetal hosts. -func NewPowerOnCommand(cfgFactory config.Factory, options *CommonOptions) *cobra.Command { +func NewPowerOnCommand(cfgFactory config.Factory, options *inventory.CommandOptions) *cobra.Command { cmd := &cobra.Command{ Use: "poweron", Short: "Power on a host", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return performAction(cfgFactory, options, powerOnAction, cmd.OutOrStdout()) + return options.BMHAction(ifc.BaremetalOperationPowerOn) }, } diff --git a/cmd/baremetal/powerstatus.go b/cmd/baremetal/powerstatus.go index 9cf8e1842..f4edf1f2d 100644 --- a/cmd/baremetal/powerstatus.go +++ b/cmd/baremetal/powerstatus.go @@ -18,16 +18,17 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" + "opendev.org/airship/airshipctl/pkg/inventory" ) // NewPowerStatusCommand provides a command to retrieve the power status of a baremetal host. -func NewPowerStatusCommand(cfgFactory config.Factory, options *CommonOptions) *cobra.Command { +func NewPowerStatusCommand(cfgFactory config.Factory, options *inventory.CommandOptions) *cobra.Command { cmd := &cobra.Command{ Use: "powerstatus", Short: "Retrieve the power status of a baremetal host", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return performAction(cfgFactory, options, powerStatusAction, cmd.OutOrStdout()) + return options.PowerStatus(cmd.OutOrStdout()) }, } diff --git a/cmd/baremetal/reboot.go b/cmd/baremetal/reboot.go index 28fc6498c..036c1b59e 100644 --- a/cmd/baremetal/reboot.go +++ b/cmd/baremetal/reboot.go @@ -18,16 +18,18 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" + "opendev.org/airship/airshipctl/pkg/inventory" + "opendev.org/airship/airshipctl/pkg/inventory/ifc" ) // NewRebootCommand provides a command with the capability to reboot baremetal hosts. -func NewRebootCommand(cfgFactory config.Factory, options *CommonOptions) *cobra.Command { +func NewRebootCommand(cfgFactory config.Factory, options *inventory.CommandOptions) *cobra.Command { cmd := &cobra.Command{ Use: "reboot", Short: "Reboot a host", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return performAction(cfgFactory, options, rebootAction, cmd.OutOrStdout()) + return options.BMHAction(ifc.BaremetalOperationReboot) }, } diff --git a/cmd/baremetal/remotedirect.go b/cmd/baremetal/remotedirect.go index d2fe2a767..ebda41ce7 100644 --- a/cmd/baremetal/remotedirect.go +++ b/cmd/baremetal/remotedirect.go @@ -18,20 +18,21 @@ import ( "github.com/spf13/cobra" "opendev.org/airship/airshipctl/pkg/config" - "opendev.org/airship/airshipctl/pkg/document" + "opendev.org/airship/airshipctl/pkg/inventory" ) // NewRemoteDirectCommand provides a command with the capability to perform remote direct operations. -func NewRemoteDirectCommand(cfgFactory config.Factory, options *CommonOptions) *cobra.Command { +func NewRemoteDirectCommand(cfgFactory config.Factory, options *inventory.CommandOptions) *cobra.Command { cmd := &cobra.Command{ Use: "remotedirect", Short: "Bootstrap the ephemeral host", RunE: func(cmd *cobra.Command, args []string) error { - options.phase = config.BootstrapPhase - options.labels = document.EphemeralHostSelector - return performAction(cfgFactory, options, remoteDirectAction, cmd.OutOrStdout()) + return options.RemoteDirect() }, } + initFlags(options, cmd) + + cmd.Flags().StringVar(&options.IsoURL, "iso-url", "", "specify iso url for host to boot from") return cmd } diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-ejectmedia-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-ejectmedia-with-help.golden index cb1c657a2..db90cf2d8 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-ejectmedia-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-ejectmedia-with-help.golden @@ -4,7 +4,8 @@ Usage: ejectmedia [flags] Flags: - -h, --help help for ejectmedia - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for ejectmedia + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden index 370705f3a..b6c263e72 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweroff-with-help.golden @@ -4,7 +4,8 @@ Usage: poweroff [flags] Flags: - -h, --help help for poweroff - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for poweroff + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweron-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweron-with-help.golden index bee25b489..fca30b5f1 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweron-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-poweron-with-help.golden @@ -4,7 +4,8 @@ Usage: poweron [flags] Flags: - -h, --help help for poweron - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for poweron + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden index 009717273..260b6152b 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-powerstatus-with-help.golden @@ -4,7 +4,8 @@ Usage: powerstatus [flags] Flags: - -h, --help help for powerstatus - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for powerstatus + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden index e3fc5a8da..95cbfc99f 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-reboot-with-help.golden @@ -4,7 +4,8 @@ Usage: reboot [flags] Flags: - -h, --help help for reboot - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for reboot + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-remotedirect-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-remotedirect-with-help.golden index f7a69f351..3152cc0c2 100644 --- a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-remotedirect-with-help.golden +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-remotedirect-with-help.golden @@ -4,4 +4,9 @@ Usage: remotedirect [flags] Flags: - -h, --help help for remotedirect + -h, --help help for remotedirect + --iso-url string specify iso url for host to boot from + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) diff --git a/docs/source/cli/airshipctl_baremetal_ejectmedia.md b/docs/source/cli/airshipctl_baremetal_ejectmedia.md index ddff9e08c..551809d27 100644 --- a/docs/source/cli/airshipctl_baremetal_ejectmedia.md +++ b/docs/source/cli/airshipctl_baremetal_ejectmedia.md @@ -13,10 +13,11 @@ airshipctl baremetal ejectmedia [flags] ### Options ``` - -h, --help help for ejectmedia - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for ejectmedia + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) ``` ### Options inherited from parent commands diff --git a/docs/source/cli/airshipctl_baremetal_poweroff.md b/docs/source/cli/airshipctl_baremetal_poweroff.md index 172a86402..1e9084a31 100644 --- a/docs/source/cli/airshipctl_baremetal_poweroff.md +++ b/docs/source/cli/airshipctl_baremetal_poweroff.md @@ -13,10 +13,11 @@ airshipctl baremetal poweroff [flags] ### Options ``` - -h, --help help for poweroff - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for poweroff + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) ``` ### Options inherited from parent commands diff --git a/docs/source/cli/airshipctl_baremetal_poweron.md b/docs/source/cli/airshipctl_baremetal_poweron.md index 6d7b62163..417d51956 100644 --- a/docs/source/cli/airshipctl_baremetal_poweron.md +++ b/docs/source/cli/airshipctl_baremetal_poweron.md @@ -13,10 +13,11 @@ airshipctl baremetal poweron [flags] ### Options ``` - -h, --help help for poweron - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for poweron + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) ``` ### Options inherited from parent commands diff --git a/docs/source/cli/airshipctl_baremetal_powerstatus.md b/docs/source/cli/airshipctl_baremetal_powerstatus.md index 6ca56283c..b20bd1e12 100644 --- a/docs/source/cli/airshipctl_baremetal_powerstatus.md +++ b/docs/source/cli/airshipctl_baremetal_powerstatus.md @@ -13,10 +13,11 @@ airshipctl baremetal powerstatus [flags] ### Options ``` - -h, --help help for powerstatus - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for powerstatus + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) ``` ### Options inherited from parent commands diff --git a/docs/source/cli/airshipctl_baremetal_reboot.md b/docs/source/cli/airshipctl_baremetal_reboot.md index f8bc55c7c..532f88230 100644 --- a/docs/source/cli/airshipctl_baremetal_reboot.md +++ b/docs/source/cli/airshipctl_baremetal_reboot.md @@ -13,10 +13,11 @@ airshipctl baremetal reboot [flags] ### Options ``` - -h, --help help for reboot - -l, --labels string Label(s) to filter desired baremetal host documents - -n, --name string Name to filter desired baremetal host document - --phase string airshipctl phase that contains the desired baremetal host document(s) (default "bootstrap-iso") + -h, --help help for reboot + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) ``` ### Options inherited from parent commands diff --git a/docs/source/cli/airshipctl_baremetal_remotedirect.md b/docs/source/cli/airshipctl_baremetal_remotedirect.md index 276ed5bbd..b72055eda 100644 --- a/docs/source/cli/airshipctl_baremetal_remotedirect.md +++ b/docs/source/cli/airshipctl_baremetal_remotedirect.md @@ -13,7 +13,12 @@ airshipctl baremetal remotedirect [flags] ### Options ``` - -h, --help help for remotedirect + -h, --help help for remotedirect + --iso-url string specify iso url for host to boot from + -l, --labels string Label(s) to filter desired baremetal host documents + --name string Name to filter desired baremetal host document + -n, --namespace string airshipctl phase that contains the desired baremetal host document(s) + --timeout duration timeout on baremetal action (default 10m0s) ``` ### Options inherited from parent commands diff --git a/docs/source/cli/airshipctl_image_build.md b/docs/source/cli/airshipctl_image_build.md index ae76310c5..a243292a9 100644 --- a/docs/source/cli/airshipctl_image_build.md +++ b/docs/source/cli/airshipctl_image_build.md @@ -13,7 +13,7 @@ airshipctl image build [flags] ### Options ``` - -h, --help help for build + -h, --help help for build ``` ### Options inherited from parent commands diff --git a/manifests/site/test-site/host-inventory/ephemeral-patch.yaml b/manifests/site/test-site/host-inventory/ephemeral-patch.yaml new file mode 100644 index 000000000..7d8282cc8 --- /dev/null +++ b/manifests/site/test-site/host-inventory/ephemeral-patch.yaml @@ -0,0 +1,20 @@ +# This patches the node02 BMH to be suitable for ephemeral purposes +apiVersion: metal3.io/v1alpha1 +kind: BareMetalHost +metadata: + annotations: + labels: + airshipit.org/ephemeral-node: "true" + airshipit.org/deploy-k8s: "false" + name: node02 +spec: + online: true + bmc: + address: redfish+https://localhost:8443/redfish/v1/Systems/air-ephemeral +status: + provisioning: +# we need this status to make sure, that the host is not going to be +# reprovisioned by the ephemeral baremetal operator. +# when we have more flexible labeling system in place, we will not +# deliver this document to ephemeral cluster + state: externally provisioned diff --git a/manifests/site/test-site/host-inventory/hostgenerator/host-generation.yaml b/manifests/site/test-site/host-inventory/hostgenerator/host-generation.yaml new file mode 100644 index 000000000..c2b762af4 --- /dev/null +++ b/manifests/site/test-site/host-inventory/hostgenerator/host-generation.yaml @@ -0,0 +1,14 @@ +# Site-level, phase-specific lists of hosts to generate +# This is used by the hostgenerator-m3 function to narrow down the site-level +# host-catalogue to just the hosts needed for a particular phase. +apiVersion: airshipit.org/v1alpha1 +kind: VariableCatalogue +metadata: + name: host-generation-catalogue +hosts: + m3: + # Note: this list should be kept up to date with + # the full list of hosts in the cluster + - node01 + - node02 + - node03 diff --git a/manifests/site/test-site/host-inventory/hostgenerator/kustomization.yaml b/manifests/site/test-site/host-inventory/hostgenerator/kustomization.yaml new file mode 100644 index 000000000..cef4e0595 --- /dev/null +++ b/manifests/site/test-site/host-inventory/hostgenerator/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../../../function/hostgenerator-m3 + - ../../target/catalogues + - host-generation.yaml + +transformers: + - ../../../../function/hostgenerator-m3/replacements + - patchesstrategicmerge.yaml diff --git a/manifests/site/test-site/host-inventory/hostgenerator/patchesstrategicmerge.yaml b/manifests/site/test-site/host-inventory/hostgenerator/patchesstrategicmerge.yaml new file mode 100644 index 000000000..6c6b85275 --- /dev/null +++ b/manifests/site/test-site/host-inventory/hostgenerator/patchesstrategicmerge.yaml @@ -0,0 +1,41 @@ +apiVersion: builtin +kind: PatchStrategicMergeTransformer +metadata: + name: smp +patches: |- + --- + apiVersion: airshipit.org/v1alpha1 + kind: VariableCatalogue + metadata: + name: host-catalogue + $patch: delete + --- + apiVersion: airshipit.org/v1alpha1 + kind: VariableCatalogue + metadata: + name: host-generation-catalogue + $patch: delete + --- + apiVersion: airshipit.org/v1alpha1 + kind: VariableCatalogue + metadata: + name: networking + $patch: delete + --- + apiVersion: airshipit.org/v1alpha1 + kind: VariableCatalogue + metadata: + name: env-vars-catalogue + $patch: delete + --- + apiVersion: airshipit.org/v1alpha1 + kind: VariableCatalogue + metadata: + name: versions-airshipctl + $patch: delete + --- + apiVersion: airshipit.org/v1alpha1 + kind: VariableCatalogue + metadata: + name: password-secret + $patch: delete diff --git a/manifests/site/test-site/host-inventory/kustomization.yaml b/manifests/site/test-site/host-inventory/kustomization.yaml new file mode 100644 index 000000000..848ce20c7 --- /dev/null +++ b/manifests/site/test-site/host-inventory/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +generators: + - hostgenerator + +patchesStrategicMerge: + - ephemeral-patch.yaml \ No newline at end of file diff --git a/manifests/site/test-site/metadata.yaml b/manifests/site/test-site/metadata.yaml index 5d03d5c8f..c0f84dc28 100644 --- a/manifests/site/test-site/metadata.yaml +++ b/manifests/site/test-site/metadata.yaml @@ -1,3 +1,5 @@ phase: path: manifests/site/test-site/phases docEntryPointPrefix: manifests/site/test-site +inventory: + path: manifests/site/test-site/host-inventory \ No newline at end of file diff --git a/manifests/site/test-site/target/catalogues/hosts.yaml b/manifests/site/test-site/target/catalogues/hosts.yaml index abbf90e45..b8f0df647 100644 --- a/manifests/site/test-site/target/catalogues/hosts.yaml +++ b/manifests/site/test-site/target/catalogues/hosts.yaml @@ -25,7 +25,7 @@ hosts: node02: bootMode: UEFI macAddress: 52:54:00:b6:ed:02 - bmcAddress: redfish+http://10.23.25.2:8000/redfish/v1/Systems/air-target-2 + bmcAddress: redfish+https://localhost:8443/redfish/v1/Systems/air-ephemeral bmcUsername: username bmcPassword: password ipAddresses: @@ -48,3 +48,16 @@ hosts: oam: 52:54:00:9b:27:07 pxe: 52:54:00:b6:ed:23 hardwareProfile: default # defined in the hardwareprofile-example function + node04: + bootMode: UEFI + macAddress: 52:54:00:36:5e:e3 + bmcAddress: redfish+http://10.23.25.2:8000/redfish/v1/Systems/air-target-2 + bmcUsername: username + bmcPassword: password + ipAddresses: + oam-ipv4: 10.23.25.104 + pxe-ipv4: 10.23.24.104 + macAddresses: + oam: 52:54:00:dc:ab:04 + pxe: 52:54:00:51:0b:e4 + hardwareProfile: default # defined in the hardwareprofile-example function diff --git a/tools/deployment/25_deploy_ephemeral_node.sh b/tools/deployment/25_deploy_ephemeral_node.sh index 50897a5b3..57800c046 100755 --- a/tools/deployment/25_deploy_ephemeral_node.sh +++ b/tools/deployment/25_deploy_ephemeral_node.sh @@ -20,7 +20,10 @@ export KUBECONFIG=${KUBECONFIG:-"$HOME/.airship/kubeconfig"} export KUBECONFIG_EPHEMERAL_CONTEXT=${KUBECONFIG_EPHEMERAL_CONTEXT:-"ephemeral-cluster"} echo "Deploy ephemeral node using redfish with iso" -airshipctl baremetal remotedirect --debug +airshipctl baremetal remotedirect \ + --iso-url http://localhost:8099/ephemeral.iso \ + --name "node02" \ + --debug echo "Wait for apiserver to become available" N=0 diff --git a/tools/deployment/31_deploy_initinfra_target_node.sh b/tools/deployment/31_deploy_initinfra_target_node.sh index fe8786a73..8acb0b7fa 100755 --- a/tools/deployment/31_deploy_initinfra_target_node.sh +++ b/tools/deployment/31_deploy_initinfra_target_node.sh @@ -15,7 +15,6 @@ set -xe export KUBECONFIG=${KUBECONFIG:-"$HOME/.airship/kubeconfig"} -NODENAME="node01" export KUBECONFIG_TARGET_CONTEXT=${KUBECONFIG_TARGET_CONTEXT:-"target-cluster"} echo "Deploy calico using tigera operator"