Skip to content

Commit 33807f5

Browse files
fixed driver / mountstring os differences
1 parent 41de52f commit 33807f5

File tree

5 files changed

+82
-9
lines changed

5 files changed

+82
-9
lines changed

docs/resources/cluster.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ resource "kubernetes_deployment" "deployment" {
120120
- `docker_env` (List of String) Environment variables to pass to the Docker daemon. (format: key=value)
121121
- `docker_opt` (List of String) Specify arbitrary flags to pass to the Docker daemon. (format: key=value)
122122
- `download_only` (Boolean) If true, only download and cache files for later use - don't install or start anything.
123-
- `driver` (String) Driver is one of: virtualbox, parallels, vmwarefusion, hyperkit, vmware, qemu2 (experimental), docker, podman (experimental), ssh (defaults to auto-detect)
123+
- `driver` (String) Driver is one of the following - Windows: (hyperv, docker, virtualbox, vmware, qemu2, ssh) - OSX: (virtualbox, parallels, vmwarefusion, hyperkit, vmware, qemu2, docker, podman, ssh) - Linux: (docker, kvm2, virtualbox, qemu2, none, podman, ssh)
124124
- `dry_run` (Boolean) dry-run mode. Validates configuration, but does not mutate system state
125125
- `embed_certs` (Boolean) if true, will embed the certs in kubeconfig.
126126
- `enable_default_cni` (Boolean) DEPRECATED: Replaced by --cni=bridge
@@ -141,7 +141,7 @@ resource "kubernetes_deployment" "deployment" {
141141
- `install_addons` (Boolean) If set, install addons. Defaults to true.
142142
- `interactive` (Boolean) Allow user prompts for more information
143143
- `keep_context` (Boolean) This will keep the existing kubectl context and will create a minikube context.
144-
- `kubernetes_version` (String) The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for v1.25.2, 'latest' for v1.25.2). Defaults to 'stable'.
144+
- `kubernetes_version` (String) The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for v1.25.3, 'latest' for v1.25.3). Defaults to 'stable'.
145145
- `kvm_gpu` (Boolean) Enable experimental NVIDIA GPU support in minikube
146146
- `kvm_hidden` (Boolean) Hide the hypervisor signature from the guest in minikube (kvm2 driver only)
147147
- `kvm_network` (String) The KVM default network name. (kvm2 driver only)

minikube/generator/schema_builder.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type SchemaOverride struct {
5050
Description string
5151
Default string
5252
Type SchemaType
53+
DefaultFunc string
5354
}
5455

5556
var schemaOverrides map[string]SchemaOverride = map[string]SchemaOverride{
@@ -63,6 +64,29 @@ var schemaOverrides map[string]SchemaOverride = map[string]SchemaOverride{
6364
Description: "Amount of CPUs to allocate to Kubernetes",
6465
Type: Int,
6566
},
67+
// Customize the description to be the fullset of drivers
68+
"driver": {
69+
Default: "docker",
70+
Description: "Driver is one of the following - Windows: (hyperv, docker, virtualbox, vmware, qemu2, ssh) - OSX: (virtualbox, parallels, vmwarefusion, hyperkit, vmware, qemu2, docker, podman, ssh) - Linux: (docker, kvm2, virtualbox, qemu2, none, podman, ssh)",
71+
Type: String,
72+
},
73+
// Default schema to unix file paths first and let the provider translate them during runtime
74+
"mount_string": {
75+
Description: "The argument to pass the minikube mount command on start.",
76+
Type: String,
77+
DefaultFunc: `func() (any, error) {
78+
if runtime.GOOS == "windows" {
79+
home, err := os.UserHomeDir()
80+
if err != nil {
81+
return nil, err
82+
}
83+
return home + ":" + "/minikube-host", nil
84+
} else if runtime.GOOS == "darwin" {
85+
return "/Users:/minikube-host", nil
86+
}
87+
return "/home:/minikube-host", nil
88+
}`,
89+
},
6690
}
6791

6892
func run(ctx context.Context, args ...string) (string, error) {
@@ -78,6 +102,7 @@ func run(ctx context.Context, args ...string) (string, error) {
78102
type SchemaEntry struct {
79103
Parameter string
80104
Default string
105+
DefaultFunc string
81106
Description string
82107
Type SchemaType
83108
ArrayType SchemaType
@@ -161,12 +186,14 @@ func loadParameter(line string) SchemaEntry {
161186
schemaEntry.Parameter = strings.TrimPrefix(seg[0], "--")
162187
schemaEntry.Parameter = strings.Replace(schemaEntry.Parameter, "-", "_", -1)
163188
schemaEntry.Default = strings.TrimSuffix(seg[1], ":")
189+
schemaEntry.Default = strings.ReplaceAll(schemaEntry.Default, "\\", "\\\\")
164190
schemaEntry.Type = getSchemaType(schemaEntry.Default)
165191

166192
// Apply explicit overrides
167193
val, ok := schemaOverrides[schemaEntry.Parameter]
168194
if ok {
169195
schemaEntry.Default = val.Default
196+
schemaEntry.DefaultFunc = val.DefaultFunc
170197
schemaEntry.Type = val.Type
171198
}
172199

@@ -185,13 +212,15 @@ func addEntry(entries []SchemaEntry, currentEntry SchemaEntry) ([]SchemaEntry, e
185212
Default: fmt.Sprintf("\"%s\"", currentEntry.Default),
186213
Type: currentEntry.Type,
187214
Description: currentEntry.Description,
215+
DefaultFunc: currentEntry.DefaultFunc,
188216
})
189217
case Bool:
190218
entries = append(entries, SchemaEntry{
191219
Parameter: currentEntry.Parameter,
192220
Default: currentEntry.Default,
193221
Type: currentEntry.Type,
194222
Description: currentEntry.Description,
223+
DefaultFunc: currentEntry.DefaultFunc,
195224
})
196225
case Int:
197226
val, err := strconv.Atoi(currentEntry.Default)
@@ -209,13 +238,15 @@ func addEntry(entries []SchemaEntry, currentEntry SchemaEntry) ([]SchemaEntry, e
209238
Default: strconv.Itoa(val),
210239
Type: currentEntry.Type,
211240
Description: currentEntry.Description,
241+
DefaultFunc: currentEntry.DefaultFunc,
212242
})
213243
case Array:
214244
entries = append(entries, SchemaEntry{
215245
Parameter: currentEntry.Parameter,
216246
Type: Array,
217247
ArrayType: String,
218248
Description: currentEntry.Description,
249+
DefaultFunc: currentEntry.DefaultFunc,
219250
})
220251
}
221252

@@ -232,7 +263,11 @@ func constructSchema(entries []SchemaEntry) string {
232263
// THIS FILE IS GENERATED DO NOT EDIT
233264
package minikube
234265
235-
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
266+
import (
267+
"runtime"
268+
"os"
269+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
270+
)
236271
237272
var (
238273
clusterSchema = map[string]*schema.Schema{
@@ -300,6 +335,9 @@ var (
300335
Type: %s,
301336
},
302337
`, "schema.Type"+entry.ArrayType)
338+
} else if entry.DefaultFunc != "" {
339+
extraParams += fmt.Sprintf(`
340+
DefaultFunc: %s,`, entry.DefaultFunc)
303341
} else {
304342
extraParams += fmt.Sprintf(`
305343
Default: %s,`, entry.Default)

minikube/generator/schema_builder_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ const header = `//go:generate go run ../generate/main.go -target $GOFILE
1212
// THIS FILE IS GENERATED DO NOT EDIT
1313
package minikube
1414
15-
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
15+
import (
16+
"runtime"
17+
"os"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
)
1620
1721
var (
1822
clusterSchema = map[string]*schema.Schema{
@@ -343,6 +347,21 @@ func GetClusterSchema() map[string]*schema.Schema {
343347
`, schema)
344348
}
345349

350+
func TestDefaultFuncOverride(t *testing.T) {
351+
ctrl := gomock.NewController(t)
352+
mockMinikube := NewMockMinikubeBinary(ctrl)
353+
mockMinikube.EXPECT().GetVersion(gomock.Any()).Return("Version 999", nil)
354+
mockMinikube.EXPECT().GetStartHelpText(gomock.Any()).Return(`
355+
--mount-string='':
356+
I am a great test description
357+
358+
`, nil)
359+
builder := NewSchemaBuilder("fake.go", mockMinikube)
360+
schema, err := builder.Build()
361+
assert.NoError(t, err)
362+
assert.Contains(t, schema, "DefaultFunc: func() (any, error) {")
363+
}
364+
346365
func TestPropertyFailure(t *testing.T) {
347366
ctrl := gomock.NewController(t)
348367
mockMinikube := NewMockMinikubeBinary(ctrl)

minikube/resource_cluster_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func mockSuccess(t *testing.T, clusterName string) schema.ConfigureContextFunc {
108108
_ = os.WriteFile("test_output/key", d1, 0644)
109109

110110
clusterSchema := ResourceCluster().Schema
111+
mountString, _ := clusterSchema["mount_string"].DefaultFunc()
111112

112113
k8sVersion := "v1.25.3"
113114
kubernetesConfig := config.KubernetesConfig{
@@ -180,7 +181,7 @@ func mockSuccess(t *testing.T, clusterName string) schema.ConfigureContextFunc {
180181
ExtraDisks: clusterSchema["extra_disks"].Default.(int),
181182
CertExpiration: time.Duration(clusterSchema["cert_expiration"].Default.(int)) * time.Minute,
182183
Mount: clusterSchema["hyperv_use_external_switch"].Default.(bool),
183-
MountString: clusterSchema["mount_string"].Default.(string),
184+
MountString: mountString.(string),
184185
Mount9PVersion: "9p2000.L",
185186
MountGID: "docker",
186187
MountIP: "",

minikube/schema_cluster.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// THIS FILE IS GENERATED DO NOT EDIT
33
package minikube
44

5-
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
5+
import (
6+
"runtime"
7+
"os"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
)
610

711
var (
812
clusterSchema = map[string]*schema.Schema{
@@ -303,12 +307,12 @@ var (
303307

304308
"driver": {
305309
Type: schema.TypeString,
306-
Description: "Driver is one of: virtualbox, parallels, vmwarefusion, hyperkit, vmware, qemu2 (experimental), docker, podman (experimental), ssh (defaults to auto-detect)",
310+
Description: "Driver is one of the following - Windows: (hyperv, docker, virtualbox, vmware, qemu2, ssh) - OSX: (virtualbox, parallels, vmwarefusion, hyperkit, vmware, qemu2, docker, podman, ssh) - Linux: (docker, kvm2, virtualbox, qemu2, none, podman, ssh)",
307311

308312
Optional: true,
309313
ForceNew: true,
310314

311-
Default: "",
315+
Default: "docker",
312316
},
313317

314318
"dry_run": {
@@ -707,7 +711,18 @@ var (
707711
Optional: true,
708712
ForceNew: true,
709713

710-
Default: "/Users:/minikube-host",
714+
DefaultFunc: func() (any, error) {
715+
if runtime.GOOS == "windows" {
716+
home, err := os.UserHomeDir()
717+
if err != nil {
718+
return nil, err
719+
}
720+
return home + ":" + "/minikube-host", nil
721+
} else if runtime.GOOS == "darwin" {
722+
return "/Users:/minikube-host", nil
723+
}
724+
return "/home:/minikube-host", nil
725+
},
711726
},
712727

713728
"mount_type": {

0 commit comments

Comments
 (0)