Skip to content

Commit a87c076

Browse files
authored
Add "--enable" flag and wire kubernetes version selection. (#1713)
1 parent cb94b93 commit a87c076

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

internal/cli/cmd/cluster/create.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func NewCreateCmd() *cobra.Command {
5555

5656
duration := fncobra.Duration(cmd.Flags(), "duration", 0, "For how long to run the ephemeral environment.")
5757

58+
enable := cmd.Flags().StringSlice("enable", nil, "Enable a feature, e.g. --enable=kubernetes:1.33")
5859
waitKubeSystem := cmd.Flags().Bool("wait_kube_system", false, "If true, wait until kube-system resources (e.g. coredns and local-path-provisioner) are ready.")
5960
waitTimeout := fncobra.Duration(cmd.Flags(), "wait_timeout", time.Minute, "For how long to wait until the instance becomes ready.")
6061

@@ -76,14 +77,15 @@ func NewCreateCmd() *cobra.Command {
7677
}
7778

7879
opts := api.CreateClusterOpts{
79-
MachineType: *machineType,
80-
KeepAtExit: true,
81-
Purpose: *purpose,
82-
Features: *features,
83-
Labels: *labels,
84-
UniqueTag: *tag,
85-
SecretIDs: *availableSecrets,
86-
Duration: *duration,
80+
MachineType: *machineType,
81+
KeepAtExit: true,
82+
Purpose: *purpose,
83+
Features: *features,
84+
Labels: *labels,
85+
UniqueTag: *tag,
86+
SecretIDs: *availableSecrets,
87+
Duration: *duration,
88+
Experimental: map[string]any{},
8789
}
8890

8991
if len(opts.Labels) == 0 {
@@ -115,10 +117,6 @@ func NewCreateCmd() *cobra.Command {
115117
}
116118

117119
if *internalExtra != "" {
118-
if opts.Experimental == nil {
119-
opts.Experimental = map[string]any{}
120-
}
121-
122120
opts.Experimental["internal_extra"] = *internalExtra
123121
}
124122

@@ -133,9 +131,6 @@ func NewCreateCmd() *cobra.Command {
133131
}
134132

135133
if *selectors != nil {
136-
if opts.Experimental == nil {
137-
opts.Experimental = map[string]any{}
138-
}
139134
sels := []*api.LabelEntry{}
140135
for k, v := range *selectors {
141136
sels = append(sels, &api.LabelEntry{Name: k, Value: v})
@@ -157,16 +152,33 @@ func NewCreateCmd() *cobra.Command {
157152
}
158153

159154
if !*bare && !strings.HasPrefix(*machineType, "mac") && !strings.HasPrefix(*machineType, "windows") {
160-
if opts.Experimental == nil {
161-
opts.Experimental = map[string]any{}
162-
}
163-
164155
// XXX for backwards compatibility, add k3s on Linux by default.
165156
if _, ok := opts.Experimental["k3s"]; !ok {
166157
opts.Experimental["k3s"] = private.K3sCfg
167158
}
168159
}
169160

161+
for _, feat := range *enable {
162+
parts := strings.SplitN(feat, ":", 2)
163+
switch parts[0] {
164+
case "kubernetes":
165+
if len(parts) != 2 {
166+
return fnerrors.Newf("expected Kubernetes version spec %q", feat)
167+
}
168+
169+
if _, ok := opts.Experimental["k3s"]; !ok {
170+
// Fill default
171+
opts.Experimental["k3s"] = private.K3sCfg
172+
}
173+
174+
cfg := opts.Experimental["k3s"].(map[string]any)
175+
cfg["kubernetes_version"] = parts[1]
176+
177+
default:
178+
return fnerrors.Newf("unknown feature option %q", parts[0])
179+
}
180+
}
181+
170182
switch *ingress {
171183
case "":
172184
// nothing to do

0 commit comments

Comments
 (0)