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

Unify create-create overrides and set-cluster fields #5123

Merged
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
26 changes: 2 additions & 24 deletions cmd/kops/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/kops/pkg/apis/kops/registry"
"k8s.io/kops/pkg/apis/kops/validation"
"k8s.io/kops/pkg/assets"
"k8s.io/kops/pkg/commands"
"k8s.io/kops/pkg/dns"
"k8s.io/kops/pkg/featureflag"
"k8s.io/kops/upup/pkg/fi"
Expand Down Expand Up @@ -1041,7 +1042,7 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
cluster.Spec.SSHAccess = c.SSHAccess
}

if err := setOverrides(c.Overrides, cluster, instanceGroups); err != nil {
if err := commands.SetClusterFields(c.Overrides, cluster, instanceGroups); err != nil {
return err
}

Expand Down Expand Up @@ -1246,29 +1247,6 @@ func parseCloudLabels(s string) (map[string]string, error) {
return m, nil
}

// setOverrides sets override values in the spec
func setOverrides(overrides []string, cluster *api.Cluster, instanceGroups []*api.InstanceGroup) error {
for _, override := range overrides {
kv := strings.SplitN(override, "=", 2)
if len(kv) != 2 {
return fmt.Errorf("unhandled override: %q", override)
}

// For now we have hard-code the values we want to support; we'll get test coverage and then do this properly...
switch kv[0] {
case "cluster.spec.nodePortAccess":
cluster.Spec.NodePortAccess = append(cluster.Spec.NodePortAccess, kv[1])
case "cluster.spec.etcdClusters[*].version":
for _, etcd := range cluster.Spec.EtcdClusters {
etcd.Version = kv[1]
}
default:
return fmt.Errorf("unhandled override: %q", override)
}
}
return nil
}

func getZoneToSubnetProviderID(VPCID string, region string, subnetIDs []string) (map[string]string, error) {
res := make(map[string]string)
cloudTags := map[string]string{}
Expand Down
12 changes: 9 additions & 3 deletions pkg/commands/set_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func RunSetCluster(f *util.Factory, cmd *cobra.Command, out io.Writer, options *
return err
}

if err := setClusterFields(options.Fields, cluster); err != nil {
if err := SetClusterFields(options.Fields, cluster, instanceGroups); err != nil {
return err
}

Expand All @@ -70,8 +70,8 @@ func RunSetCluster(f *util.Factory, cmd *cobra.Command, out io.Writer, options *
return nil
}

// setClusterFields sets field values in the cluster
func setClusterFields(fields []string, cluster *api.Cluster) error {
// SetClusterFields sets field values in the cluster
func SetClusterFields(fields []string, cluster *api.Cluster, instanceGroups []*api.InstanceGroup) error {
for _, field := range fields {
kv := strings.SplitN(field, "=", 2)
if len(kv) != 2 {
Expand All @@ -80,8 +80,14 @@ func setClusterFields(fields []string, cluster *api.Cluster) error {

// For now we have hard-code the values we want to support; we'll get test coverage and then do this properly...
switch kv[0] {
case "cluster.spec.nodePortAccess":
cluster.Spec.NodePortAccess = append(cluster.Spec.NodePortAccess, kv[1])
case "spec.kubernetesVersion":
cluster.Spec.KubernetesVersion = kv[1]
case "cluster.spec.etcdClusters[*].version":
for _, c := range cluster.Spec.EtcdClusters {
c.Version = kv[1]
}
default:
return fmt.Errorf("unhandled field: %q", field)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/commands/set_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func TestSetClusterFields(t *testing.T) {
}

for _, g := range grid {
var igs []*kops.InstanceGroup
c := g.Input
err := setClusterFields(g.Fields, &c)

err := SetClusterFields(g.Fields, &c, igs)
if err != nil {
t.Errorf("unexpected error from setClusterFields %v: %v", g.Fields, err)
continue
Expand Down