Skip to content
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

Merged
merged 6 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions cmd/kops/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
Copy link
Contributor Author

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?

Copy link
Contributor Author

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?


return cmd
}

Expand Down Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The 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{})
Expand All @@ -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 {
Expand Down Expand Up @@ -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(), ","))
Copy link
Member

Choose a reason for hiding this comment

The 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 {
Expand Down
15 changes: 8 additions & 7 deletions docs/cli/kops_update_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ kops update cluster
### Options

```
--create-kube-config Will control automatically creating the kube config file on your local filesystem (default true)
--model string Models to apply (separate multiple models with commas) (default "config,proto,cloudup")
--out string Path to write any local output
--phase string Subset of tasks to run: assets, cluster, network, security
--ssh-public-key string SSH public key to use (deprecated: use kops create secret instead)
--target string Target - direct, terraform, cloudformation (default "direct")
-y, --yes Create cloud resources, without --yes update is in dry run mode
--create-kube-config Will control automatically creating the kube config file on your local filesystem (default true)
--lifecycle-overrides stringSlice comma separated list of phase overrides, example: SecurityGroups=Ignore,InternetGateway=ExistsAndWarnIfChanges
--model string Models to apply (separate multiple models with commas) (default "config,proto,cloudup")
--out string Path to write any local output
--phase string Subset of tasks to run: assets, cluster, network, security
--ssh-public-key string SSH public key to use (deprecated: use kops create secret instead)
--target string Target - direct, terraform, cloudformation (default "direct")
-y, --yes Create cloud resources, without --yes update is in dry run mode
```

### Options inherited from parent commands
Expand Down
7 changes: 6 additions & 1 deletion upup/pkg/fi/assettasks/copydockerimage_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/assettasks/copyfile_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ type ApplyClusterCmd struct {

// Phase can be set to a Phase to run the specific subset of tasks, if we don't want to run everything
Phase Phase

// LifecycleOverrides is passed in to override the lifecycle for one of more tasks.
// The key value is the task name such as InternetGateway and the value is the fi.Lifecycle
// that is re-mapped.
LifecycleOverrides map[string]fi.Lifecycle
}

func (c *ApplyClusterCmd) Run() error {
Expand Down Expand Up @@ -628,7 +633,7 @@ func (c *ApplyClusterCmd) Run() error {

tf.AddTo(l.TemplateFunctions)

taskMap, err := l.BuildTasks(modelStore, fileModels, assetBuilder, &stageAssetsLifecycle)
taskMap, err := l.BuildTasks(modelStore, fileModels, assetBuilder, &stageAssetsLifecycle, c.LifecycleOverrides)
if err != nil {
return fmt.Errorf("error building tasks: %v", err)
}
Expand Down
7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/autoscalinggroup_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/dhcpoptions_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/dnsname_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/dnszone_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/ebsvolume_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/elasticip_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/iaminstanceprofile_fitask.go

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.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/iamrole_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/iamrolepolicy_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/internetgateway_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion upup/pkg/fi/cloudup/awstasks/launchconfiguration_fitask.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading