Skip to content

Commit

Permalink
Fix PVC creation if SC is not specified
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
viveksinghggits committed Nov 3, 2024
1 parent e184f33 commit ec2dc56
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/create_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit ec2dc56

Please sign in to comment.