Skip to content

Commit 143d9a9

Browse files
check that ProbeThreshold is valid
1 parent df66fa6 commit 143d9a9

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

api/pie/v1alpha1/pieprobe_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type PieProbeSpec struct {
2323
//+kubebuilder:validation:Minimum:=1
2424
ProbePeriod int `json:"probePeriod"`
2525

26-
ProbeThreshold string `json:"probeThreshold"`
26+
ProbeThreshold metav1.Duration `json:"probeThreshold"`
2727
}
2828

2929
// PieProbeStatus defines the observed state of PieProbe

api/pie/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/pie/pieprobe_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"context"
55
"crypto/sha1"
66
"encoding/hex"
7+
"errors"
78
"fmt"
89
"hash/crc32"
910
"io"
11+
"time"
1012

1113
piev1alpha1 "github.com/topolvm/pie/api/pie/v1alpha1"
1214
"github.com/topolvm/pie/constants"
@@ -68,6 +70,10 @@ func (r *PieProbeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
6870
return ctrl.Result{}, err
6971
}
7072

73+
if time.Duration(pieProbe.Spec.ProbePeriod)*time.Minute <= pieProbe.Spec.ProbeThreshold.Duration {
74+
return ctrl.Result{}, errors.New("probe period should be larger than probe threshold")
75+
}
76+
7177
var storageClassForGet storagev1.StorageClass
7278
err = r.client.Get(ctx, client.ObjectKey{Name: pieProbe.Spec.MonitoringStorageClass}, &storageClassForGet)
7379
if err != nil {

internal/controller/probe_pod_controller.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ func (r *ProbePodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
7777
}
7878
r.po.setPodPieProbeName(pod.Namespace, pod.Name, pieProbeName)
7979

80-
probeThreshold, err := time.ParseDuration(pieProbe.Spec.ProbeThreshold)
81-
if err != nil {
82-
return ctrl.Result{}, err
83-
}
80+
probeThreshold := pieProbe.Spec.ProbeThreshold.Duration
8481
r.po.setProbeThreshold(pod.Namespace, pod.Name, probeThreshold)
8582

8683
for _, status := range pod.Status.ContainerStatuses {

0 commit comments

Comments
 (0)