Skip to content

Commit

Permalink
Fix PVC generation: name and CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Makhov <amakhov@mirantis.com>
  • Loading branch information
makhov committed Nov 15, 2023
1 parent 4c61bce commit 9fc744b
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 5 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,16 @@ jobs:
export KUBECONFIG=$(realpath kind.conf)
docker system prune -f
make -C inttest ${{ matrix.smoke-suite }}
- name: Get k0smotron logs
if: failure()
run: |
kubectl logs -n k0smotron deploy/k0smotron-controller-manager > /tmp/${{ matrix.smoke-suite }}-k0smotron.log
- name: Collect k0s logs and support bundle
if: failure()
uses: actions/upload-artifact@v3
with:
name: smoketests-${{ matrix.smoke-suite }}-files
path: |
/tmp/${{ matrix.smoke-suite }}-k0smotron.log
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ help: ## Display this help.
### manifests
manifests_targets += config/crd/bases/bootstrap.cluster.x-k8s.io_k0sconfigs.yaml
config/crd/bases/bootstrap.cluster.x-k8s.io_k0sconfigs.yaml: $(CONTROLLER_GEN)
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases

manifests_targets += config/crd/bases/k0smotron.io_clusters.yaml
manifests_targets += config/crd/bases/k0smotron.io_jointokenrequests.yaml
Expand Down
2 changes: 1 addition & 1 deletion api/k0smotron.io/v1beta1/k0smotroncluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ 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 *v1.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"`
Expand Down
6 changes: 5 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.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ spec:
template:
properties:
metadata:
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,23 @@ spec:
description: May contain labels and annotations that
will be copied into the PVC when creating it. No other
fields are allowed and will be rejected during validation.
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
description: The specification for the PersistentVolumeClaim.
Expand Down Expand Up @@ -1685,6 +1702,23 @@ spec:
type: string
metadata:
description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata'
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
description: 'spec defines the desired characteristics of
Expand Down
34 changes: 34 additions & 0 deletions config/crd/bases/k0smotron.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,23 @@ spec:
description: May contain labels and annotations that
will be copied into the PVC when creating it. No other
fields are allowed and will be rejected during validation.
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
description: The specification for the PersistentVolumeClaim.
Expand Down Expand Up @@ -1689,6 +1706,23 @@ spec:
type: string
metadata:
description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata'
properties:
annotations:
additionalProperties:
type: string
type: object
finalizers:
items:
type: string
type: array
labels:
additionalProperties:
type: string
type: object
name:
type: string
namespace:
type: string
type: object
spec:
description: 'spec defines the desired characteristics of
Expand Down
10 changes: 8 additions & 2 deletions internal/controller/k0smotron.io/k0smotroncluster_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,16 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS
MountPath: "/var/lib/k0s",
})
case "pvc":
statefulSet.Spec.VolumeClaimTemplates = append(statefulSet.Spec.VolumeClaimTemplates, kmc.Spec.Persistence.PersistentVolumeClaim)
if kmc.Spec.Persistence.PersistentVolumeClaim == nil {
return apps.StatefulSet{}, fmt.Errorf("persistence type is pvc but no pvc is defined")
}
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.Template.Spec.Containers[0].VolumeMounts = append(statefulSet.Spec.Template.Spec.Containers[0].VolumeMounts, v1.VolumeMount{
Name: kmc.GetVolumeName(),
Name: kmc.Spec.Persistence.PersistentVolumeClaim.Name,
MountPath: "/var/lib/k0s",
})
}
Expand Down

0 comments on commit 9fc744b

Please sign in to comment.