Skip to content

Commit c677bf1

Browse files
committed
chore: move condition change function to its own file
1 parent b70987f commit c677bf1

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

janitor/pkg/controller/backoff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func getNextRequeueDelay(consecutiveFailures int32) time.Duration {
3131
5 * time.Minute, // Fourth+ retry (capped)
3232
}
3333

34-
// Safely convert int32 to int for array indexing
34+
// Convert int32 to int for array indexing and cap at maximum if needed
3535
idx := int(consecutiveFailures)
3636
if idx >= len(delays) {
3737
return delays[len(delays)-1] // Cap at maximum

janitor/pkg/controller/rebootnode_controller.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,6 @@ const (
4747
MaxRebootRetries = 20 // 10 minutes at 30s base intervals
4848
)
4949

50-
// conditionsChanged compares two sets of conditions and returns true if they differ.
51-
// It checks the type, status, reason, and message of each condition.
52-
func conditionsChanged(original, updated []metav1.Condition) bool {
53-
if len(original) != len(updated) {
54-
return true
55-
}
56-
57-
// Build a map of original conditions for quick lookup
58-
originalMap := make(map[string]metav1.Condition)
59-
for _, cond := range original {
60-
originalMap[cond.Type] = cond
61-
}
62-
63-
// Check each updated condition against the original
64-
for _, updatedCond := range updated {
65-
originalCond, exists := originalMap[updatedCond.Type]
66-
if !exists {
67-
return true // New condition type added
68-
}
69-
70-
// Compare the fields that matter for status updates
71-
if originalCond.Status != updatedCond.Status ||
72-
originalCond.Reason != updatedCond.Reason ||
73-
originalCond.Message != updatedCond.Message {
74-
return true
75-
}
76-
}
77-
78-
return false
79-
}
80-
8150
// updateRebootNodeStatus is a helper function that handles status updates with proper error handling.
8251
// It delegates to the generic updateNodeActionStatus function.
8352
func (r *RebootNodeReconciler) updateRebootNodeStatus(

janitor/pkg/controller/status_update.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,37 @@ type NodeActionSpec interface {
4646
GetNodeName() string
4747
}
4848

49+
// conditionsChanged compares two slices of conditions and returns true if they differ.
50+
// It checks for differences in Type, Status, Reason, and Message fields.
51+
func conditionsChanged(original, updated []metav1.Condition) bool {
52+
if len(original) != len(updated) {
53+
return true
54+
}
55+
56+
// Build a map of original conditions for quick lookup
57+
originalMap := make(map[string]metav1.Condition)
58+
for _, cond := range original {
59+
originalMap[cond.Type] = cond
60+
}
61+
62+
// Check each updated condition against the original
63+
for _, updatedCond := range updated {
64+
originalCond, exists := originalMap[updatedCond.Type]
65+
if !exists {
66+
return true // New condition type added
67+
}
68+
69+
// Compare the fields that matter for status updates
70+
if originalCond.Status != updatedCond.Status ||
71+
originalCond.Reason != updatedCond.Reason ||
72+
originalCond.Message != updatedCond.Message {
73+
return true
74+
}
75+
}
76+
77+
return false
78+
}
79+
4980
// updateNodeActionStatus is a generic helper function that handles status updates with proper error handling.
5081
// It centralizes the status update logic to avoid code duplication and provides consistent handling
5182
// of status updates across different node action types (RebootNode, TerminateNode, etc.).

0 commit comments

Comments
 (0)