Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions api/k0smotron.io/v1beta1/k0smotroncluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package v1beta1
import (
"crypto/md5"
"fmt"
"strings"

"github.com/k0sproject/version"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
"strings"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -174,27 +175,35 @@ type Mount struct {
}

const (
defaultK0SImage = "quay.io/k0sproject/k0s"
DefaultK0SVersion = "v1.27.9-k0s.0"
DefaultK0SSuffix = "k0s.0"
DefaultEtcdImage = "quay.io/k0sproject/etcd:v3.5.13"
defaultK0SRepository = "quay.io/k0sproject/k0s"
// DefaultK0SVersion is the default version used (kubernetes version + k0s version).
DefaultK0SVersion = "v1.27.9+k0s.0"
// DefaultK0SSuffix is the default k0s version used.
DefaultK0SSuffix = "k0s.0"
// DefaultEtcdImage is the default etcd image reference used.
DefaultEtcdImage = "quay.io/k0sproject/etcd:v3.5.13"
)

func (c *ClusterSpec) GetImage() string {
k0sVersion := c.Version
if k0sVersion == "" {
k0sVersion = DefaultK0SVersion
// GetK0sImageRef returns the k0s image reference.
func (c *ClusterSpec) GetK0sImageRef() string {
k0sTag := c.Version
if k0sTag == "" {
k0sTag = DefaultK0SVersion
}

if !strings.Contains(k0sVersion, "-k0s.") {
k0sVersion = fmt.Sprintf("%s-%s", k0sVersion, DefaultK0SSuffix)
// Old references might contain "-k0s." suffix instead of "+k0s." so we check only for the presence of "k0s."
if !strings.Contains(k0sTag, "k0s.") {
k0sTag = fmt.Sprintf("%s+%s", k0sTag, DefaultK0SSuffix)
}

k0sImageRef := fmt.Sprintf("%s:%s", c.Image, k0sTag)
if c.Image == "" {
return fmt.Sprintf("%s:%s", defaultK0SImage, k0sVersion)
k0sImageRef = fmt.Sprintf("%s:%s", defaultK0SRepository, k0sTag)
}

return fmt.Sprintf("%s:%s", c.Image, k0sVersion)
// Mutate image reference to avoid "+" character in the k0s version tag which is not allowed in some
// registries like Docker Hub (https://github.com/distribution/reference/blob/main/reference.go)
return strings.ReplaceAll(k0sImageRef, "+k0s.", "-k0s.")
}

// ClusterStatus defines the observed state of K0smotronCluster
Expand Down
4 changes: 2 additions & 2 deletions api/k0smotron.io/v1beta1/k0smotroncluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestClusterSpec_GetImage(t *testing.T) {
{
name: "Only version given with suffix",
spec: &ClusterSpec{
Version: "v1.29.4-k0s.0",
Version: "v1.29.4+k0s.0",
},
want: "quay.io/k0sproject/k0s:v1.29.4-k0s.0",
},
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestClusterSpec_GetImage(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.spec.GetImage(); got != tt.want {
if got := tt.spec.GetK0sImageRef(); got != tt.want {
require.Equal(t, tt.want, got)
}
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func main() {
os.Exit(1)
}

if err = (&controlplane.K0smotronControlPlaneValidator{}).SetupK0smotronControlPlaneWebhookWithManager(mgr); err != nil {
if err = controlplane.SetupK0smotronControlPlaneWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create validation webhook", "webhook", "K0smotronControlPlaneValidator")
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion config/samples/capi/capi-controlplane-hetzner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kind: K0smotronControlPlane # This would somehow map to k0smotron
metadata:
name: cp-test
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kind: K0smotronControlPlane
metadata:
name: docker-md-test
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
2 changes: 1 addition & 1 deletion config/samples/capi/docker/docker-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kind: K0smotronControlPlane
metadata:
name: docker-test
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
20 changes: 20 additions & 0 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ webhooks:
resources:
- clusters
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-controlplane-cluster-x-k8s-io-v1beta1-k0smotroncontrolplane
failurePolicy: Fail
name: mutate-k0smotroncontrolplane-v1beta1.k0smotron.io
rules:
- apiGroups:
- controlplane.cluster.x-k8s.io
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- k0smotroncontrolplanes
sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
2 changes: 1 addition & 1 deletion docs/capi-aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kind: K0smotronControlPlane # This is the config for the controlplane
metadata:
name: k0s-aws-test-cp
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
2 changes: 1 addition & 1 deletion docs/capi-controlplane.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ kind: K0smotronControlPlane
metadata:
name: cp-test
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
2 changes: 1 addition & 1 deletion docs/capi-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ metadata:
name: docker-test-cp
namespace: default
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
2 changes: 1 addition & 1 deletion docs/capi-hetzner.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ kind: K0smotronControlPlane # This is the config for the controlplane
metadata:
name: hetzner-test-cp
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
2 changes: 1 addition & 1 deletion docs/capi-kubevirt.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ kind: K0smotronControlPlane # This is the config for the controlplane
metadata:
name: k0s-test-cp
spec:
version: v1.27.4-k0s.0
version: v1.27.4+k0s.0
persistence:
type: emptyDir
service:
Expand Down
2 changes: 1 addition & 1 deletion docs/capi-remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ metadata:
name: remote-test
namespace: default
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: emptyDir
service:
Expand Down
28 changes: 14 additions & 14 deletions docs/capi-vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ This example demonstrates how k0smotron can be used with CAPV (Cluster API Provi
**Table of Contents**

- [Cluster API - VMware](#cluster-api---vmware)
* [Setting the scene](#setting-the-scene)
* [Preparations](#preparations)
+ [Configure clusterctl on the local machine](#configure-clusterctl-on-the-local-machine)
+ [Deploy Cluster API in the management cluster](#deploy-cluster-api-in-the-management-cluster)
+ [(Optional) IPAM IP pool creation](#optional-ipam-ip-pool-creation)
* [(Optional) MetalLB as Load Balancer solution in the management cluster](#optional-metallb-as-load-balancer-solution-in-the-management-cluster)
* [Operating child clusters](#operating-child-clusters)
+ [Generate a child cluster definition using the template](#generate-a-child-cluster-definition-using-the-template)
- [Control plane in Pods](#control-plane-in-pods)
- [Control plane in VMs](#control-plane-in-vms)
+ [Deploy the child clusters](#deploy-the-child-clusters)
+ [Observe the child cluster objects](#observe-the-child-cluster-objects)
+ [Deleting the child cluster](#deleting-the-child-cluster)
- [Setting the scene](#setting-the-scene)
- [Preparations](#preparations)
- [Configure clusterctl on the local machine](#configure-clusterctl-on-the-local-machine)
- [Deploy Cluster API in the management cluster](#deploy-cluster-api-in-the-management-cluster)
- [(Optional) IPAM IP pool creation](#optional-ipam-ip-pool-creation)
- [(Optional) MetalLB as Load Balancer solution in the management cluster](#optional-metallb-as-load-balancer-solution-in-the-management-cluster)
- [Operating child clusters](#operating-child-clusters)
- [Generate a child cluster definition using the template](#generate-a-child-cluster-definition-using-the-template)
- [Control plane in Pods:](#control-plane-in-pods)
- [Control plane in VMs:](#control-plane-in-vms)
- [Deploy the child clusters](#deploy-the-child-clusters)
- [Observe the child cluster objects](#observe-the-child-cluster-objects)
- [Deleting the child cluster](#deleting-the-child-cluster)

## Setting the scene

Expand Down Expand Up @@ -63,7 +63,7 @@ VSPHERE_STORAGE_POLICY: "" # This is the vSph
# Keep this close to the minimum Kubernetes version of the cluster being created.
CSI_INSECURE: "1"
K0S_VERSION: "v1.29.1+k0s.1"
K0S_CP_VERSION: "v1.29.1-k0s.1"
K0S_CP_VERSION: "v1.29.1+k0s.1"
NODE_IPAM_POOL_NAME: "ipam-ip-pool"
NODE_IPAM_POOL_API_GROUP: "ipam.cluster.x-k8s.io"
NODE_IPAM_POOL_KIND: "InClusterIPPool"
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
spec:
replicas: 1
image: quay.io/k0sproject/k0s
version: v1.27.1-k0s.0
version: v1.27.1+k0s.0
service:
type: NodePort
apiPort: 30443
Expand Down
2 changes: 1 addition & 1 deletion docs/hcp-autoscaling.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metadata:
namespace: default
spec:
replicas: 1
version: "v1.31.5-k0s.0"
version: "v1.31.5+k0s.0"
service:
type: NodePort
resources:
Expand Down
4 changes: 2 additions & 2 deletions docs/ingress-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ metadata:
name: my-cluster-cp
namespace: default
spec:
version: v1.34.0-k0s.0
version: v1.34.0+k0s.0
ingress:
apiHost: kube-api.example.com
konnectivityHost: konnectivity.example.com
Expand All @@ -80,7 +80,7 @@ metadata:
name: my-cluster
namespace: default
spec:
version: v1.34.0-k0s.0
version: v1.34.0+k0s.0
ingress:
apiHost: kube-api.example.com
konnectivityHost: konnectivity.example.com
Expand Down
2 changes: 1 addition & 1 deletion docs/update/hcp-autopilot.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ metadata:
spec:
replicas: 1
k0sImage: quay.io/k0sproject/k0s
version: v1.33.1-k0s.0 # new k0s version
version: v1.33.1+k0s.0 # new k0s version
```

!!! warning
Expand Down
6 changes: 3 additions & 3 deletions docs/update/update-cluster-pod.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ the k0s version and machine names in the YAML configuration file:
metadata:
name: docker-test-cp
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
```
2. Make sure that the [persistence](../resource-reference/k0smotron.io-v1beta1.md#clusterspecpersistence) is configured
to prevent data loss. For example:
Expand All @@ -46,7 +46,7 @@ to prevent data loss. For example:
metadata:
name: docker-test-cp
spec:
version: v1.27.2-k0s.0
version: v1.27.2+k0s.0
persistence:
type: hostPath
hostPath: "/tmp/kmc-test" # k0smotron will mount a basic hostPath volume to avoid data loss.
Expand All @@ -64,7 +64,7 @@ to prevent data loss. For example:
metadata:
name: cp-test
spec:
version: v1.28.7-k0s.0 # new k0s version
version: v1.28.7+k0s.0 # new k0s version
```

4. In the same configuration, replace the names of machines running the old k0smotron version
Expand Down
4 changes: 2 additions & 2 deletions docs/update/update-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ in the YAML configuration file:
spec:
replicas: 1
k0sImage: quay.io/k0sproject/k0s
version: v1.27.1-k0s.0
version: v1.27.1+k0s.0
```

2. Change all the k0s versions to the target one. For example:
Expand All @@ -26,7 +26,7 @@ in the YAML configuration file:
spec:
replicas: 1
k0sImage: quay.io/k0sproject/k0s
version: v1.28.7-k0s.0 # new k0s version
version: v1.28.7+k0s.0 # new k0s version
```

3. Update the resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ metadata:
namespace: ${NAMESPACE}
spec:
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
version: v1.30.1-k0s.0
version: v1.30.1+k0s.0
service:
type: NodePort

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ kind: K0smotronControlPlane
metadata:
name: ${CLUSTER_NAME}-cp
spec:
version: v1.34.1-k0s.0
version: v1.34.1+k0s.0
ingress:
apiHost: kube-api.${KIND_IP}.nip.io
konnectivityHost: konnectivity.${KIND_IP}.nip.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
namespace: ${NAMESPACE}
key: value
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
version: v1.30.1-k0s.0
version: v1.30.1+k0s.0
service:
type: NodePort

Expand Down
Loading
Loading