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

KUBESAW-43: Introduce LastUpdatedTime as prefered one #398

Merged
merged 4 commits into from
May 13, 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
4 changes: 4 additions & 0 deletions controllers/toolchaincluster/healthchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func clusterReadyCondition() toolchainv1alpha1.ToolchainClusterCondition {
Reason: toolchainv1alpha1.ToolchainClusterClusterReadyReason,
Message: healthzOk,
LastProbeTime: currentTime,
LastUpdatedTime: &currentTime,
LastTransitionTime: &currentTime,
}
}
Expand All @@ -84,6 +85,7 @@ func clusterNotReadyCondition() toolchainv1alpha1.ToolchainClusterCondition {
Reason: toolchainv1alpha1.ToolchainClusterClusterNotReadyReason,
Message: healthzNotOk,
LastProbeTime: currentTime,
LastUpdatedTime: &currentTime,
LastTransitionTime: &currentTime,
}
}
Expand All @@ -96,6 +98,7 @@ func clusterOfflineCondition() toolchainv1alpha1.ToolchainClusterCondition {
Reason: toolchainv1alpha1.ToolchainClusterClusterNotReachableReason,
Message: clusterNotReachableMsg,
LastProbeTime: currentTime,
LastUpdatedTime: &currentTime,
LastTransitionTime: &currentTime,
}
}
Expand All @@ -108,6 +111,7 @@ func clusterNotOfflineCondition() toolchainv1alpha1.ToolchainClusterCondition {
Reason: toolchainv1alpha1.ToolchainClusterClusterReachableReason,
Message: clusterReachableMsg,
LastProbeTime: currentTime,
LastUpdatedTime: &currentTime,
LastTransitionTime: &currentTime,
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 7 additions & 1 deletion pkg/status/toolchaincluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +51 to +54
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add/update the unit tests so it verifies that it give the LastUpdatedTime preference and if not set then it takes the LastProbeTime?
I mean, let's verify that it works when either from these two fields are not set. If I'm not mistaken, the current unit tests sets both fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added it

}()
foundLastProbeTime = true
}

}
if !foundLastProbeTime {
lastProbeNotFoundMsg := "the time of the last probe could not be determined"
Expand Down
27 changes: 15 additions & 12 deletions pkg/status/toolchaincluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
}},
},
}
Expand Down
Loading