Skip to content

Commit

Permalink
remove writing out lastCheckedAt status
Browse files Browse the repository at this point in the history
Signed-off-by: craig <[email protected]>

rh-pre-commit.version: 2.2.0
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
maleck13 committed Nov 8, 2024
1 parent d59e618 commit db6233f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/dnshealthcheckprobe_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type AdditionalHeader struct {

// DNSHealthCheckProbeStatus defines the observed state of DNSHealthCheckProbe
type DNSHealthCheckProbeStatus struct {
LastCheckedAt metav1.Time `json:"lastCheckedAt"`
LastCheckedAt metav1.Time `json:"-"`
ConsecutiveFailures int `json:"consecutiveFailures,omitempty"`
Reason string `json:"reason,omitempty"`
Status int `json:"status,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion bundle/manifests/dns-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ metadata:
capabilities: Basic Install
categories: Integration & Delivery
containerImage: quay.io/kuadrant/dns-operator:latest
createdAt: "2024-10-18T15:21:24Z"
createdAt: "2024-11-07T15:15:46Z"
description: A Kubernetes Operator to manage the lifecycle of DNS resources
operators.operatorframework.io/builder: operator-sdk-v1.33.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v4
Expand Down
4 changes: 0 additions & 4 deletions bundle/manifests/kuadrant.io_dnshealthcheckprobes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ spec:
type: integer
healthy:
type: boolean
lastCheckedAt:
format: date-time
type: string
observedGeneration:
format: int64
type: integer
Expand All @@ -124,7 +121,6 @@ spec:
type: integer
required:
- healthy
- lastCheckedAt
type: object
type: object
served: true
Expand Down
4 changes: 0 additions & 4 deletions charts/dns-operator/templates/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ spec:
type: integer
healthy:
type: boolean
lastCheckedAt:
format: date-time
type: string
observedGeneration:
format: int64
type: integer
Expand All @@ -125,7 +122,6 @@ spec:
type: integer
required:
- healthy
- lastCheckedAt
type: object
type: object
served: true
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/kuadrant.io_dnshealthcheckprobes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ spec:
type: integer
healthy:
type: boolean
lastCheckedAt:
format: date-time
type: string
observedGeneration:
format: int64
type: integer
Expand All @@ -124,7 +121,6 @@ spec:
type: integer
required:
- healthy
- lastCheckedAt
type: object
type: object
served: true
Expand Down
14 changes: 10 additions & 4 deletions internal/probes/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ const (
)

type ProbeResult struct {
// CheckedAt the current helath check time
CheckedAt metav1.Time
Healthy bool
Reason string
Status int
// PreviousCheck the time it was checked before the current check
PreviousCheck metav1.Time
Healthy bool
Reason string
Status int
}

type RoundTripperFunc func(*http.Request) (*http.Response, error)
Expand Down Expand Up @@ -74,7 +77,10 @@ func (w *Probe) ExecuteProbe(ctx context.Context, probe *v1alpha1.DNSHealthCheck
case <-timer.C:
logger.V(2).Info("health probe worker: executing")
result := w.execute(ctx, localProbe)
// set the previous check time from the exsting probe
result.PreviousCheck = localProbe.Status.LastCheckedAt
// as this routine is just executing the local config it only cares about when it should execute again
// set the lastCheck based on the result
localProbe.Status.LastCheckedAt = result.CheckedAt
sig <- result
}
Expand Down Expand Up @@ -246,11 +252,11 @@ func (w *Probe) Start(clientctx context.Context, k8sClient client.Client, probe
} else {
freshProbe.Status.ConsecutiveFailures = 0
}
logger.V(1).Info("health: execution complete ", "result", probeResult, "checked at", probeResult.CheckedAt.String(), "previoud check at ", probeResult.PreviousCheck)
freshProbe.Status.Healthy = &probeResult.Healthy
freshProbe.Status.LastCheckedAt = probeResult.CheckedAt
freshProbe.Status.Reason = probeResult.Reason
freshProbe.Status.Status = probeResult.Status
logger.V(1).Info("health: execution complete ", "result", probeResult)

logger.V(2).Info("health: probe finished updating status for probe", "status", freshProbe)
err := k8sClient.Status().Update(clientctx, freshProbe)
Expand Down
6 changes: 6 additions & 0 deletions internal/probes/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func TestWorker_ProbeSuccess(t *testing.T) {
if lastResult.Healthy == false {
t.Fatalf("expected the result of the probe to be healthy but it was not")
}
if !lastResult.CheckedAt.After(results[len(results)-2].CheckedAt.Time) {
t.Fatalf("result checked at should be after the previous result checkAt ")
}
if !lastResult.CheckedAt.After(lastResult.PreviousCheck.Time) {
t.Fatalf("result checked at should be after the previousCheck")
}
if lastResult.Status != 200 {
t.Fatalf("expected the result status to be 200 but got %v", lastResult.Status)
}
Expand Down

0 comments on commit db6233f

Please sign in to comment.