Skip to content

Commit

Permalink
[kwokctl] Support kind-nerdctl as runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed May 16, 2024
1 parent 3b622ae commit c953f33
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 22 deletions.
2 changes: 1 addition & 1 deletion hack/requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LOCAL_BIN_DIR="${ROOT_DIR}/bin"

export PATH="${LOCAL_BIN_DIR}:${PATH}"

KIND_VERSION=0.19.0
KIND_VERSION=0.23.0

KUBE_VERSION=1.29.0

Expand Down
19 changes: 12 additions & 7 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (

EtcdBinaryPrefix = "https://github.com/etcd-io/etcd/releases/download"

KindVersion = "0.19.0"
KindVersion = "0.23.0"
KindBinaryPrefix = "https://github.com/kubernetes-sigs/kind/releases/download"
KindNodeImagePrefix = "docker.io/kindest"

Expand Down Expand Up @@ -69,12 +69,17 @@ var (

// The following runtime is provided.
const (
RuntimeTypeKind = "kind"
RuntimeTypeKindPodman = RuntimeTypeKind + "-" + RuntimeTypePodman
RuntimeTypeDocker = "docker"
RuntimeTypeNerdctl = "nerdctl"
RuntimeTypePodman = "podman"
RuntimeTypeBinary = "binary"
RuntimeTypeKind = "kind"
RuntimeTypeKindPodman = RuntimeTypeKind + "-" + RuntimeTypePodman
RuntimeTypeKindNerdctl = RuntimeTypeKind + "-" + RuntimeTypeNerdctl
RuntimeTypeKindLima = RuntimeTypeKind + "-" + RuntimeTypeLima
RuntimeTypeKindFinch = RuntimeTypeKind + "-" + RuntimeTypeFinch
RuntimeTypeDocker = "docker"
RuntimeTypePodman = "podman"
RuntimeTypeNerdctl = "nerdctl"
RuntimeTypeLima = "lima"
RuntimeTypeFinch = "finch"
RuntimeTypeBinary = "binary"
)

// The following components is provided.
Expand Down
5 changes: 4 additions & 1 deletion pkg/kwokctl/cmd/create/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ func runE(ctx context.Context, flags *flagpole) error {
}

if flags.Options.Runtime == consts.RuntimeTypeKind ||
flags.Options.Runtime == consts.RuntimeTypeKindPodman {
flags.Options.Runtime == consts.RuntimeTypeKindPodman ||
flags.Options.Runtime == consts.RuntimeTypeKindNerdctl ||
flags.Options.Runtime == consts.RuntimeTypeKindLima ||
flags.Options.Runtime == consts.RuntimeTypeKindFinch {
// override kubeconfig for kind
defer setContext()
} else {
Expand Down
17 changes: 11 additions & 6 deletions pkg/kwokctl/components/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ const (

var (
runtimeTypeMap = map[string]string{
consts.RuntimeTypeKind: RuntimeModeCluster,
consts.RuntimeTypeKindPodman: RuntimeModeCluster,
consts.RuntimeTypeDocker: RuntimeModeContainer,
consts.RuntimeTypeNerdctl: RuntimeModeContainer,
consts.RuntimeTypePodman: RuntimeModeContainer,
consts.RuntimeTypeBinary: RuntimeModeNative,
consts.RuntimeTypeKind: RuntimeModeCluster,
consts.RuntimeTypeKindPodman: RuntimeModeCluster,
consts.RuntimeTypeKindNerdctl: RuntimeModeCluster,
consts.RuntimeTypeKindLima: RuntimeModeCluster,
consts.RuntimeTypeKindFinch: RuntimeModeCluster,
consts.RuntimeTypeDocker: RuntimeModeContainer,
consts.RuntimeTypePodman: RuntimeModeContainer,
consts.RuntimeTypeNerdctl: RuntimeModeContainer,
consts.RuntimeTypeLima: RuntimeModeContainer,
consts.RuntimeTypeFinch: RuntimeModeContainer,
consts.RuntimeTypeBinary: RuntimeModeNative,
}
)

Expand Down
6 changes: 6 additions & 0 deletions pkg/kwokctl/runtime/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func (c *Cluster) Save(ctx context.Context) error {
if !slices.Contains(conf.Options.EnableCRDs, v1alpha1.StageKind) &&
conf.Options.Runtime != consts.RuntimeTypeKind &&
conf.Options.Runtime != consts.RuntimeTypeKindPodman &&
conf.Options.Runtime != consts.RuntimeTypeKindNerdctl &&
conf.Options.Runtime != consts.RuntimeTypeKindLima &&
conf.Options.Runtime != consts.RuntimeTypeKindFinch &&
len(config.FilterWithTypeFromContext[*internalversion.Stage](ctx)) == 0 {
defaultStages, err := c.getDefaultStages(conf.Options.NodeStatusUpdateFrequencyMilliseconds, conf.Options.NodeLeaseDurationSeconds != 0)
if err != nil {
Expand All @@ -191,6 +194,9 @@ func (c *Cluster) Save(ctx context.Context) error {
if !slices.Contains(conf.Options.EnableCRDs, v1alpha1.StageKind) {
if conf.Options.Runtime != consts.RuntimeTypeKind &&
conf.Options.Runtime != consts.RuntimeTypeKindPodman &&
conf.Options.Runtime != consts.RuntimeTypeKindNerdctl &&
conf.Options.Runtime != consts.RuntimeTypeKindLima &&
conf.Options.Runtime != consts.RuntimeTypeKindFinch &&
len(config.FilterWithTypeFromContext[*internalversion.Stage](ctx)) == 0 {
defaultStages, err := c.getDefaultStages(conf.Options.NodeStatusUpdateFrequencyMilliseconds, conf.Options.NodeLeaseDurationSeconds != 0)
if err != nil {
Expand Down
22 changes: 19 additions & 3 deletions pkg/kwokctl/runtime/compose/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ type Cluster struct {
canNerdctlUnlessStopped *bool
}

// NewDockerCluster creates a new Runtime for docker.
func NewDockerCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Cluster: runtime.NewCluster(name, workdir),
runtime: consts.RuntimeTypeDocker,
}, nil
}

// NewPodmanCluster creates a new Runtime for podman.
func NewPodmanCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Expand All @@ -68,11 +76,19 @@ func NewNerdctlCluster(name, workdir string) (runtime.Runtime, error) {
}, nil
}

// NewDockerCluster creates a new Runtime for docker.
func NewDockerCluster(name, workdir string) (runtime.Runtime, error) {
// NewLimaCluster creates a new Runtime for lima.
func NewLimaCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Cluster: runtime.NewCluster(name, workdir),
runtime: consts.RuntimeTypeDocker,
runtime: consts.RuntimeTypeNerdctl + "." + consts.RuntimeTypeLima,
}, nil
}

// NewFinchCluster creates a new Runtime for finch.
func NewFinchCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Cluster: runtime.NewCluster(name, workdir),
runtime: consts.RuntimeTypeFinch,
}, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/kwokctl/runtime/compose/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

func init() {
runtime.DefaultRegistry.Register(consts.RuntimeTypeDocker, NewDockerCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeNerdctl, NewNerdctlCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypePodman, NewPodmanCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeNerdctl, NewNerdctlCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeLima, NewLimaCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeFinch, NewFinchCluster)
}
24 changes: 24 additions & 0 deletions pkg/kwokctl/runtime/kind/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ func NewPodmanCluster(name, workdir string) (runtime.Runtime, error) {
}, nil
}

// NewNerdctlCluster creates a new Runtime for kind with nerdctl
func NewNerdctlCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Cluster: runtime.NewCluster(name, workdir),
runtime: consts.RuntimeTypeNerdctl,
}, nil
}

// NewLimaCluster creates a new Runtime for kind with lima
func NewLimaCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Cluster: runtime.NewCluster(name, workdir),
runtime: consts.RuntimeTypeNerdctl + "." + consts.RuntimeTypeLima,
}, nil
}

// NewFinchCluster creates a new Runtime for kind with finch
func NewFinchCluster(name, workdir string) (runtime.Runtime, error) {
return &Cluster{
Cluster: runtime.NewCluster(name, workdir),
runtime: consts.RuntimeTypeFinch,
}, nil
}

// Available checks whether the runtime is available.
func (c *Cluster) Available(ctx context.Context) error {
if c.IsDryRun() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/kwokctl/runtime/kind/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ import (
func init() {
runtime.DefaultRegistry.Register(consts.RuntimeTypeKind, NewDockerCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeKindPodman, NewPodmanCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeKindNerdctl, NewNerdctlCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeKindLima, NewLimaCluster)
runtime.DefaultRegistry.Register(consts.RuntimeTypeKindFinch, NewFinchCluster)
}
4 changes: 2 additions & 2 deletions site/content/en/docs/generated/kwokctl_create_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ kwokctl create cluster [flags]
(default "docker.io/jaegertracing/all-in-one:1.53.0")
--jaeger-port uint32 Port to expose Jaeger UI
--kind-binary string Binary of kind, only for kind/kind-podman runtime
(default "https://github.com/kubernetes-sigs/kind/releases/download/v0.19.0/kind-linux-amd64")
(default "https://github.com/kubernetes-sigs/kind/releases/download/v0.23.0/kind-linux-amd64")
--kind-node-image string Image of kind node, only for kind/kind-podman runtime
'${KWOK_KIND_NODE_IMAGE_PREFIX}/node:${KWOK_KUBE_VERSION}'
(default "docker.io/kindest/node:v1.29.0")
Expand Down Expand Up @@ -80,7 +80,7 @@ kwokctl create cluster [flags]
(default "docker.io/prom/prometheus:v2.49.1")
--prometheus-port uint32 Port to expose Prometheus metrics
--quiet-pull Pull without printing progress information
--runtime string Runtime of the cluster (binary or docker or kind or kind-podman or nerdctl or podman)
--runtime string Runtime of the cluster (binary or docker or finch or kind or kind-finch or kind-lima or kind-nerdctl or kind-podman or lima or nerdctl or podman)
--secure-port The apiserver port on which to serve HTTPS with authentication and authorization, is not available before Kubernetes 1.13.0 (default true)
--timeout duration Timeout for waiting for the cluster to be created
--wait duration Wait for the cluster to be ready
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/generated/kwokctl_get_artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kwokctl get artifacts [flags]
```
--filter string Filter the list of (binary or image)
-h, --help help for artifacts
--runtime string Runtime of the cluster (binary or docker or kind or kind-podman or nerdctl or podman)
--runtime string Runtime of the cluster (binary or docker or finch or kind or kind-finch or kind-lima or kind-nerdctl or kind-podman or lima or nerdctl or podman)
```

### Options inherited from parent commands
Expand Down

0 comments on commit c953f33

Please sign in to comment.