diff --git a/api/controlplane/v1beta1/k0s_types.go b/api/controlplane/v1beta1/k0s_types.go index 739cae182..2a8ee2015 100644 --- a/api/controlplane/v1beta1/k0s_types.go +++ b/api/controlplane/v1beta1/k0s_types.go @@ -46,6 +46,10 @@ type K0sControlPlaneSpec struct { //+kubebuilder:validation:Optional //+kubebuilder:default=1 Replicas int32 `json:"replicas,omitempty"` + // K0sVersion defines the k0s version to be deployed. If empty k0smotron + // will pick it automatically. + //+kubebuilder:validation:Optional + K0sVersion string `json:"k0sVersion,omitempty"` } type K0sBootstrapConfigSpec struct { diff --git a/config/crd/bases/controlplane.cluster.x-k8s.io_k0scontrolplanes.yaml b/config/crd/bases/controlplane.cluster.x-k8s.io_k0scontrolplanes.yaml index 893758ed5..f87ce3ee4 100644 --- a/config/crd/bases/controlplane.cluster.x-k8s.io_k0scontrolplanes.yaml +++ b/config/crd/bases/controlplane.cluster.x-k8s.io_k0scontrolplanes.yaml @@ -122,6 +122,10 @@ spec: For reference see the Kubernetes version skew policy: https://kubernetes.io/docs/setup/release/version-skew-policy/' type: string type: object + k0sVersion: + description: K0sVersion defines the k0s version to be deployed. If + empty k0smotron will pick it automatically. + type: string machineTemplate: properties: infrastructureRef: diff --git a/internal/controller/controlplane/helper.go b/internal/controller/controlplane/helper.go index 6a91c8164..e16bdabda 100644 --- a/internal/controller/controlplane/helper.go +++ b/internal/controller/controlplane/helper.go @@ -43,7 +43,7 @@ func (c *K0sController) deleteMachine(ctx context.Context, name string, kcp *cpv } func (c *K0sController) generateMachine(_ context.Context, name string, cluster *clusterv1.Cluster, kcp *cpv1beta1.K0sControlPlane, infraRef corev1.ObjectReference) *clusterv1.Machine { - ver := semver.MustParse(kcp.Spec.K0sConfigSpec.Version) + ver := semver.MustParse(kcp.Spec.K0sVersion) v := fmt.Sprintf("%d.%d.%d", ver.Major(), ver.Minor(), ver.Patch()) return &clusterv1.Machine{ TypeMeta: metav1.TypeMeta{ diff --git a/internal/controller/controlplane/k0s_controlplane_controller.go b/internal/controller/controlplane/k0s_controlplane_controller.go index 52f25e4a3..e1281a8f5 100644 --- a/internal/controller/controlplane/k0s_controlplane_controller.go +++ b/internal/controller/controlplane/k0s_controlplane_controller.go @@ -80,8 +80,8 @@ func (c *K0sController) Reconcile(ctx context.Context, req ctrl.Request) (res ct return ctrl.Result{}, nil } - if kcp.Spec.K0sConfigSpec.Version == "" { - kcp.Spec.K0sConfigSpec.Version = defaultK0SVersion + if kcp.Spec.K0sVersion == "" { + kcp.Spec.K0sVersion = defaultK0SVersion } cluster, err := capiutil.GetOwnerCluster(ctx, c.Client, kcp.ObjectMeta) diff --git a/inttest/capi-controlplane-docker-worker/capi_controlplane_docker_worker_test.go b/inttest/capi-controlplane-docker-worker/capi_controlplane_docker_worker_test.go index f83552067..e8107486a 100644 --- a/inttest/capi-controlplane-docker-worker/capi_controlplane_docker_worker_test.go +++ b/inttest/capi-controlplane-docker-worker/capi_controlplane_docker_worker_test.go @@ -195,7 +195,7 @@ metadata: spec: replicas: 1 k0sConfigSpec: - version: v1.27.3+k0s.0 + version: v1.28.2+k0s.0 k0s: apiVersion: k0s.k0sproject.io/v1beta1 kind: ClusterConfig