@@ -125,6 +125,8 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
125
125
if err != nil {
126
126
return reconcile.Result {}, err
127
127
}
128
+
129
+ // If all lifecycle is finished, or the is no lifecycle begined
128
130
if len (idToLabelsMap ) == 0 {
129
131
updated , err := r .addServiceAvailable (pod )
130
132
if updated {
@@ -139,6 +141,7 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
139
141
}
140
142
}
141
143
144
+ // Get the state of pod managed by TransitionRule
142
145
state , err := r .podTransitionRuleManager .GetState (ctx , r .Client , pod )
143
146
if err != nil {
144
147
logger .Error (err , "failed to get pod state" )
@@ -164,8 +167,8 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
164
167
}
165
168
166
169
expected := map [string ]bool {
167
- v1alpha1 .PodPreparingLabelPrefix : false , // set readiness gate to false, traffic off
168
- v1alpha1 .PodCompletingLabelPrefix : true , // set readiness gate to true, traffic on
170
+ v1alpha1 .PodPreparingLabelPrefix : false , // Set readiness gate to false
171
+ v1alpha1 .PodCompletingLabelPrefix : true , // Set readiness gate to true
169
172
}
170
173
for _ , labels := range idToLabelsMap {
171
174
for k , v := range expected {
@@ -175,7 +178,7 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
175
178
176
179
updated , err := r .updateServiceReadiness (ctx , pod , v )
177
180
if err != nil {
178
- return reconcile.Result {}, err // only need set once
181
+ return reconcile.Result {}, err // Only need set once
179
182
}
180
183
if updated {
181
184
r .Recorder .Eventf (pod , corev1 .EventTypeNormal , "ReadinessGate" , "Set service ready readiness gate to %v" , v )
@@ -186,6 +189,7 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
186
189
return reconcile.Result {}, nil
187
190
}
188
191
192
+ // addServiceAvailable try to add service available label to pod
189
193
func (r * ReconcilePodOpsLifecycle ) addServiceAvailable (pod * corev1.Pod ) (bool , error ) {
190
194
if pod .Labels == nil {
191
195
return false , nil
@@ -194,7 +198,8 @@ func (r *ReconcilePodOpsLifecycle) addServiceAvailable(pod *corev1.Pod) (bool, e
194
198
return false , nil
195
199
}
196
200
197
- satisfied , notSatisfiedFinalizers , err := controllerutils .IsExpectedFinalizerSatisfied (pod ) // whether all expected finalizers are satisfied
201
+ // Whether all expected finalizers are satisfied
202
+ satisfied , notSatisfiedFinalizers , err := controllerutils .IsExpectedFinalizerSatisfied (pod )
198
203
if err != nil {
199
204
return false , err
200
205
}
@@ -207,7 +212,7 @@ func (r *ReconcilePodOpsLifecycle) addServiceAvailable(pod *corev1.Pod) (bool, e
207
212
if ! allDirty {
208
213
return false , nil
209
214
}
210
- // all not satisfied expected finalizers are dirty, so actually the pod satisfied expected finalizer now
215
+ // All not satisfied finalizers are dirty, so actually the pod satisfied expected finalizers now
211
216
}
212
217
213
218
if ! controllerutils .IsPodReady (pod ) {
@@ -221,7 +226,7 @@ func (r *ReconcilePodOpsLifecycle) addServiceAvailable(pod *corev1.Pod) (bool, e
221
226
}
222
227
223
228
func (r * ReconcilePodOpsLifecycle ) removeDirtyExpectedFinalizer (pod * corev1.Pod , notSatisfiedFinalizers map [string ]string ) (bool , error ) {
224
- var allDirty bool
229
+ var allDirty bool // Whether all not atisfied finalizers are dirty
225
230
dirtyExpectedFinalizer := make (map [string ]string )
226
231
227
232
for expectedFlzKey , finalizer := range notSatisfiedFinalizers {
@@ -348,7 +353,7 @@ func (r *ReconcilePodOpsLifecycle) setServiceReadiness(pod *corev1.Pod, isReady
348
353
if ! isReady {
349
354
status = corev1 .ConditionFalse
350
355
}
351
- if index == - 1 { // append readiness gate
356
+ if index == - 1 { // Append readiness gate
352
357
pod .Status .Conditions = append (pod .Status .Conditions , corev1.PodCondition {
353
358
Type : v1alpha1 .ReadinessGatePodServiceReady ,
354
359
Status : status ,
@@ -362,7 +367,7 @@ func (r *ReconcilePodOpsLifecycle) setServiceReadiness(pod *corev1.Pod, isReady
362
367
return false , ""
363
368
}
364
369
365
- // update readiness gate
370
+ // Update readiness gate
366
371
pod .Status .Conditions [index ].Status = status
367
372
pod .Status .Conditions [index ].LastTransitionTime = metav1 .Now ()
368
373
pod .Status .Conditions [index ].Message = "updated by PodOpsLifecycle"
0 commit comments