Skip to content

Commit a4a5096

Browse files
fix case where cli option is prefixed with a short alias (#140)
* fix case where cli option is prefixed with a short alias * remove node head (previously ignored due to short alias) * set gpu flag in cluster config
1 parent b939b48 commit a4a5096

File tree

4 files changed

+72
-25
lines changed

4 files changed

+72
-25
lines changed

minikube/generator/schema_builder.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log"
1010
"os"
1111
"os/exec"
12+
"regexp"
1213
"strconv"
1314
"strings"
1415
"time"
@@ -159,14 +160,21 @@ func (s *SchemaBuilder) Build() (string, error) {
159160

160161
currentEntry := SchemaEntry{}
161162

163+
pattern := "^-[a-zA-Z], "
164+
165+
srg := regexp.MustCompile(pattern)
166+
162167
for scanner.Scan() {
163168
line := scanner.Text()
164169
line = strings.TrimSpace(line)
165170

171+
// trim the short parameter e.g. -g
172+
line = srg.ReplaceAllString(line, "")
173+
166174
if strings.HasPrefix(line, "--") {
167175
currentEntry = loadParameter(line)
168176
} else if line != "" {
169-
if currentEntry.Description != "" { // Let's readd a space between line blocks
177+
if currentEntry.Description != "" { // Let's read a space between line blocks
170178
currentEntry.Description += " "
171179
}
172180
currentEntry.Description += line
@@ -306,14 +314,6 @@ var (
306314
Default: "terraform-provider-minikube",
307315
},
308316
309-
"nodes": {
310-
Type: schema.TypeInt,
311-
Optional: true,
312-
ForceNew: true,
313-
Description: "Amount of nodes in the cluster",
314-
Default: 1,
315-
},
316-
317317
"client_key": {
318318
Type: schema.TypeString,
319319
Computed: true,

minikube/generator/schema_builder_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ var (
3131
Default: "terraform-provider-minikube",
3232
},
3333
34-
"nodes": {
35-
Type: schema.TypeInt,
36-
Optional: true,
37-
ForceNew: true,
38-
Description: "Amount of nodes in the cluster",
39-
Default: 1,
40-
},
41-
4234
"client_key": {
4335
Type: schema.TypeString,
4436
Computed: true,
@@ -111,6 +103,38 @@ func GetClusterSchema() map[string]*schema.Schema {
111103
`, schema)
112104
}
113105

106+
func TestAliasProperty(t *testing.T) {
107+
ctrl := gomock.NewController(t)
108+
mockMinikube := NewMockMinikubeBinary(ctrl)
109+
mockMinikube.EXPECT().GetVersion(gomock.Any()).Return("Version 999", nil)
110+
mockMinikube.EXPECT().GetStartHelpText(gomock.Any()).Return(`
111+
-t, --test='test-value':
112+
I am a great test description
113+
114+
`, nil)
115+
builder := NewSchemaBuilder("fake.go", mockMinikube)
116+
schema, err := builder.Build()
117+
assert.NoError(t, err)
118+
assert.Equal(t, header+`
119+
"test": {
120+
Type: schema.TypeString,
121+
Description: "I am a great test description",
122+
123+
Optional: true,
124+
ForceNew: true,
125+
126+
Default: "test-value",
127+
},
128+
129+
}
130+
)
131+
132+
func GetClusterSchema() map[string]*schema.Schema {
133+
return clusterSchema
134+
}
135+
`, schema)
136+
}
137+
114138
func TestMultilineDescription(t *testing.T) {
115139
ctrl := gomock.NewController(t)
116140
mockMinikube := NewMockMinikubeBinary(ctrl)

minikube/resource_cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ func initialiseMinikubeClient(d *schema.ResourceData, m interface{}) (lib.Cluste
407407
KubernetesConfig: kubernetesConfig,
408408
MultiNodeRequested: multiNode,
409409
StaticIP: d.Get("static_ip").(string),
410+
GPUs: d.Get("gpus").(string),
410411
}
411412

412413
clusterClient.SetConfig(lib.MinikubeClientConfig{

minikube/schema_cluster.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ var (
2121
Default: "terraform-provider-minikube",
2222
},
2323

24-
"nodes": {
25-
Type: schema.TypeInt,
26-
Optional: true,
27-
ForceNew: true,
28-
Description: "Amount of nodes in the cluster",
29-
Default: 1,
30-
},
31-
3224
"client_key": {
3325
Type: schema.TypeString,
3426
Computed: true,
@@ -417,6 +409,16 @@ var (
417409
Default: false,
418410
},
419411

412+
"gpus": {
413+
Type: schema.TypeString,
414+
Description: "Allow pods to use your NVIDIA GPUs. Options include: [all,nvidia] (Docker driver with Docker container-runtime only)",
415+
416+
Optional: true,
417+
ForceNew: true,
418+
419+
Default: "",
420+
},
421+
420422
"host_dns_resolver": {
421423
Type: schema.TypeBool,
422424
Description: "Enable host resolver for NAT DNS requests (virtualbox driver only)",
@@ -873,6 +875,26 @@ var (
873875
Default: false,
874876
},
875877

878+
"nodes": {
879+
Type: schema.TypeInt,
880+
Description: "The number of nodes to spin up. Defaults to 1.",
881+
882+
Optional: true,
883+
ForceNew: true,
884+
885+
Default: 1,
886+
},
887+
888+
"output": {
889+
Type: schema.TypeString,
890+
Description: "Format to print stdout in. Options include: [text,json]",
891+
892+
Optional: true,
893+
ForceNew: true,
894+
895+
Default: "text",
896+
},
897+
876898
"ports": {
877899
Type: schema.TypeSet,
878900
Description: "List of ports that should be exposed (docker and podman driver only)",

0 commit comments

Comments
 (0)