Skip to content

Commit 0d5cfc3

Browse files
don't hardcode the k8s version (#646)
Co-authored-by: Dave Protasowski <dprotaso@gmail.com>
1 parent 6191a36 commit 0d5cfc3

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

pkg/kind/kind.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ import (
3636
// NOTE: If you are changing kubernetesVersion and kindVersion, please also
3737
// update the kubectl and kind versions listed here:
3838
// https://github.com/knative-extensions/kn-plugin-quickstart/blob/main/README.md
39-
//
40-
// NOTE: Latest minimum k8 version needed for knative can be found here:
41-
// https://github.com/knative/pkg/blob/main/version/version.go#L36
42-
var kubernetesVersion = "kindest/node:v1.32.0"
43-
var clusterName string
44-
var kindVersion = 0.26
45-
var container_reg_name = "kind-registry"
46-
var container_reg_port = "5001"
47-
var installKnative = true
39+
var (
40+
kubernetesVersion = ""
41+
clusterName string
42+
kindVersion = 0.26
43+
container_reg_name = "kind-registry"
44+
container_reg_port = "5001"
45+
installKnative = true
46+
)
4847

4948
// SetUp creates a local Kind cluster and installs all the relevant Knative components
5049
func SetUp(name, kVersion string, installServing, installEventing, installKindRegistry bool, installKindExtraMountHostPath string, installKindExtraMountContainerPath string) error {
@@ -239,7 +238,6 @@ data:
239238
// checkKindVersion validates that the user has the correct version of Kind installed.
240239
// If not, it prompts the user to download a newer version before continuing.
241240
func checkKindVersion() error {
242-
243241
versionCheck := exec.Command("kind", "version", "-q")
244242
out, err := versionCheck.CombinedOutput()
245243
if err != nil {
@@ -366,8 +364,7 @@ func recreateCluster(registry bool, extraMountHostPath string, extraMountContain
366364
func createNewCluster(extraMountHostPath string, extraMountContainerPath string) error {
367365
extraMount := ""
368366
if extraMountHostPath != "" && extraMountContainerPath != "" {
369-
extraMount = fmt.Sprintf(`
370-
extraMounts:
367+
extraMount = fmt.Sprintf(`extraMounts:
371368
- hostPath: %s
372369
containerPath: %s`, extraMountHostPath, extraMountContainerPath)
373370
}
@@ -378,6 +375,11 @@ func createNewCluster(extraMountHostPath string, extraMountContainerPath string)
378375
fmt.Println("☸ Creating Kind cluster with extraMounts...")
379376
}
380377

378+
imageString := ""
379+
if kubernetesVersion != "" {
380+
imageString = fmt.Sprintf(`image: %s`, kubernetesVersion)
381+
}
382+
381383
config := fmt.Sprintf(`
382384
kind: Cluster
383385
apiVersion: kind.x-k8s.io/v1alpha4
@@ -388,11 +390,12 @@ containerdConfigPatches:
388390
config_path = "/etc/containerd/certs.d/"
389391
nodes:
390392
- role: control-plane
391-
image: %s %s
393+
%s
394+
%s
392395
extraPortMappings:
393396
- containerPort: 31080
394397
listenAddress: 0.0.0.0
395-
hostPort: 80`, clusterName, kubernetesVersion, extraMount)
398+
hostPort: 80`, clusterName, imageString, extraMount)
396399

397400
createCluster := exec.Command("kind", "create", "cluster", "--wait=120s", "--config=-")
398401
createCluster.Stdin = strings.NewReader(config)

0 commit comments

Comments
 (0)