From 1bb9278b7391b1da53a5dc30da66fac198533bb3 Mon Sep 17 00:00:00 2001 From: Florent Benoit Date: Fri, 17 Nov 2023 13:23:08 +0100 Subject: [PATCH] feat: add option to customize base image and add mount option fixes https://github.com/containers/podman-desktop-extension-minikube/issues/13 Change-Id: I0706aaa3c934aa71f30e2c1948f7811883fd12f5 Signed-off-by: Florent Benoit --- package.json | 11 +++++++++++ src/create-cluster.ts | 29 +++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 12ba114..d90bb05 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,18 @@ ], "scope": "KubernetesProviderConnectionFactory", "description": "Container Runtime" + }, + "minikube.cluster.creation.base-image": { + "type": "string", + "scope": "KubernetesProviderConnectionFactory", + "markdownDescription": "Optional base image to use for docker/podman drivers. See [documentation](https://minikube.sigs.k8s.io/docs/commands/start/#options). Intended for local development" + }, + "minikube.cluster.creation.mount-string": { + "type": "string", + "scope": "KubernetesProviderConnectionFactory", + "markdownDescription": "Optional mount definition `host-path:container-path` to include during the start of minikube container. See [documentation](https://minikube.sigs.k8s.io/docs/commands/start/#options)" } + } }, "menus": { diff --git a/src/create-cluster.ts b/src/create-cluster.ts index 9441423..2bd25c5 100644 --- a/src/create-cluster.ts +++ b/src/create-cluster.ts @@ -42,19 +42,36 @@ export async function createCluster( runtime = params['minikube.cluster.creation.runtime']; } + let baseImage = ''; + if (params['minikube.cluster.creation.base-image']) { + baseImage = params['minikube.cluster.creation.base-image']; + } + + let mountString = ''; + if (params['minikube.cluster.creation.mount-string']) { + mountString = params['minikube.cluster.creation.mount-string']; + } + const env = Object.assign({}, process.env); + const startArgs = ['start', '--profile', clusterName, '--driver', driver, '--container-runtime', runtime]; + + // add base image parameter + if (baseImage) { + startArgs.push('--base-image', baseImage); + } + if (mountString) { + // need to add also the mount option + startArgs.push('--mount'); + startArgs.push('--mount-string', mountString); + } + // update PATH to include minikube env.PATH = getMinikubePath(); // now execute the command to create the cluster try { - await runCliCommand( - minikubeCli, - ['start', '--profile', clusterName, '--driver', driver, '--container-runtime', runtime], - { env, logger }, - token, - ); + await runCliCommand(minikubeCli, startArgs, { env, logger }, token); telemetryLogger.logUsage('createCluster', { driver, runtime }); } catch (error) { const errorMessage = error instanceof Error ? error.message : error;