@@ -114,8 +114,8 @@ func getOrUpdateOperationCondition(currentCond *OperationCondition, conditionTyp
114114 return & newCond , true
115115}
116116
117- // getLastEntityCondition returns the condition with the specific type form status.conditions
118- func getLastEntityCondition (status OperationStatus , condType OperationConditionType ) * OperationCondition {
117+ // getLastEntityCondition returns the latest status condition.
118+ func getLastEntityCondition (status OperationStatus ) * OperationCondition {
119119 if len (status .Conditions ) > 0 {
120120 return & status .Conditions [len (status .Conditions )- 1 ]
121121 }
@@ -193,7 +193,7 @@ func IsOperationBeingDeleted[T metav1.Object](obj T) bool {
193193
194194// removeCondition removes a condition of the specified type from the status
195195func removeCondition (status * OperationStatus , conditionType OperationConditionType ) {
196- var newConditions []OperationCondition
196+ newConditions := make ( []OperationCondition , 0 , len ( status . Conditions ))
197197 for _ , c := range status .Conditions {
198198 if c .Type == conditionType {
199199 continue
@@ -204,9 +204,9 @@ func removeCondition(status *OperationStatus, conditionType OperationConditionTy
204204}
205205
206206// logCondition logs a condition to the status
207- func logCondition (status * OperationStatus , condType OperationConditionType , conditionStatus corev1. ConditionStatus , reason , message string ) bool {
208- currentCond := getLastEntityCondition (* status , condType )
209- cond , isUpdated := getOrUpdateOperationCondition (currentCond , condType , conditionStatus , reason , message )
207+ func logCondition (status * OperationStatus , condType OperationConditionType , reason , message string ) bool {
208+ currentCond := getLastEntityCondition (* status )
209+ cond , isUpdated := getOrUpdateOperationCondition (currentCond , condType , corev1 . ConditionTrue , reason , message )
210210 if isUpdated && cond != nil {
211211 removeCondition (status , condType )
212212 status .Conditions = append (status .Conditions , * cond )
@@ -217,12 +217,12 @@ func logCondition(status *OperationStatus, condType OperationConditionType, cond
217217
218218// LogStarting sets Operation to starting
219219func (status * OperationStatus ) LogStarting () bool {
220- return logCondition (status , OperationStarting , corev1 . ConditionTrue , "OperatorController" , "Operation is starting" )
220+ return logCondition (status , OperationStarting , "OperatorController" , "Operation is starting" )
221221}
222222
223223// LogRunning sets Operation to running
224224func (status * OperationStatus ) LogRunning () bool {
225- return logCondition (status , OperationRunning , corev1 . ConditionTrue , "OperatorController" , "Operation is running" )
225+ return logCondition (status , OperationRunning , "OperatorController" , "Operation is running" )
226226}
227227
228228// LogWarning sets Operation to succeeded
@@ -233,22 +233,22 @@ func (status *OperationStatus) LogWarning(reason, message string) bool {
233233 if message == "" {
234234 message = "Underlaying job has an issue"
235235 }
236- return logCondition (status , OperationWarning , corev1 . ConditionTrue , reason , message )
236+ return logCondition (status , OperationWarning , reason , message )
237237}
238238
239239// LogSucceeded sets Operation to succeeded
240240func (status * OperationStatus ) LogSucceeded () bool {
241- return logCondition (status , OperationSucceeded , corev1 . ConditionTrue , "OperatorController" , "Operation has succeeded" )
241+ return logCondition (status , OperationSucceeded , "OperatorController" , "Operation has succeeded" )
242242}
243243
244244// LogFailed sets Operation to failed
245245func (status * OperationStatus ) LogFailed (reason , message string ) bool {
246- return logCondition (status , OperationFailed , corev1 . ConditionTrue , reason , message )
246+ return logCondition (status , OperationFailed , reason , message )
247247}
248248
249249// LogStopped sets Operation to stopped
250250func (status * OperationStatus ) LogStopped (reason , message string ) bool {
251- return logCondition (status , OperationStopped , corev1 . ConditionTrue , reason , message )
251+ return logCondition (status , OperationStopped , reason , message )
252252}
253253
254254// ShouldMarkJobAsDeleted checks if a job that doesn't exist should be marked as deleted
0 commit comments