Skip to content

Commit 8316373

Browse files
committed
bugfix
1 parent 697e3a8 commit 8316373

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

internal/generated/controller/flexcluster/handler_v20250312_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,18 +1114,20 @@ func withGeneration(flexCluster *akov2generated.FlexCluster, generation int64) *
11141114
// withObservedGeneration sets the observed generation in status conditions
11151115
func withObservedGeneration(flexCluster *akov2generated.FlexCluster, observedGen int64) *akov2generated.FlexCluster {
11161116
if flexCluster.Status.Conditions == nil {
1117-
flexCluster.Status.Conditions = &[]metav1.Condition{}
1117+
// Allocate a new empty slice pointer to avoid storing a pointer to a temporary value
1118+
flexCluster.Status.Conditions = new([]metav1.Condition)
11181119
}
11191120
conditions := *flexCluster.Status.Conditions
11201121
conditions = append(conditions, metav1.Condition{
11211122
Type: state.StateCondition,
11221123
ObservedGeneration: observedGen,
11231124
Status: metav1.ConditionTrue,
11241125
})
1125-
// Allocate a new slice to avoid storing a pointer to a local variable
1126+
// Allocate a new slice pointer that persists beyond function scope
11261127
newConditions := make([]metav1.Condition, len(conditions))
11271128
copy(newConditions, conditions)
1128-
flexCluster.Status.Conditions = &newConditions
1129+
flexCluster.Status.Conditions = new([]metav1.Condition)
1130+
*flexCluster.Status.Conditions = newConditions
11291131
return flexCluster
11301132
}
11311133

0 commit comments

Comments
 (0)