Skip to content

Commit

Permalink
PVC object moved to the k0smotron types
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Makhov <[email protected]>
  • Loading branch information
makhov committed Nov 16, 2023
1 parent 9fc744b commit 66f0be4
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 39 additions & 1 deletion api/k0smotron.io/v1beta1/k0smotroncluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,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"`
Expand Down
55 changes: 54 additions & 1 deletion api/k0smotron.io/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion internal/controller/k0smotron.io/k0smotroncluster_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,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,
Expand Down
9 changes: 8 additions & 1 deletion inttest/capi-docker/capi_docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ metadata:
spec:
k0sVersion: v1.27.2-k0s.0
persistence:
type: emptyDir
type: pvc
persistentVolumeClaim:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Mi
service:
type: NodePort
k0sConfig:
Expand Down

0 comments on commit 66f0be4

Please sign in to comment.