From 5ff6d38e03458ba8f073426fece481bf006d1d87 Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Fri, 31 Jul 2020 14:59:43 -0500 Subject: [PATCH] Add airshipctl phase run Commands execution logic will be added when executors are implemented Change-Id: I78ef95a858117d0c6d407289955228b6ba1a3d5e --- cmd/phase/phase.go | 1 + cmd/phase/run.go | 63 +++++++++++++++++++ cmd/phase/run_test.go | 35 +++++++++++ .../phase-cmd-with-help.golden | 1 + .../TestRunGoldenOutput/run-with-help.golden | 14 +++++ docs/source/cli/airshipctl_phase.md | 1 + docs/source/cli/airshipctl_phase_run.md | 40 ++++++++++++ 7 files changed, 155 insertions(+) create mode 100644 cmd/phase/run.go create mode 100644 cmd/phase/run_test.go create mode 100644 cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden create mode 100644 docs/source/cli/airshipctl_phase_run.md diff --git a/cmd/phase/phase.go b/cmd/phase/phase.go index 18181668e..4e47410cd 100644 --- a/cmd/phase/phase.go +++ b/cmd/phase/phase.go @@ -44,6 +44,7 @@ func NewPhaseCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comman phaseRootCmd.AddCommand(NewApplyCommand(rootSettings)) phaseRootCmd.AddCommand(NewRenderCommand(rootSettings)) phaseRootCmd.AddCommand(NewPlanCommand(rootSettings)) + phaseRootCmd.AddCommand(NewRunCommand(rootSettings)) return phaseRootCmd } diff --git a/cmd/phase/run.go b/cmd/phase/run.go new file mode 100644 index 000000000..bac2b5f5d --- /dev/null +++ b/cmd/phase/run.go @@ -0,0 +1,63 @@ +/* + 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 phase + +import ( + "github.com/spf13/cobra" + + "opendev.org/airship/airshipctl/pkg/environment" + "opendev.org/airship/airshipctl/pkg/events" + "opendev.org/airship/airshipctl/pkg/k8s/utils" + "opendev.org/airship/airshipctl/pkg/phase" +) + +const ( + // TODO (kkalynovskyi) when different phase executors will be implmeneted, and their description is more clear, + // add documentation here. also consider adding dynamic phase descriptions based on executors. + // TODO (kkalynovskyi) when this command is fully functional and phase executors are developed + // remove phase apply command + runLong = `Run specific life-cycle phase such as ephemeral-control-plane, target-initinfra etc...` + runExample = ` +# Run initinfra phase +airshipctl phase run ephemeral-control-plane +` +) + +// NewRunCommand creates a command to run specific phase +func NewRunCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { + p := &phase.Cmd{ + AirshipCTLSettings: rootSettings, + Processor: events.NewDefaultProcessor(utils.Streams()), + } + + runCmd := &cobra.Command{ + Use: "run PHASE_NAME", + Short: "Run phase", + Long: runLong, + Args: cobra.ExactArgs(1), + Example: runExample, + RunE: func(cmd *cobra.Command, args []string) error { + return p.Exec(args[0]) + }, + } + flags := runCmd.Flags() + flags.BoolVar( + &p.DryRun, + "dry-run", + false, + "simulate phase execution") + // TODO add kubeconfig flags when https://review.opendev.org/#/c/744382 is merged + return runCmd +} diff --git a/cmd/phase/run_test.go b/cmd/phase/run_test.go new file mode 100644 index 000000000..549e66ca6 --- /dev/null +++ b/cmd/phase/run_test.go @@ -0,0 +1,35 @@ +/* + 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 phase_test + +import ( + "testing" + + "opendev.org/airship/airshipctl/cmd/phase" + "opendev.org/airship/airshipctl/testutil" +) + +func TestRun(t *testing.T) { + tests := []*testutil.CmdTest{ + { + Name: "run-with-help", + CmdLine: "-h", + Cmd: phase.NewRunCommand(nil), + }, + } + for _, tt := range tests { + testutil.RunTest(t, tt) + } +} diff --git a/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden b/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden index 48c9523b5..5c624e522 100644 --- a/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden +++ b/cmd/phase/testdata/TestNewPhaseCommandGoldenOutput/phase-cmd-with-help.golden @@ -9,6 +9,7 @@ Available Commands: help Help about any command plan List phases render Render phase documents from model + run Run phase Flags: -h, --help help for phase diff --git a/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden b/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden new file mode 100644 index 000000000..f55613edc --- /dev/null +++ b/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden @@ -0,0 +1,14 @@ +Run specific life-cycle phase such as ephemeral-control-plane, target-initinfra etc... + +Usage: + run PHASE_NAME [flags] + +Examples: + +# Run initinfra phase +airshipctl phase run ephemeral-control-plane + + +Flags: + --dry-run simulate phase execution + -h, --help help for run diff --git a/docs/source/cli/airshipctl_phase.md b/docs/source/cli/airshipctl_phase.md index 02a81c087..db50d6c43 100644 --- a/docs/source/cli/airshipctl_phase.md +++ b/docs/source/cli/airshipctl_phase.md @@ -28,4 +28,5 @@ such as getting list and applying specific one. * [airshipctl phase apply](airshipctl_phase_apply.md) - Apply phase to a cluster * [airshipctl phase plan](airshipctl_phase_plan.md) - List phases * [airshipctl phase render](airshipctl_phase_render.md) - Render phase documents from model +* [airshipctl phase run](airshipctl_phase_run.md) - Run phase diff --git a/docs/source/cli/airshipctl_phase_run.md b/docs/source/cli/airshipctl_phase_run.md new file mode 100644 index 000000000..247343b49 --- /dev/null +++ b/docs/source/cli/airshipctl_phase_run.md @@ -0,0 +1,40 @@ +## airshipctl phase run + +Run phase + +### Synopsis + +Run specific life-cycle phase such as ephemeral-control-plane, target-initinfra etc... + +``` +airshipctl phase run PHASE_NAME [flags] +``` + +### Examples + +``` + +# Run initinfra phase +airshipctl phase run ephemeral-control-plane + +``` + +### Options + +``` + --dry-run simulate phase execution + -h, --help help for run +``` + +### Options inherited from parent commands + +``` + --airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config") + --debug enable verbose output + --kubeconfig string Path to kubeconfig associated with airshipctl configuration. (default "$HOME/.airship/kubeconfig") +``` + +### SEE ALSO + +* [airshipctl phase](airshipctl_phase.md) - Manage phases +