From 6eeb54a7babd1182161d0e2590c98265b1bed44f Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Tue, 14 Nov 2023 09:50:47 +0200 Subject: [PATCH 1/2] Fix PVC generation: name and CRD. GitHub image repo Signed-off-by: Alexey Makhov --- inttest/capi-docker/capi_docker_test.go | 1 + inttest/capi-remote-machine/capi_remote_machine_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/inttest/capi-docker/capi_docker_test.go b/inttest/capi-docker/capi_docker_test.go index 7a1df4a04..6f5c86a8a 100644 --- a/inttest/capi-docker/capi_docker_test.go +++ b/inttest/capi-docker/capi_docker_test.go @@ -214,6 +214,7 @@ kind: K0smotronControlPlane metadata: name: docker-test spec: + k0sImage: ghcr.io/k0sproject/k0s k0sVersion: v1.27.2-k0s.0 persistence: type: emptyDir diff --git a/inttest/capi-remote-machine/capi_remote_machine_test.go b/inttest/capi-remote-machine/capi_remote_machine_test.go index 434e686a0..ee20219ef 100644 --- a/inttest/capi-remote-machine/capi_remote_machine_test.go +++ b/inttest/capi-remote-machine/capi_remote_machine_test.go @@ -274,6 +274,7 @@ metadata: name: remote-test namespace: default spec: + k0sImage: ghcr.io/k0sproject/k0s k0sVersion: v1.27.2-k0s.0 persistence: type: emptyDir From 99534b7f398397bb4554a9b8d6783ac303298501 Mon Sep 17 00:00:00 2001 From: Alexey Makhov Date: Wed, 15 Nov 2023 15:27:20 +0200 Subject: [PATCH 2/2] PVC object moved to the k0smotron types Signed-off-by: Alexey Makhov --- .github/workflows/go.yml | 4 ++ .../v1beta1/k0smotroncluster_types.go | 40 +++++++++++++- .../v1beta1/zz_generated.deepcopy.go | 55 ++++++++++++++++++- .../k0smotroncluster_statefulset.go | 11 +++- inttest/capi-docker/capi_docker_test.go | 10 +++- .../capi_remote_machine_test.go | 1 - 6 files changed, 115 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0c6d89a16..b60b8eed0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -182,6 +182,10 @@ jobs: run: | clusterctl init --infrastructure docker + - name: Install PVC provider + run: | + kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml + - name: Run inttest for CAPI with docker provider run: | kind get kubeconfig > kind.conf diff --git a/api/k0smotron.io/v1beta1/k0smotroncluster_types.go b/api/k0smotron.io/v1beta1/k0smotroncluster_types.go index 8b6dd5a59..d447c6686 100644 --- a/api/k0smotron.io/v1beta1/k0smotroncluster_types.go +++ b/api/k0smotron.io/v1beta1/k0smotroncluster_types.go @@ -153,12 +153,50 @@ type PersistenceSpec struct { Type string `json:"type"` // PersistentVolumeClaim defines the PVC configuration. Will be used as is in case of .spec.persistence.type is pvc. //+kubebuilder:validation:Optional - PersistentVolumeClaim *v1.PersistentVolumeClaim `json:"persistentVolumeClaim,omitempty"` + PersistentVolumeClaim *PersistentVolumeClaim `json:"persistentVolumeClaim,omitempty"` // HostPath defines the host path configuration. Will be used as is in case of .spec.persistence.type is hostPath. //+kubebuilder:validation:Optional HostPath string `json:"hostPath,omitempty"` } +// PersistentVolumeClaim is a user's request for and claim to a persistent volume +type PersistentVolumeClaim struct { + metav1.TypeMeta `json:",inline"` + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + // +optional + ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // spec defines the desired characteristics of a volume requested by a pod author. + // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims + // +optional + Spec v1.PersistentVolumeClaimSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` + + // status represents the current information/status of a persistent volume claim. + // Read-only. + // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims + // +optional + Status v1.PersistentVolumeClaimStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` +} + +type ObjectMeta struct { + // +optional + Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"` + + // +optional + Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"` + + // +optional + Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,rep,name=labels"` + + // +optional + Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"` + + // +optional + // +patchStrategy=merge + Finalizers []string `json:"finalizers,omitempty" patchStrategy:"merge" protobuf:"bytes,14,rep,name=finalizers"` +} + type CertificateRef struct { //+kubebuilder:validation:Enum=ca;sa;proxy Type string `json:"type"` diff --git a/api/k0smotron.io/v1beta1/zz_generated.deepcopy.go b/api/k0smotron.io/v1beta1/zz_generated.deepcopy.go index abc9f46cd..7de51cbfc 100644 --- a/api/k0smotron.io/v1beta1/zz_generated.deepcopy.go +++ b/api/k0smotron.io/v1beta1/zz_generated.deepcopy.go @@ -259,12 +259,46 @@ func (in *JoinTokenRequestStatus) DeepCopy() *JoinTokenRequestStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ObjectMeta) DeepCopyInto(out *ObjectMeta) { + *out = *in + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Finalizers != nil { + in, out := &in.Finalizers, &out.Finalizers + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectMeta. +func (in *ObjectMeta) DeepCopy() *ObjectMeta { + if in == nil { + return nil + } + out := new(ObjectMeta) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PersistenceSpec) DeepCopyInto(out *PersistenceSpec) { *out = *in if in.PersistentVolumeClaim != nil { in, out := &in.PersistentVolumeClaim, &out.PersistentVolumeClaim - *out = new(v1.PersistentVolumeClaim) + *out = new(PersistentVolumeClaim) (*in).DeepCopyInto(*out) } } @@ -279,6 +313,25 @@ func (in *PersistenceSpec) DeepCopy() *PersistenceSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PersistentVolumeClaim) DeepCopyInto(out *PersistentVolumeClaim) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PersistentVolumeClaim. +func (in *PersistentVolumeClaim) DeepCopy() *PersistentVolumeClaim { + if in == nil { + return nil + } + out := new(PersistentVolumeClaim) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { *out = *in diff --git a/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go b/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go index 98ab8a58d..5e0c4116a 100644 --- a/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go +++ b/internal/controller/k0smotron.io/k0smotroncluster_statefulset.go @@ -187,7 +187,16 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS if kmc.Spec.Persistence.PersistentVolumeClaim.Name == "" { kmc.Spec.Persistence.PersistentVolumeClaim.Name = kmc.GetVolumeName() } - statefulSet.Spec.VolumeClaimTemplates = append(statefulSet.Spec.VolumeClaimTemplates, *kmc.Spec.Persistence.PersistentVolumeClaim) + statefulSet.Spec.VolumeClaimTemplates = append(statefulSet.Spec.VolumeClaimTemplates, v1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: kmc.Spec.Persistence.PersistentVolumeClaim.Name, + Namespace: kmc.Spec.Persistence.PersistentVolumeClaim.Namespace, + Labels: kmc.Spec.Persistence.PersistentVolumeClaim.Labels, + Annotations: kmc.Spec.Persistence.PersistentVolumeClaim.Annotations, + Finalizers: kmc.Spec.Persistence.PersistentVolumeClaim.Finalizers, + }, + Spec: kmc.Spec.Persistence.PersistentVolumeClaim.Spec, + }) statefulSet.Spec.Template.Spec.Containers[0].VolumeMounts = append(statefulSet.Spec.Template.Spec.Containers[0].VolumeMounts, v1.VolumeMount{ Name: kmc.Spec.Persistence.PersistentVolumeClaim.Name, diff --git a/inttest/capi-docker/capi_docker_test.go b/inttest/capi-docker/capi_docker_test.go index 6f5c86a8a..8b21ff771 100644 --- a/inttest/capi-docker/capi_docker_test.go +++ b/inttest/capi-docker/capi_docker_test.go @@ -214,10 +214,16 @@ kind: K0smotronControlPlane metadata: name: docker-test spec: - k0sImage: ghcr.io/k0sproject/k0s k0sVersion: v1.27.2-k0s.0 persistence: - type: emptyDir + type: pvc + persistentVolumeClaim: + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Mi service: type: NodePort k0sConfig: diff --git a/inttest/capi-remote-machine/capi_remote_machine_test.go b/inttest/capi-remote-machine/capi_remote_machine_test.go index ee20219ef..434e686a0 100644 --- a/inttest/capi-remote-machine/capi_remote_machine_test.go +++ b/inttest/capi-remote-machine/capi_remote_machine_test.go @@ -274,7 +274,6 @@ metadata: name: remote-test namespace: default spec: - k0sImage: ghcr.io/k0sproject/k0s k0sVersion: v1.27.2-k0s.0 persistence: type: emptyDir