From db6233fd3b93de501a3eb05617b020d9054e69c6 Mon Sep 17 00:00:00 2001 From: craig Date: Thu, 7 Nov 2024 15:16:43 +0000 Subject: [PATCH] remove writing out lastCheckedAt status Signed-off-by: craig rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED --- api/v1alpha1/dnshealthcheckprobe_types.go | 2 +- .../dns-operator.clusterserviceversion.yaml | 2 +- .../kuadrant.io_dnshealthcheckprobes.yaml | 4 ---- charts/dns-operator/templates/manifests.yaml | 4 ---- .../bases/kuadrant.io_dnshealthcheckprobes.yaml | 4 ---- internal/probes/worker.go | 14 ++++++++++---- internal/probes/worker_test.go | 6 ++++++ 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/api/v1alpha1/dnshealthcheckprobe_types.go b/api/v1alpha1/dnshealthcheckprobe_types.go index 971441a..e1ce752 100644 --- a/api/v1alpha1/dnshealthcheckprobe_types.go +++ b/api/v1alpha1/dnshealthcheckprobe_types.go @@ -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"` diff --git a/bundle/manifests/dns-operator.clusterserviceversion.yaml b/bundle/manifests/dns-operator.clusterserviceversion.yaml index 362e24d..cb36b11 100644 --- a/bundle/manifests/dns-operator.clusterserviceversion.yaml +++ b/bundle/manifests/dns-operator.clusterserviceversion.yaml @@ -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 diff --git a/bundle/manifests/kuadrant.io_dnshealthcheckprobes.yaml b/bundle/manifests/kuadrant.io_dnshealthcheckprobes.yaml index d876137..4f77c9c 100644 --- a/bundle/manifests/kuadrant.io_dnshealthcheckprobes.yaml +++ b/bundle/manifests/kuadrant.io_dnshealthcheckprobes.yaml @@ -112,9 +112,6 @@ spec: type: integer healthy: type: boolean - lastCheckedAt: - format: date-time - type: string observedGeneration: format: int64 type: integer @@ -124,7 +121,6 @@ spec: type: integer required: - healthy - - lastCheckedAt type: object type: object served: true diff --git a/charts/dns-operator/templates/manifests.yaml b/charts/dns-operator/templates/manifests.yaml index 89cce51..49d6771 100644 --- a/charts/dns-operator/templates/manifests.yaml +++ b/charts/dns-operator/templates/manifests.yaml @@ -113,9 +113,6 @@ spec: type: integer healthy: type: boolean - lastCheckedAt: - format: date-time - type: string observedGeneration: format: int64 type: integer @@ -125,7 +122,6 @@ spec: type: integer required: - healthy - - lastCheckedAt type: object type: object served: true diff --git a/config/crd/bases/kuadrant.io_dnshealthcheckprobes.yaml b/config/crd/bases/kuadrant.io_dnshealthcheckprobes.yaml index 49b88f9..16dca83 100644 --- a/config/crd/bases/kuadrant.io_dnshealthcheckprobes.yaml +++ b/config/crd/bases/kuadrant.io_dnshealthcheckprobes.yaml @@ -112,9 +112,6 @@ spec: type: integer healthy: type: boolean - lastCheckedAt: - format: date-time - type: string observedGeneration: format: int64 type: integer @@ -124,7 +121,6 @@ spec: type: integer required: - healthy - - lastCheckedAt type: object type: object served: true diff --git a/internal/probes/worker.go b/internal/probes/worker.go index 474de8f..c38f23e 100644 --- a/internal/probes/worker.go +++ b/internal/probes/worker.go @@ -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) @@ -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 } @@ -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) diff --git a/internal/probes/worker_test.go b/internal/probes/worker_test.go index a577569..0bf33d0 100644 --- a/internal/probes/worker_test.go +++ b/internal/probes/worker_test.go @@ -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) }