airshipctl/cmd/phase/apply.go
Kostiantyn Kalynovskyi e4adce2bcf Integrate cli-utils applier with phases.
This will also enable us to wait for kubernetes resources to reach
required state

Relates-To: #238

Change-Id: Ia2c9cebd94ca2ef5bfd9ed5830ae469e6aa6b167
2020-07-15 11:10:37 -05:00

80 lines
2.0 KiB
Go

/*
Copyright 2014 The Kubernetes Authors.
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
http://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 (
"time"
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/phase/apply"
)
const (
applyLong = `
Apply specific phase to kubernetes cluster such as control-plane, workloads, initinfra
`
applyExample = `
# Apply initinfra phase to a cluster
airshipctl phase apply initinfra
`
)
// NewApplyCommand creates a command to apply phase to k8s cluster.
func NewApplyCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
i := &apply.Options{
RootSettings: rootSettings,
}
applyCmd := &cobra.Command{
Use: "apply PHASE_NAME",
Short: "Apply phase to a cluster",
Long: applyLong[1:],
Args: cobra.ExactArgs(1),
Example: applyExample,
RunE: func(cmd *cobra.Command, args []string) error {
i.PhaseName = args[0]
i.Initialize()
return i.Run()
},
}
addApplyFlags(i, applyCmd)
return applyCmd
}
func addApplyFlags(i *apply.Options, cmd *cobra.Command) {
flags := cmd.Flags()
flags.BoolVar(
&i.DryRun,
"dry-run",
false,
"don't deliver documents to the cluster, simulate the changes instead")
flags.BoolVar(
&i.Prune,
"prune",
false,
`if set to true, command will delete all kubernetes resources that are not`+
` defined in airship documents and have airshipit.org/deployed=apply label`)
flags.DurationVar(
&i.WaitTimeout,
"wait-timeout",
time.Second*120,
`number of seconds to wait for resources to become ready, if set to 0 will not wait`)
}