Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove writing out lastCheckedAt status #300

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this value any more? I thought that the only that matters is LastCheckedAt in the localProbe 🤔

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should not write LastCheckedAt to the probe CR anymore

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
Loading