-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lifecycle overrides #4445
Lifecycle overrides #4445
Changes from all commits
a68cf85
e6b9a15
31bb485
e14b4ed
13ff087
64439b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,10 @@ type UpdateClusterOptions struct { | |
CreateKubecfg bool | ||
|
||
Phase string | ||
|
||
// LifecycleOverrides is a slice of taskName=lifecycle name values. This slice is used | ||
// to populate the LifecycleOverrides struct member in ApplyClusterCmd struct. | ||
LifecycleOverrides []string | ||
} | ||
|
||
func (o *UpdateClusterOptions) InitDefaults() { | ||
|
@@ -109,6 +113,8 @@ func NewCmdUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command { | |
cmd.Flags().StringVar(&options.OutDir, "out", options.OutDir, "Path to write any local output") | ||
cmd.Flags().BoolVar(&options.CreateKubecfg, "create-kube-config", options.CreateKubecfg, "Will control automatically creating the kube config file on your local filesystem") | ||
cmd.Flags().StringVar(&options.Phase, "phase", options.Phase, "Subset of tasks to run: "+strings.Join(cloudup.Phases.List(), ", ")) | ||
cmd.Flags().StringSliceVar(&options.LifecycleOverrides, "lifecycle-overrides", options.LifecycleOverrides, "comma separated list of phase overrides, example: SecurityGroups=Ignore,InternetGateway=ExistsAndWarnIfChanges") | ||
|
||
return cmd | ||
} | ||
|
||
|
@@ -195,6 +201,25 @@ func RunUpdateCluster(f *util.Factory, clusterName string, out io.Writer, c *Upd | |
} | ||
} | ||
|
||
lifecycleOverrideMap := make(map[string]fi.Lifecycle) | ||
|
||
for _, override := range c.LifecycleOverrides { | ||
values := strings.Split(override, "=") | ||
if len(values) != 2 { | ||
return fmt.Errorf("Incorrect syntax for lifecyle-overrides, correct syntax is TaskName=lifecycleName, override provided: %q", override) | ||
} | ||
|
||
taskName := values[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be case-sensitive (and fail silently on case mismatch) |
||
lifecycleName := values[1] | ||
|
||
lifecycleOverride, err := parseLifecycle(lifecycleName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
lifecycleOverrideMap[taskName] = lifecycleOverride | ||
} | ||
|
||
var instanceGroups []*kops.InstanceGroup | ||
{ | ||
list, err := clientset.InstanceGroupsFor(cluster).List(metav1.ListOptions{}) | ||
|
@@ -207,15 +232,16 @@ func RunUpdateCluster(f *util.Factory, clusterName string, out io.Writer, c *Upd | |
} | ||
|
||
applyCmd := &cloudup.ApplyClusterCmd{ | ||
Clientset: clientset, | ||
Cluster: cluster, | ||
DryRun: isDryrun, | ||
InstanceGroups: instanceGroups, | ||
MaxTaskDuration: c.MaxTaskDuration, | ||
Models: strings.Split(c.Models, ","), | ||
OutDir: c.OutDir, | ||
Phase: phase, | ||
TargetName: targetName, | ||
Clientset: clientset, | ||
Cluster: cluster, | ||
DryRun: isDryrun, | ||
InstanceGroups: instanceGroups, | ||
MaxTaskDuration: c.MaxTaskDuration, | ||
Models: strings.Split(c.Models, ","), | ||
OutDir: c.OutDir, | ||
Phase: phase, | ||
TargetName: targetName, | ||
LifecycleOverrides: lifecycleOverrideMap, | ||
} | ||
|
||
if err := applyCmd.Run(); err != nil { | ||
|
@@ -335,6 +361,13 @@ func RunUpdateCluster(f *util.Factory, clusterName string, out io.Writer, c *Upd | |
return nil | ||
} | ||
|
||
func parseLifecycle(lifecycle string) (fi.Lifecycle, error) { | ||
if v, ok := fi.LifecycleNameMap[lifecycle]; ok { | ||
return v, nil | ||
} | ||
return "", fmt.Errorf("unknown lifecycle %q, available lifecycle: %s", lifecycle, strings.Join(fi.Lifecycles.List(), ",")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This one is fine, because we fail-fast and give a helpful message) |
||
} | ||
|
||
func usesBastion(instanceGroups []*kops.InstanceGroup) bool { | ||
for _, ig := range instanceGroups { | ||
if ig.Spec.Role == kops.InstanceGroupRoleBastion { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I separated this out so that a phase does not have to be set. If we include this with the
--phase
flag a user would not be able to run all of the phases. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open to other ideas, but I do not want to force a user to define a phase in order to use overrides. Users will want to use overrides but not specify a phase. We can do phase="", but that is ugly and a change to syntax. Phases are a group of tasks and lifecycles, while lifecycle overrides are just setting the lifecycle on a single task. Kinda stumped how to do this well.
@rdrgmnzs I know you are going to use this functionality, any opinion?