Skip to content

Commit 0bc5cb7

Browse files
committed
Do not use MustParse to process PVC size
The resource.MustParse function was previously used by the operator to process the storageSize request provided by the top-level CR. However, even though defer() and recover() can be used to handle the panic() generated by that function in case of a wrong user input, that approach doesn't seem to work properly and the operator crashes without any chance to recover. The ParseQuantity implementation returns an error instead of panic(), and it can be easily caught at the operator level. This change moves away from the MustParse usage and relies on the ParseQuantity mechanism. Signed-off-by: Francesco Pantano <[email protected]>
1 parent ccfe3fc commit 0bc5cb7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

controllers/ovndbcluster_controller.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,13 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
578578
return ctrl.Result{}, fmt.Errorf("waiting for Topology requirements: %w", err)
579579
}
580580

581+
stsSpec, err := ovndbcluster.StatefulSet(instance, inputHash,
582+
serviceLabels, serviceAnnotations, topology)
583+
if err != nil {
584+
return ctrl.Result{}, err
585+
}
581586
// Define a new Statefulset object
582-
sfset := statefulset.NewStatefulSet(
583-
ovndbcluster.StatefulSet(instance, inputHash, serviceLabels, serviceAnnotations, topology),
584-
time.Duration(5)*time.Second,
585-
)
586-
587+
sfset := statefulset.NewStatefulSet(stsSpec, time.Duration(5)*time.Second)
587588
ctrlResult, err = sfset.CreateOrPatch(ctx, helper)
588589
if err != nil {
589590
instance.Status.Conditions.Set(condition.FalseCondition(

pkg/ovndbcluster/statefulset.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func StatefulSet(
4343
labels map[string]string,
4444
annotations map[string]string,
4545
topology *topologyv1.Topology,
46-
) *appsv1.StatefulSet {
46+
) (*appsv1.StatefulSet, error) {
4747
livenessProbe := &corev1.Probe{
4848
// TODO might need tuning
4949
TimeoutSeconds: 5,
@@ -67,6 +67,11 @@ func StatefulSet(
6767
var preStopCmd []string
6868
cmd := []string{"/usr/bin/dumb-init"}
6969
args := []string{ServiceCommand}
70+
// Parse the storageRequest defined in the CR
71+
storageRequest, err := resource.ParseQuantity(instance.Spec.StorageRequest)
72+
if err != nil {
73+
return nil, err
74+
}
7075
//
7176
// https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
7277
//
@@ -204,7 +209,7 @@ func StatefulSet(
204209
StorageClassName: &instance.Spec.StorageClass,
205210
Resources: corev1.VolumeResourceRequirements{
206211
Requests: corev1.ResourceList{
207-
corev1.ResourceStorage: resource.MustParse(instance.Spec.StorageRequest),
212+
corev1.ResourceStorage: storageRequest,
208213
},
209214
},
210215
},
@@ -229,5 +234,5 @@ func StatefulSet(
229234
)
230235
}
231236

232-
return statefulset
237+
return statefulset, nil
233238
}

0 commit comments

Comments
 (0)