From ec2dc56f07fe328b1e6b7866edb3510744748536 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Sun, 3 Nov 2024 19:11:32 +0100 Subject: [PATCH] Fix PVC creation if SC is not specified If SC was not configured in CLI `kreate` the PVC resource that got created has SC set to empty string `""` which resulted into the problem and the volume was not provisioned. This commit fixes that by making sure that if the sc is not configured we don't sc which would result into defalt SC being used in the PVC. --- cmd/create_pvc.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/create_pvc.go b/cmd/create_pvc.go index 134bf25..cd10ab7 100644 --- a/cmd/create_pvc.go +++ b/cmd/create_pvc.go @@ -96,7 +96,7 @@ func (o *CreatePVCOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args } func (o *CreatePVCOptions) createPVCObject() *corev1.PersistentVolumeClaim { - return &corev1.PersistentVolumeClaim{ + pvc := &corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: o.Name, Namespace: o.Namespace, @@ -107,12 +107,17 @@ func (o *CreatePVCOptions) createPVCObject() *corev1.PersistentVolumeClaim { "storage": resource.MustParse(fmt.Sprintf("%sGi", o.Size)), }, }, - StorageClassName: &o.StorageClass, AccessModes: []corev1.PersistentVolumeAccessMode{ corev1.ReadWriteOnce, }, }, } + + if o.StorageClass != "" { + pvc.Spec.StorageClassName = &o.StorageClass + } + + return pvc } func (o *CreatePVCOptions) Run() error {