Skip to content

Commit 2068c18

Browse files
authored
Merge pull request #406 from stmcginnis/setruntime
Explicitly set provider runtime
2 parents c9c38aa + 8e2a5ee commit 2068c18

2 files changed

Lines changed: 42 additions & 18 deletions

File tree

cmd/app.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,38 @@ func runE(cmd *cobra.Command, args []string) error {
177177
config.DefaultConfig.ControlPlaneConnectivity = config.Portmap
178178

179179
// initialize kind provider
180+
// Check KIND_EXPERIMENTAL_PROVIDER directly, as the kind CLI does, so it
181+
// takes effect regardless of auto-detection results.
180182
var option cluster.ProviderOption
181-
switch p := container.Runtime(); p {
182-
case "podman":
183-
option = cluster.ProviderWithPodman()
184-
case "nerdctl", "finch", "nerdctl.lima":
185-
option = cluster.ProviderWithNerdctl(p)
186-
default:
187-
option = cluster.ProviderWithDocker()
183+
if p := os.Getenv("KIND_EXPERIMENTAL_PROVIDER"); p != "" {
184+
switch p {
185+
case "podman":
186+
klog.Infof("Using podman provider due to KIND_EXPERIMENTAL_PROVIDER")
187+
option = cluster.ProviderWithPodman()
188+
container.SetRuntime("podman")
189+
case "docker":
190+
klog.Infof("Using docker provider due to KIND_EXPERIMENTAL_PROVIDER")
191+
option = cluster.ProviderWithDocker()
192+
container.SetRuntime("docker")
193+
case "nerdctl", "finch", "nerdctl.lima":
194+
klog.Infof("Using %s provider due to KIND_EXPERIMENTAL_PROVIDER", p)
195+
option = cluster.ProviderWithNerdctl(p)
196+
container.SetRuntime(p)
197+
default:
198+
klog.Warningf("Ignoring unknown KIND_EXPERIMENTAL_PROVIDER value %q", p)
199+
}
200+
}
201+
if option == nil {
202+
p := container.DetectRuntime()
203+
container.SetRuntime(p)
204+
switch p {
205+
case "podman":
206+
option = cluster.ProviderWithPodman()
207+
case "nerdctl", "finch", "nerdctl.lima":
208+
option = cluster.ProviderWithNerdctl(p)
209+
default:
210+
option = cluster.ProviderWithDocker()
211+
}
188212
}
189213
kindProvider := cluster.NewProvider(
190214
option,

pkg/container/container.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ func Runtime() string {
4343
return containerRuntime
4444
}
4545

46-
func init() {
47-
// allow to override the container provider as we do in KIND
48-
if p := os.Getenv("KIND_EXPERIMENTAL_PROVIDER"); p != "" {
49-
containerRuntime = p
50-
return
51-
}
46+
// SetRuntime overrides the auto-detected container runtime.
47+
func SetRuntime(name string) {
48+
containerRuntime = name
49+
}
5250

51+
// DetectRuntime probes the system for an available container runtime.
52+
func DetectRuntime() string {
5353
if dockerIsAvailable() {
54-
return
54+
return "docker"
5555
}
5656
if podmanIsAvailable() {
57-
containerRuntime = "podman"
58-
return
57+
return "podman"
5958
}
6059
if nerdctlIsAvailable() {
61-
containerRuntime = "nerdctl"
6260
if _, err := exec.LookPath("nerdctl"); err != nil {
6361
if _, err := exec.LookPath("finch"); err == nil {
64-
containerRuntime = "finch"
62+
return "finch"
6563
}
6664
}
65+
return "nerdctl"
6766
}
67+
return "docker"
6868
}
6969

7070
func Logs(name string, w io.Writer) error {

0 commit comments

Comments
 (0)