Skip to content

Commit

Permalink
check that ProbeThreshold is valid
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
  • Loading branch information
ushitora-anqou committed Jun 6, 2024
1 parent 3f8c347 commit 84f2ae2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/pie/v1alpha1/pieprobe_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type PieProbeSpec struct {
//+kubebuilder:validation:Minimum:=1
ProbePeriod int `json:"probePeriod"`

ProbeThreshold string `json:"probeThreshold"`
ProbeThreshold metav1.Duration `json:"probeThreshold"`
}

// PieProbeStatus defines the observed state of PieProbe
Expand Down
1 change: 1 addition & 0 deletions api/pie/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions internal/controller/pie/pieprobe_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"crypto/sha1"
"encoding/hex"
"errors"
"fmt"
"hash/crc32"
"io"
"time"

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

if time.Duration(pieProbe.Spec.ProbePeriod)*time.Minute <= pieProbe.Spec.ProbeThreshold.Duration {
return ctrl.Result{}, errors.New("probe period should be larger than probe threshold")
}

var storageClassForGet storagev1.StorageClass
err = r.client.Get(ctx, client.ObjectKey{Name: pieProbe.Spec.MonitoringStorageClass}, &storageClassForGet)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions internal/controller/probe_pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func (r *ProbePodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}
r.po.setPodPieProbeName(pod.Namespace, pod.Name, pieProbeName)

probeThreshold, err := time.ParseDuration(pieProbe.Spec.ProbeThreshold)
if err != nil {
return ctrl.Result{}, err
}
probeThreshold := pieProbe.Spec.ProbeThreshold.Duration
r.po.setProbeThreshold(pod.Namespace, pod.Name, probeThreshold)

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

0 comments on commit 84f2ae2

Please sign in to comment.