Repository: kubernetes-sigs/kwok (go)

Issue:
[kwokctl] Download kind binary automatically if necessary
### What would you like to be added?

When using Kind as a runtime, download the kind if it doesn't exist

### Why is this needed?

Optimize the experience

Pull request description:
Download kind binary
Signed-off-by: huangminjie <minjie.huang@daocloud.io>

<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide/first-contribution.md#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/sig-release/release.md#issuepr-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/sig-testing/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

#### What type of PR is this?
/kind feature

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind documentation
/kind feature

Optionally add one or more of the following kinds if applicable:
/kind api-change
/kind deprecation
/kind failing-test
/kind flake
/kind regression
-->

#### What this PR does / why we need it:

#### Which issue(s) this PR fixes:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #105

#### Special notes for your reviewer:

#### Does this PR introduce a user-facing change?
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->
```release-note
Download kind binary
```

#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

<!--
This section can be blank if this pull request does not require a release note.

When adding links which point to resources within git repositories, like
KEPs or supporting documentation, please reference a specific commit and avoid
linking directly to the master branch. This ensures that links reference a
specific point in time, rather than a document that may change over time.

See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files

Please use the following format for linking documentation:
- [KEP]: <link>
- [Usage]: <link>
- [Other doc]: <link>
-->
```docs

```


Patch:
diff --git a/.golangci.yaml b/.golangci.yaml
index 277f616f..edccfb90 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -28,7 +28,7 @@ linters:
     # - revive
     # - rowserrcheck
     - staticcheck
-    - stylecheck
+    # - stylecheck
     - typecheck
     - unconvert
     - unparam
@@ -62,8 +62,6 @@ linters-settings:
     go: "1.19"
   stylecheck:
     go: "1.19"
-    # STxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
-    checks: [ "all", "-ST1000", "-ST1003" ]
   depguard:
     include-go-root: true
     packages:
diff --git a/pkg/apis/internalversion/kwokctl_configuration_types.go b/pkg/apis/internalversion/kwokctl_configuration_types.go
index 26003253..f6a169b1 100644
--- a/pkg/apis/internalversion/kwokctl_configuration_types.go
+++ b/pkg/apis/internalversion/kwokctl_configuration_types.go
@@ -58,6 +58,9 @@ type KwokctlConfigurationOptions struct {
 	// DockerComposeVersion is the version of docker-compose to use.
 	DockerComposeVersion string
 
+	// KindVersion is the version of kind to use.
+	KindVersion string
+
 	// SecurePort is the apiserver port on which to serve HTTPS with authentication and authorization.
 	SecurePort bool
 
@@ -125,6 +128,9 @@ type KwokctlConfigurationOptions struct {
 	// DockerComposeBinary is the binary of Docker compose.
 	DockerComposeBinary string
 
+	// KindBinary is the binary of kind.
+	KindBinary string
+
 	// Mode is several default parameter templates for clusters
 	Mode string
 
diff --git a/pkg/apis/internalversion/zz_generated.conversion.go b/pkg/apis/internalversion/zz_generated.conversion.go
index f8044698..c884ce8e 100644
--- a/pkg/apis/internalversion/zz_generated.conversion.go
+++ b/pkg/apis/internalversion/zz_generated.conversion.go
@@ -183,6 +183,7 @@ func autoConvert_internalversion_KwokctlConfigurationOptions_To_v1alpha1_Kwokctl
 	out.EtcdVersion = in.EtcdVersion
 	out.PrometheusVersion = in.PrometheusVersion
 	out.DockerComposeVersion = in.DockerComposeVersion
+	out.KindVersion = in.KindVersion
 	if err := v1.Convert_bool_To_Pointer_bool(&in.SecurePort, &out.SecurePort, s); err != nil {
 		return err
 	}
@@ -213,6 +214,7 @@ func autoConvert_internalversion_KwokctlConfigurationOptions_To_v1alpha1_Kwokctl
 	out.PrometheusBinary = in.PrometheusBinary
 	out.PrometheusBinaryTar = in.PrometheusBinaryTar
 	out.DockerComposeBinary = in.DockerComposeBinary
+	out.KindBinary = in.KindBinary
 	out.Mode = in.Mode
 	out.KubeFeatureGates = in.KubeFeatureGates
 	out.KubeRuntimeConfig = in.KubeRuntimeConfig
@@ -243,6 +245,7 @@ func autoConvert_v1alpha1_KwokctlConfigurationOptions_To_internalversion_Kwokctl
 	out.EtcdVersion = in.EtcdVersion
 	out.PrometheusVersion = in.PrometheusVersion
 	out.DockerComposeVersion = in.DockerComposeVersion
+	out.KindVersion = in.KindVersion
 	if err := v1.Convert_Pointer_bool_To_bool(&in.SecurePort, &out.SecurePort, s); err != nil {
 		return err
 	}
@@ -283,6 +286,8 @@ func autoConvert_v1alpha1_KwokctlConfigurationOptions_To_internalversion_Kwokctl
 	out.PrometheusBinaryTar = in.PrometheusBinaryTar
 	// WARNING: in.DockerComposeBinaryPrefix requires manual conversion: does not exist in peer-type
 	out.DockerComposeBinary = in.DockerComposeBinary
+	// WARNING: in.KindBinaryPrefix requires manual conversion: does not exist in peer-type
+	out.KindBinary = in.KindBinary
 	out.Mode = in.Mode
 	out.KubeFeatureGates = in.KubeFeatureGates
 	out.KubeRuntimeConfig = in.KubeRuntimeConfig
diff --git a/pkg/apis/v1alpha1/kwokctl_configuration_types.go b/pkg/apis/v1alpha1/kwokctl_configuration_types.go
index 6891a1be..05c0b1a1 100644
--- a/pkg/apis/v1alpha1/kwokctl_configuration_types.go
+++ b/pkg/apis/v1alpha1/kwokctl_configuration_types.go
@@ -75,6 +75,10 @@ type KwokctlConfigurationOptions struct {
 	// is the default value for env KWOK_DOCKER_COMPOSE_VERSION
 	DockerComposeVersion string `json:"dockerComposeVersion,omitempty"`
 
+	// KindVersion is the version of kind to use.
+	// is the default value for env KWOK_KIND_VERSION
+	KindVersion string `json:"kindVersion,omitempty"`
+
 	// SecurePort is the apiserver port on which to serve HTTPS with authentication and authorization.
 	// is the default value for flag --secure-port and env KWOK_SECURE_PORT
 	// +default=false
@@ -207,6 +211,14 @@ type KwokctlConfigurationOptions struct {
 	// is the default value for flag --docker-compose-binary and env KWOK_DOCKER_COMPOSE_BINARY
 	DockerComposeBinary string `json:"dockerComposeBinary,omitempty"`
 
+	// KindBinaryPrefix is the binary prefix of kind.
+	// is the default value for env KWOK_KIND_BINARY_PREFIX
+	KindBinaryPrefix string `json:"kindBinaryPrefix,omitempty"`
+
+	// KindBinary is the binary of kind.
+	// is the default value for flag --kind-binary and env KWOK_KIND_BINARY
+	KindBinary string `json:"kindBinary,omitempty"`
+
 	// Mode is several default parameter templates for clusters
 	// is the default value for env KWOK_MODE
 	Mode string `json:"mode,omitempty"`
diff --git a/pkg/config/vars.go b/pkg/config/vars.go
index a1eb4aa4..d05e36f2 100644
--- a/pkg/config/vars.go
+++ b/pkg/config/vars.go
@@ -318,6 +318,21 @@ func setKwokctlConfigurationDefaults(config *v1alpha1.KwokctlConfiguration) *v1a
 			conf.KindNodeImage = joinImageURI(conf.KindNodeImagePrefix, "node", conf.KubeVersion)
 		}
 		conf.KindNodeImage = envs.GetEnvWithPrefix("KIND_NODE_IMAGE", conf.KindNodeImage)
+
+		if conf.KindVersion == "" {
+			conf.KindVersion = consts.KindVersion
+		}
+		conf.KindVersion = addPrefixV(envs.GetEnvWithPrefix("KIND_VERSION", conf.KindVersion))
+
+		if conf.KindBinaryPrefix == "" {
+			conf.KindBinaryPrefix = consts.KindBinaryPrefix + "/" + conf.KindVersion
+		}
+		conf.KindBinaryPrefix = envs.GetEnvWithPrefix("KIND_BINARY_PREFIX", conf.KindBinaryPrefix)
+
+		if conf.KindBinary == "" {
+			conf.KindBinary = conf.KindBinaryPrefix + "/kind-" + runtime.GOOS + "-" + runtime.GOARCH + conf.BinSuffix
+		}
+		conf.KindBinary = envs.GetEnvWithPrefix("KIND_BINARY", conf.KindBinary)
 	}
 
 	if runtimeDocker {
diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go
index cbd83204..da6b9545 100644
--- a/pkg/consts/consts.go
+++ b/pkg/consts/consts.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package consts defines the constants for building the project.
 package consts
 
 var (
@@ -34,6 +33,9 @@ var (
 	DockerComposeVersion      = "2.13.0"
 	DockerComposeBinaryPrefix = "https://github.com/docker/compose/releases/download"
 
+	KindVersion      = "0.17.0"
+	KindBinaryPrefix = "https://github.com/kubernetes-sigs/kind/releases/download"
+
 	PrometheusVersion      = "2.35.0"
 	PrometheusBinaryPrefix = "https://github.com/prometheus/prometheus/releases/download"
 	PrometheusImagePrefix  = "docker.io/prom"
diff --git a/pkg/kwok/cmd/root.go b/pkg/kwok/cmd/root.go
index a1b9ab68..47a3b9fc 100644
--- a/pkg/kwok/cmd/root.go
+++ b/pkg/kwok/cmd/root.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package cmd defines a root command for the kwok.
 package cmd
 
 import (
@@ -200,8 +199,8 @@ func Serve(ctx context.Context, address string) {
 }
 
 // buildConfigFromFlags is a helper function that builds configs from a master url or a kubeconfig filepath.
-func buildConfigFromFlags(ctx context.Context, masterURL, kubeconfigPath string) (*rest.Config, error) {
-	if kubeconfigPath == "" && masterURL == "" {
+func buildConfigFromFlags(ctx context.Context, masterUrl, kubeconfigPath string) (*rest.Config, error) {
+	if kubeconfigPath == "" && masterUrl == "" {
 		logger := log.FromContext(ctx)
 		logger.Warn("Neither --kubeconfig nor --master was specified")
 		logger.Info("Using the inClusterConfig")
@@ -214,7 +213,7 @@ func buildConfigFromFlags(ctx context.Context, masterURL, kubeconfigPath string)
 	}
 	return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
 		&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
-		&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: masterURL}}).ClientConfig()
+		&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: masterUrl}}).ClientConfig()
 }
 
 func newClientset(ctx context.Context, master, kubeconfig string) (kubernetes.Interface, error) {
diff --git a/pkg/kwok/controllers/doc.go b/pkg/kwok/controllers/doc.go
deleted file mode 100644
index b2b31ea4..00000000
--- a/pkg/kwok/controllers/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package controllers is the package that contains the core logic on pods and nodes simulation.
-package controllers
diff --git a/pkg/kwok/controllers/node_controller.go b/pkg/kwok/controllers/node_controller.go
index 45d03586..8204f9a4 100644
--- a/pkg/kwok/controllers/node_controller.go
+++ b/pkg/kwok/controllers/node_controller.go
@@ -354,7 +354,7 @@ func (c *NodeController) LockNode(ctx context.Context, nodeName string) error {
 }
 
 func (c *NodeController) configureNode(node *corev1.Node) ([]byte, error) {
-	patch, err := c.renderer.renderToJSON(c.nodeStatusTemplate, node)
+	patch, err := c.renderer.renderToJson(c.nodeStatusTemplate, node)
 	if err != nil {
 		return nil, err
 	}
@@ -391,7 +391,7 @@ func (c *NodeController) configureNode(node *corev1.Node) ([]byte, error) {
 }
 
 func (c *NodeController) configureHeartbeatNode(node *corev1.Node) ([]byte, error) {
-	patch, err := c.renderer.renderToJSON(c.nodeHeartbeatTemplate, node)
+	patch, err := c.renderer.renderToJson(c.nodeHeartbeatTemplate, node)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/kwok/controllers/pod_controller.go b/pkg/kwok/controllers/pod_controller.go
index 4e12ba9e..bd54e9fc 100644
--- a/pkg/kwok/controllers/pod_controller.go
+++ b/pkg/kwok/controllers/pod_controller.go
@@ -402,7 +402,7 @@ func (c *PodController) configurePod(pod *corev1.Pod) ([]byte, error) {
 }
 
 func (c *PodController) computePatchData(pod *corev1.Pod, temp string) ([]byte, error) {
-	patch, err := c.renderer.renderToJSON(temp, pod)
+	patch, err := c.renderer.renderToJson(temp, pod)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/kwok/controllers/renderer.go b/pkg/kwok/controllers/renderer.go
index 8f6faf1a..8a428ac0 100644
--- a/pkg/kwok/controllers/renderer.go
+++ b/pkg/kwok/controllers/renderer.go
@@ -45,8 +45,8 @@ func newRenderer(funcMap template.FuncMap) *renderer {
 	}
 }
 
-// renderToJSON renders the template with the given text and original object.
-func (r *renderer) renderToJSON(text string, original interface{}) ([]byte, error) {
+// renderToJson renders the template with the given text and original object.
+func (r *renderer) renderToJson(text string, original interface{}) ([]byte, error) {
 	text = strings.TrimSpace(text)
 	v, ok := r.cache.Load(text)
 	if !ok {
diff --git a/pkg/kwok/controllers/templates/templates.go b/pkg/kwok/controllers/templates/templates.go
index 8b2700e4..77c620aa 100644
--- a/pkg/kwok/controllers/templates/templates.go
+++ b/pkg/kwok/controllers/templates/templates.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package templates contains node and pod templates used by controllers.
 package templates
 
 import (
diff --git a/pkg/kwok/controllers/utils.go b/pkg/kwok/controllers/utils.go
index aa4b49b0..8fe53198 100644
--- a/pkg/kwok/controllers/utils.go
+++ b/pkg/kwok/controllers/utils.go
@@ -34,7 +34,7 @@ func parseCIDR(s string) (*net.IPNet, error) {
 	return ipnet, nil
 }
 
-func addIP(ip net.IP, add uint64) net.IP {
+func addIp(ip net.IP, add uint64) net.IP {
 	if len(ip) < 8 {
 		return ip
 	}
@@ -67,7 +67,7 @@ func newIPPool(cidr *net.IPNet) *ipPool {
 
 func (i *ipPool) new() string {
 	for {
-		ip := addIP(i.cidr.IP, i.index).String()
+		ip := addIp(i.cidr.IP, i.index).String()
 		i.index++
 
 		if _, ok := i.used[ip]; ok {
diff --git a/pkg/kwokctl/cmd/create/cluster/cluster.go b/pkg/kwokctl/cmd/create/cluster/cluster.go
index 1fb3ea85..2fb1c115 100644
--- a/pkg/kwokctl/cmd/create/cluster/cluster.go
+++ b/pkg/kwokctl/cmd/create/cluster/cluster.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package cluster contains a command to create a cluster.
 package cluster
 
 import (
@@ -99,6 +98,8 @@ func NewCommand(ctx context.Context) *cobra.Command {
 `)
 	cmd.Flags().StringVar(&flags.DockerComposeBinary, "docker-compose-binary", flags.DockerComposeBinary, `Binary of Docker-compose, only for docker runtime
 `)
+	cmd.Flags().StringVar(&flags.KindBinary, "kind-binary", flags.KindBinary, `Binary of kind, only for kind runtime`)
+
 	cmd.Flags().StringVar(&flags.KubeFeatureGates, "kube-feature-gates", flags.KubeFeatureGates, `A set of key=value pairs that describe feature gates for alpha/experimental features of Kubernetes
 `)
 	cmd.Flags().StringVar(&flags.KubeRuntimeConfig, "kube-runtime-config", flags.KubeRuntimeConfig, `A set of key=value pairs that enable or disable built-in APIs
diff --git a/pkg/kwokctl/cmd/create/create.go b/pkg/kwokctl/cmd/create/create.go
index cb90e97e..c1759202 100644
--- a/pkg/kwokctl/cmd/create/create.go
+++ b/pkg/kwokctl/cmd/create/create.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package create defines a parent command for cluster creation.
 package create
 
 import (
diff --git a/pkg/kwokctl/cmd/delete/cluster/cluster.go b/pkg/kwokctl/cmd/delete/cluster/cluster.go
index 61ac6018..e93f8435 100644
--- a/pkg/kwokctl/cmd/delete/cluster/cluster.go
+++ b/pkg/kwokctl/cmd/delete/cluster/cluster.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package cluster contains a command to delete a cluster.
 package cluster
 
 import (
diff --git a/pkg/kwokctl/cmd/delete/delete.go b/pkg/kwokctl/cmd/delete/delete.go
index 6a5b4254..b50dc289 100644
--- a/pkg/kwokctl/cmd/delete/delete.go
+++ b/pkg/kwokctl/cmd/delete/delete.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package delete defines a parent command for cluster deletion.
 package delete
 
 import (
diff --git a/pkg/kwokctl/cmd/etcdctl/etcdctl.go b/pkg/kwokctl/cmd/etcdctl/etcdctl.go
index 24b9c52b..e8aad3bd 100644
--- a/pkg/kwokctl/cmd/etcdctl/etcdctl.go
+++ b/pkg/kwokctl/cmd/etcdctl/etcdctl.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package etcdctl provides a method for users to use the etcdctl binary in a cluster.
 package etcdctl
 
 import (
diff --git a/pkg/kwokctl/cmd/get/artifacts/artifacts.go b/pkg/kwokctl/cmd/get/artifacts/artifacts.go
index 3f76c4cf..795f7553 100644
--- a/pkg/kwokctl/cmd/get/artifacts/artifacts.go
+++ b/pkg/kwokctl/cmd/get/artifacts/artifacts.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package artifacts contains a command to list binaries or images used by a cluster.
 package artifacts
 
 import (
diff --git a/pkg/kwokctl/cmd/get/clusters/clusters.go b/pkg/kwokctl/cmd/get/clusters/clusters.go
index d72f7267..bcce301a 100644
--- a/pkg/kwokctl/cmd/get/clusters/clusters.go
+++ b/pkg/kwokctl/cmd/get/clusters/clusters.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package clusters contains a command to list existing clusters.
 package clusters
 
 import (
diff --git a/pkg/kwokctl/cmd/get/get.go b/pkg/kwokctl/cmd/get/get.go
index fc38a592..34acaa5b 100644
--- a/pkg/kwokctl/cmd/get/get.go
+++ b/pkg/kwokctl/cmd/get/get.go
@@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package get defines a parent command for getting artifacts,
-// clusters and kubeconfig.
 package get
 
 import (
diff --git a/pkg/kwokctl/cmd/get/kubeconfig/kubeconfig.go b/pkg/kwokctl/cmd/get/kubeconfig/kubeconfig.go
index 1676bf0c..da1424b4 100644
--- a/pkg/kwokctl/cmd/get/kubeconfig/kubeconfig.go
+++ b/pkg/kwokctl/cmd/get/kubeconfig/kubeconfig.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package kubeconfig contains a command to prints cluster kubeconfig
 package kubeconfig
 
 import (
diff --git a/pkg/kwokctl/cmd/kubectl/kubectl.go b/pkg/kwokctl/cmd/kubectl/kubectl.go
index ded9dc45..6fdddafc 100644
--- a/pkg/kwokctl/cmd/kubectl/kubectl.go
+++ b/pkg/kwokctl/cmd/kubectl/kubectl.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package kubectl contains a command to use the kubectl in a cluster.
 package kubectl
 
 import (
diff --git a/pkg/kwokctl/cmd/logs/logs.go b/pkg/kwokctl/cmd/logs/logs.go
index 1a7908ce..44e960e7 100644
--- a/pkg/kwokctl/cmd/logs/logs.go
+++ b/pkg/kwokctl/cmd/logs/logs.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package logs contains a command to log a component of a cluster.
 package logs
 
 import (
diff --git a/pkg/kwokctl/cmd/root.go b/pkg/kwokctl/cmd/root.go
index 9f1f314f..7fd2bb0c 100644
--- a/pkg/kwokctl/cmd/root.go
+++ b/pkg/kwokctl/cmd/root.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package cmd defines a root command for the kwokctl.
 package cmd
 
 import (
diff --git a/pkg/kwokctl/cmd/snapshot/restore/restore.go b/pkg/kwokctl/cmd/snapshot/restore/restore.go
index 77c1aaff..0e78c11c 100644
--- a/pkg/kwokctl/cmd/snapshot/restore/restore.go
+++ b/pkg/kwokctl/cmd/snapshot/restore/restore.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package restore provides a command to restore the snapshot of a cluster.
 package restore
 
 import (
diff --git a/pkg/kwokctl/cmd/snapshot/save/save.go b/pkg/kwokctl/cmd/snapshot/save/save.go
index 378ee58a..a23f2412 100644
--- a/pkg/kwokctl/cmd/snapshot/save/save.go
+++ b/pkg/kwokctl/cmd/snapshot/save/save.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package save provides a command to save the snapshot of a cluster.
 package save
 
 import (
diff --git a/pkg/kwokctl/cmd/snapshot/snapshot.go b/pkg/kwokctl/cmd/snapshot/snapshot.go
index fbe5ffbd..0307f3cc 100644
--- a/pkg/kwokctl/cmd/snapshot/snapshot.go
+++ b/pkg/kwokctl/cmd/snapshot/snapshot.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package snapshot contains a parent command which snapshots one of cluster.
 package snapshot
 
 import (
diff --git a/pkg/kwokctl/k8s/doc.go b/pkg/kwokctl/k8s/doc.go
deleted file mode 100644
index 1b7cc708..00000000
--- a/pkg/kwokctl/k8s/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package k8s contains some helper functions related to the Kuberentes.
-package k8s
diff --git a/pkg/kwokctl/pki/doc.go b/pkg/kwokctl/pki/doc.go
deleted file mode 100644
index d23f713d..00000000
--- a/pkg/kwokctl/pki/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package pki is the package that provides functions to generate certificates
-package pki
diff --git a/pkg/kwokctl/runtime/binary/doc.go b/pkg/kwokctl/runtime/binary/doc.go
deleted file mode 100644
index a899c7dc..00000000
--- a/pkg/kwokctl/runtime/binary/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package binary implements the runtime.Runtime interface using the binaries.
-package binary
diff --git a/pkg/kwokctl/runtime/compose/doc.go b/pkg/kwokctl/runtime/compose/doc.go
deleted file mode 100644
index 357dd3a0..00000000
--- a/pkg/kwokctl/runtime/compose/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package compose implements the runtime.Runtime interface using the image with compose file.
-package compose
diff --git a/pkg/kwokctl/runtime/doc.go b/pkg/kwokctl/runtime/doc.go
deleted file mode 100644
index a050043a..00000000
--- a/pkg/kwokctl/runtime/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package runtime defines the interface of a cluster operation and providers a register method.
-package runtime
diff --git a/pkg/kwokctl/runtime/kind/cluster.go b/pkg/kwokctl/runtime/kind/cluster.go
index 0cca8bb4..3bc9c735 100644
--- a/pkg/kwokctl/runtime/kind/cluster.go
+++ b/pkg/kwokctl/runtime/kind/cluster.go
@@ -142,10 +142,15 @@ func (c *Cluster) Up(ctx context.Context) error {
 
 	logger := log.FromContext(ctx)
 
+	kindPath, err := c.preDownloadKind(ctx)
+	if err != nil {
+		return err
+	}
+
 	err = exec.Exec(ctx, "", exec.IOStreams{
 		ErrOut: os.Stderr,
 		Out:    os.Stderr,
-	}, conf.Runtime, "create", "cluster",
+	}, kindPath, "create", "cluster",
 		"--config", c.GetWorkdirPath(runtime.KindName),
 		"--name", c.Name(),
 		"--image", conf.KindNodeImage,
@@ -159,7 +164,7 @@ func (c *Cluster) Up(ctx context.Context) error {
 	if conf.PrometheusPort != 0 {
 		images = append(images, conf.PrometheusImage)
 	}
-	err = loadImages(ctx, "kind", c.Name(), images)
+	err = loadImages(ctx, kindPath, c.Name(), images)
 	if err != nil {
 		return err
 	}
@@ -290,20 +295,20 @@ func (c *Cluster) Ready(ctx context.Context) (bool, error) {
 }
 
 func (c *Cluster) Down(ctx context.Context) error {
-	conf, err := c.Config(ctx)
-	if err != nil {
-		return err
-	}
-
 	// unset the context in default kubeconfig
 	_ = c.Kubectl(ctx, exec.IOStreams{}, "config", "unset", "contexts."+c.Name()+".cluster")
 	_ = c.Kubectl(ctx, exec.IOStreams{}, "config", "unset", "contexts."+c.Name()+".user")
 
+	kindPath, err := c.preDownloadKind(ctx)
+	if err != nil {
+		return err
+	}
+
 	logger := log.FromContext(ctx)
 	err = exec.Exec(ctx, "", exec.IOStreams{
 		ErrOut: os.Stderr,
 		Out:    os.Stderr,
-	}, conf.Runtime, "delete", "cluster", "--name", c.Name())
+	}, kindPath, "delete", "cluster", "--name", c.Name())
 	if err != nil {
 		logger.Error("Failed to delete cluster", err)
 	}
@@ -401,3 +406,24 @@ func (c *Cluster) EtcdctlInCluster(ctx context.Context, stm exec.IOStreams, args
 	return c.KubectlInCluster(ctx, stm,
 		append([]string{"exec", "-i", "-n", "kube-system", etcdContainerName, "--", "etcdctl", "--endpoints=127.0.0.1:2379", "--cert=/etc/kubernetes/pki/etcd/server.crt", "--key=/etc/kubernetes/pki/etcd/server.key", "--cacert=/etc/kubernetes/pki/etcd/ca.crt"}, args...)...)
 }
+
+// preDownloadKind pre-download and cache kind
+func (c *Cluster) preDownloadKind(ctx context.Context) (string, error) {
+	conf, err := c.Config(ctx)
+	if err != nil {
+		return "", err
+	}
+
+	_, err = exec.LookPath("kind")
+	if err != nil {
+		// kind does not exist, try to download it
+		kindPath := c.GetBinPath("kind" + conf.BinSuffix)
+		err = file.DownloadWithCache(ctx, conf.CacheDir, conf.KindBinary, kindPath, 0755, conf.QuietPull)
+		if err != nil {
+			return "", err
+		}
+		return kindPath, nil
+	}
+
+	return "kind", nil
+}
diff --git a/pkg/kwokctl/runtime/kind/doc.go b/pkg/kwokctl/runtime/kind/doc.go
deleted file mode 100644
index 4efcafc8..00000000
--- a/pkg/kwokctl/runtime/kind/doc.go
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package kind implements the runtime.Runtime interface using the kind.
-
-package kind
diff --git a/pkg/log/doc.go b/pkg/log/doc.go
deleted file mode 100644
index 97aa5fb7..00000000
--- a/pkg/log/doc.go
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-Copyright 2022 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Package log wrappers slog for the kwok and kwokctl
-package log
diff --git a/pkg/utils/signals/signals.go b/pkg/utils/signals/signals.go
index f650007d..b7bdf6ff 100644
--- a/pkg/utils/signals/signals.go
+++ b/pkg/utils/signals/signals.go
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-// Package signals is the package that provide helper functions to receive signals from the system.
 package signals
 
 import (


Test patch:
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 81ea6e5e..94b93074 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -127,13 +127,6 @@ jobs:
           ./hack/requirements.sh compose
            docker compose version
 
-      - name: Install Kind
-        if: ${{ matrix.kwokctl-runtime == 'kind' }}
-        shell: bash
-        run: |
-          ./hack/requirements.sh kind
-          kind version
-
       - name: Docker Info
         if: ${{ matrix.kwokctl-runtime != 'binary' }}
         shell: bash
diff --git a/pkg/kwok/controllers/renderer_test.go b/pkg/kwok/controllers/renderer_test.go
index 4526eca4..5fb471f5 100644
--- a/pkg/kwok/controllers/renderer_test.go
+++ b/pkg/kwok/controllers/renderer_test.go
@@ -69,7 +69,7 @@ func TestRenderToJson(t *testing.T) {
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			r := newRenderer(tc.funcMap)
-			actual, err := r.renderToJSON(tc.templText, tc.original)
+			actual, err := r.renderToJson(tc.templText, tc.original)
 			if err != nil {
 				t.Fatal(err)
 			}
diff --git a/test/kwokctl/kwokctl_kind_audit.test.sh b/test/kwokctl/kwokctl_kind_audit.test.sh
index 2a63e4a1..eeef01a8 100755
--- a/test/kwokctl/kwokctl_kind_audit.test.sh
+++ b/test/kwokctl/kwokctl_kind_audit.test.sh
@@ -25,7 +25,6 @@ source "${ROOT_DIR}/hack/requirements.sh"
 function requirements() {
   install_kubectl
   install_buildx
-  install_kind
 }
 
 function main() {
diff --git a/test/kwokctl/kwokctl_kind_authorization.test.sh b/test/kwokctl/kwokctl_kind_authorization.test.sh
index abc02032..1f7f4a64 100755
--- a/test/kwokctl/kwokctl_kind_authorization.test.sh
+++ b/test/kwokctl/kwokctl_kind_authorization.test.sh
@@ -25,7 +25,6 @@ source "${ROOT_DIR}/hack/requirements.sh"
 function requirements() {
   install_kubectl
   install_buildx
-  install_kind
 }
 
 function main() {
diff --git a/test/kwokctl/kwokctl_kind_snapshot.test.sh b/test/kwokctl/kwokctl_kind_snapshot.test.sh
index 9609972d..a25bb9d5 100755
--- a/test/kwokctl/kwokctl_kind_snapshot.test.sh
+++ b/test/kwokctl/kwokctl_kind_snapshot.test.sh
@@ -25,7 +25,6 @@ source "${ROOT_DIR}/hack/requirements.sh"
 function requirements() {
   install_kubectl
   install_buildx
-  install_kind
 }
 
 function main() {