Skip to content

Commit 684eeb1

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 <fpantano@redhat.com>
1 parent 3fbafaa commit 684eeb1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

controllers/ironicconductor_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,12 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc
719719
}
720720

721721
// Define a new StatefulSet object
722+
ssSpec, err := ironicconductor.StatefulSet(instance, inputHash, serviceLabels, ingressDomain, serviceAnnotations, topology)
723+
if err != nil {
724+
return ctrl.Result{}, err
725+
}
722726
ss := statefulset.NewStatefulSet(
723-
ironicconductor.StatefulSet(instance, inputHash, serviceLabels, ingressDomain, serviceAnnotations, topology),
727+
ssSpec,
724728
time.Duration(5)*time.Second,
725729
)
726730

pkg/ironicconductor/statefulset.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func StatefulSet(
4747
ingressDomain string,
4848
annotations map[string]string,
4949
topology *topologyv1.Topology,
50-
) *appsv1.StatefulSet {
50+
) (*appsv1.StatefulSet, error) {
5151
runAsUser := int64(0)
5252

5353
livenessProbe := &corev1.Probe{
@@ -118,6 +118,11 @@ func StatefulSet(
118118
Port: intstr.IntOrString{Type: intstr.Int, IntVal: int32(8088)},
119119
}
120120

121+
// Parse the storageRequest defined in the CR
122+
storageRequest, err := resource.ParseQuantity(instance.Spec.StorageRequest)
123+
if err != nil {
124+
return nil, err
125+
}
121126
// dnsmasq only listen on ports 67 and/or 547 when DHCPRanges are configured.
122127
dnsmasqProbeCommand := []string{"sh", "-c", "ss -lun | grep :69"}
123128
ipv6Probe := false
@@ -298,7 +303,7 @@ func StatefulSet(
298303
},
299304
Resources: corev1.VolumeResourceRequirements{
300305
Requests: corev1.ResourceList{
301-
corev1.ResourceStorage: resource.MustParse(instance.Spec.StorageRequest),
306+
corev1.ResourceStorage: storageRequest,
302307
},
303308
},
304309
StorageClassName: &instance.Spec.StorageClass,
@@ -352,5 +357,5 @@ func StatefulSet(
352357
}
353358
statefulset.Spec.Template.Spec.InitContainers = ironic.InitContainer(initContainerDetails)
354359

355-
return statefulset
360+
return statefulset, nil
356361
}

0 commit comments

Comments
 (0)