diff --git a/controllers/toolchaincluster/healthchecker.go b/controllers/toolchaincluster/healthchecker.go index 01d2ead9..a2bab13b 100644 --- a/controllers/toolchaincluster/healthchecker.go +++ b/controllers/toolchaincluster/healthchecker.go @@ -72,6 +72,7 @@ func clusterReadyCondition() toolchainv1alpha1.ToolchainClusterCondition { Reason: toolchainv1alpha1.ToolchainClusterClusterReadyReason, Message: healthzOk, LastProbeTime: currentTime, + LastUpdatedTime: ¤tTime, LastTransitionTime: ¤tTime, } } @@ -84,6 +85,7 @@ func clusterNotReadyCondition() toolchainv1alpha1.ToolchainClusterCondition { Reason: toolchainv1alpha1.ToolchainClusterClusterNotReadyReason, Message: healthzNotOk, LastProbeTime: currentTime, + LastUpdatedTime: ¤tTime, LastTransitionTime: ¤tTime, } } @@ -96,6 +98,7 @@ func clusterOfflineCondition() toolchainv1alpha1.ToolchainClusterCondition { Reason: toolchainv1alpha1.ToolchainClusterClusterNotReachableReason, Message: clusterNotReachableMsg, LastProbeTime: currentTime, + LastUpdatedTime: ¤tTime, LastTransitionTime: ¤tTime, } } @@ -108,6 +111,7 @@ func clusterNotOfflineCondition() toolchainv1alpha1.ToolchainClusterCondition { Reason: toolchainv1alpha1.ToolchainClusterClusterReachableReason, Message: clusterReachableMsg, LastProbeTime: currentTime, + LastUpdatedTime: ¤tTime, LastTransitionTime: ¤tTime, } } diff --git a/go.mod b/go.mod index d734acf7..865c995c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/codeready-toolchain/toolchain-common go 1.20 require ( - github.com/codeready-toolchain/api v0.0.0-20240425165440-d0a6da0060a5 + github.com/codeready-toolchain/api v0.0.0-20240502171347-8db815b922bd github.com/go-logr/logr v1.2.3 github.com/golang-jwt/jwt/v5 v5.2.0 github.com/lestrrat-go/jwx v1.2.29 diff --git a/go.sum b/go.sum index 29a437ac..c3bc4148 100644 --- a/go.sum +++ b/go.sum @@ -115,8 +115,8 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo= github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA= github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI= -github.com/codeready-toolchain/api v0.0.0-20240425165440-d0a6da0060a5 h1:L6NhQrzGY6vWIBjXYfmJ/Q+k/4Sb+iQYKVjtR6LT2Q4= -github.com/codeready-toolchain/api v0.0.0-20240425165440-d0a6da0060a5/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E= +github.com/codeready-toolchain/api v0.0.0-20240502171347-8db815b922bd h1:znIdWMiUgIJ/ypSQ17NemR+29V688DUjH6xrG3eBEMo= +github.com/codeready-toolchain/api v0.0.0-20240502171347-8db815b922bd/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= diff --git a/pkg/status/toolchaincluster.go b/pkg/status/toolchaincluster.go index be4d3ac7..d6c57cbb 100644 --- a/pkg/status/toolchaincluster.go +++ b/pkg/status/toolchaincluster.go @@ -47,9 +47,15 @@ func GetToolchainClusterConditions(logger logr.Logger, attrs ToolchainClusterAtt foundLastProbeTime := false for _, condition := range toolchainCluster.ClusterStatus.Conditions { if condition.Type == toolchainv1alpha1.ToolchainClusterReady { - lastProbeTime = condition.LastProbeTime + lastProbeTime = func() metav1.Time { + if condition.LastUpdatedTime != nil { + return *condition.LastUpdatedTime + } + return condition.LastProbeTime + }() foundLastProbeTime = true } + } if !foundLastProbeTime { lastProbeNotFoundMsg := "the time of the last probe could not be determined" diff --git a/pkg/status/toolchaincluster_test.go b/pkg/status/toolchaincluster_test.go index 8811066c..23efcb97 100644 --- a/pkg/status/toolchaincluster_test.go +++ b/pkg/status/toolchaincluster_test.go @@ -18,7 +18,9 @@ import ( var fakeToolchainClusterReason = "AToolchainClusterReason" var fakeToolchainClusterMsg = "AToolchainClusterMsg" - +var probtime = metav1.Now() +var probtime1 = metav1.NewTime(metav1.Now().Add(time.Duration(-10) * time.Minute)) +var updatetime = metav1.NewTime(metav1.Now().Add(time.Duration(-3) * time.Second)) var log = logf.Log.WithName("toolchaincluster_test") func TestGetToolchainClusterConditions(t *testing.T) { @@ -170,34 +172,34 @@ func TestGetToolchainClusterConditions(t *testing.T) { assert.Contains(t, err.Error(), msg) test.AssertConditionsMatchAndRecentTimestamps(t, conditions, expected) }) + }) } func newGetHostClusterReady() cluster.GetHostClusterFunc { - return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue, metav1.Now(), fakeToolchainClusterReason, "") + return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue, probtime1, fakeToolchainClusterReason, "", &updatetime) } func newGetHostClusterNotOk() cluster.GetHostClusterFunc { - return NewFakeGetHostCluster(false, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse, metav1.Now(), fakeToolchainClusterReason, fakeToolchainClusterMsg) + return NewFakeGetHostCluster(false, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse, probtime, fakeToolchainClusterReason, fakeToolchainClusterMsg, nil) } func newGetHostClusterOkButNotReady(message string) cluster.GetHostClusterFunc { - return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse, metav1.Now(), fakeToolchainClusterReason, message) + return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionFalse, probtime, fakeToolchainClusterReason, message, nil) } func newGetHostClusterOkWithClusterOfflineCondition() cluster.GetHostClusterFunc { - return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterOffline, corev1.ConditionFalse, metav1.Now(), fakeToolchainClusterReason, fakeToolchainClusterMsg) + return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterOffline, corev1.ConditionFalse, probtime, fakeToolchainClusterReason, fakeToolchainClusterMsg, nil) } func newGetHostClusterLastProbeTimeExceeded() cluster.GetHostClusterFunc { - tenMinsAgo := metav1.Now().Add(time.Duration(-10) * time.Minute) - return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue, metav1.NewTime(tenMinsAgo), fakeToolchainClusterReason, fakeToolchainClusterMsg) + return NewFakeGetHostCluster(true, toolchainv1alpha1.ToolchainClusterReady, corev1.ConditionTrue, probtime1, fakeToolchainClusterReason, fakeToolchainClusterMsg, nil) } // NewGetHostCluster returns cluster.GetHostClusterFunc function. The cluster.CachedToolchainCluster // that is returned by the function then contains the given client and the given status and lastProbeTime. // If ok == false, then the function returns nil for the cluster. -func NewFakeGetHostCluster(ok bool, conditionType toolchainv1alpha1.ToolchainClusterConditionType, status corev1.ConditionStatus, lastProbeTime metav1.Time, reason, message string) cluster.GetHostClusterFunc { +func NewFakeGetHostCluster(ok bool, conditionType toolchainv1alpha1.ToolchainClusterConditionType, status corev1.ConditionStatus, lastProbeTime metav1.Time, reason, message string, lastUpdatedTime *metav1.Time) cluster.GetHostClusterFunc { if !ok { return func() (*cluster.CachedToolchainCluster, bool) { return nil, false @@ -211,10 +213,11 @@ func NewFakeGetHostCluster(ok bool, conditionType toolchainv1alpha1.ToolchainClu }, ClusterStatus: &toolchainv1alpha1.ToolchainClusterStatus{ Conditions: []toolchainv1alpha1.ToolchainClusterCondition{{ - Type: conditionType, - Reason: reason, - Status: status, - LastProbeTime: lastProbeTime, + Type: conditionType, + Reason: reason, + Status: status, + LastProbeTime: lastProbeTime, + LastUpdatedTime: lastUpdatedTime, }}, }, }