Add airshipctl phase run

Commands execution logic will be added when executors are implemented

Change-Id: I78ef95a858117d0c6d407289955228b6ba1a3d5e
This commit is contained in:
Kostiantyn Kalynovskyi 2020-07-31 14:59:43 -05:00
parent 696b287552
commit 5ff6d38e03
7 changed files with 155 additions and 0 deletions

View File

@ -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
}

63
cmd/phase/run.go Normal file
View File

@ -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
}

35
cmd/phase/run_test.go Normal file
View File

@ -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)
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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