@@ -36,7 +36,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
3636 return nil
3737 }
3838
39- // add readiness gate when pod is created
39+ // Add readiness gate when pod is created
4040 if operation == admissionv1 .Create {
4141 addReadinessGates (newPod , v1alpha1 .ReadinessGatePodServiceReady )
4242 }
@@ -50,14 +50,14 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
5050 var operatingCount , operateCount , operatedCount , completeCount int
5151 var undoTypeToNumsMap = map [string ]int {}
5252 for id , labels := range newIDToLabelsMap {
53- if undoOperationType , ok := labels [v1alpha1 .PodUndoOperationTypeLabelPrefix ]; ok { // operation is canceled
53+ if undoOperationType , ok := labels [v1alpha1 .PodUndoOperationTypeLabelPrefix ]; ok { // Operation is canceled
5454 if _ , ok := undoTypeToNumsMap [undoOperationType ]; ! ok {
5555 undoTypeToNumsMap [undoOperationType ] = 1
5656 } else {
5757 undoTypeToNumsMap [undoOperationType ] = undoTypeToNumsMap [undoOperationType ] + 1
5858 }
5959
60- // clean up these labels with id
60+ // Clean up these labels with the ID
6161 for _ , v := range []string {v1alpha1 .PodOperatingLabelPrefix ,
6262 v1alpha1 .PodOperationTypeLabelPrefix ,
6363 v1alpha1 .PodPreCheckLabelPrefix ,
@@ -76,19 +76,18 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
7676 operatingCount ++
7777
7878 if _ , ok := labels [v1alpha1 .PodPreCheckedLabelPrefix ]; ok { // pre-checked
79- _ , hasPrepare := labels [v1alpha1 .PodPreparingLabelPrefix ]
80- _ , hasOperate := labels [v1alpha1 .PodOperateLabelPrefix ]
81-
82- if ! hasPrepare && ! hasOperate {
79+ _ , hasPreparing := labels [v1alpha1 .PodPreparingLabelPrefix ]
80+ if ! hasPreparing {
8381 delete (newPod .Labels , v1alpha1 .PodServiceAvailableLabel )
8482
85- lc .addLabelWithTime (newPod , fmt .Sprintf ("%s/%s" , v1alpha1 .PodPreparingLabelPrefix , id )) // prepare
86- } else if ! hasOperate {
87- if ready , _ := lc .readyToUpgrade (newPod ); ready {
88- delete (newPod .Labels , fmt .Sprintf ("%s/%s" , v1alpha1 .PodPreparingLabelPrefix , id ))
83+ lc .addLabelWithTime (newPod , fmt .Sprintf ("%s/%s" , v1alpha1 .PodPreparingLabelPrefix , id )) // preparing
84+ }
85+
86+ _ , hasOperate := labels [v1alpha1 .PodOperateLabelPrefix ]
87+ if ! hasOperate && lc .readyToOperate (newPod ) {
88+ delete (newPod .Labels , fmt .Sprintf ("%s/%s" , v1alpha1 .PodPreparingLabelPrefix , id ))
8989
90- lc .addLabelWithTime (newPod , fmt .Sprintf ("%s/%s" , v1alpha1 .PodOperateLabelPrefix , id )) // operate
91- }
90+ lc .addLabelWithTime (newPod , fmt .Sprintf ("%s/%s" , v1alpha1 .PodOperateLabelPrefix , id )) // operate
9291 }
9392 } else {
9493 if _ , ok := labels [v1alpha1 .PodPreCheckLabelPrefix ]; ! ok {
@@ -116,17 +115,17 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
116115 klog .Infof ("pod: %s/%s, numOfIDs: %d, operatingCount: %d, operateCount: %d, operatedCount: %d, completeCount: %d" , newPod .Namespace , newPod .Name , numOfIDs , operatingCount , operateCount , operatedCount , completeCount )
117116
118117 for t , num := range undoTypeToNumsMap {
119- if num == typeToNumsMap [t ] { // reset the permission with type t if all operating with type t are canceled
118+ if num == typeToNumsMap [t ] { // Reset the permission with type t if all operating with type t are canceled
120119 delete (newPod .Labels , fmt .Sprintf ("%s/%s" , v1alpha1 .PodOperationPermissionLabelPrefix , t ))
121120 }
122121 }
123122
124- if operatingCount != 0 { // when operation is done, controller will remove operating label and operation type label
123+ if operatingCount != 0 { // When operation is done, controller will remove operating label and operation type label
125124 return nil
126125 }
127126
128- if completeCount == numOfIDs { // all operations are completed
129- satisfied , notSatisfiedFinalizers , err := controllerutils .IsExpectedFinalizerSatisfied (newPod ) // whether all expected finalizers are satisfied
127+ if completeCount == numOfIDs { // All operations are completed
128+ satisfied , notSatisfiedFinalizers , err := controllerutils .IsExpectedFinalizerSatisfied (newPod ) // Whether all expected finalizers are satisfied
130129 if err != nil || ! satisfied {
131130 klog .Infof ("pod: %s/%s, satisfied: %v, expectedFinalizer: %v, err: %v" , newPod .Namespace , newPod .Name , satisfied , notSatisfiedFinalizers , err )
132131 return err
@@ -146,7 +145,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
146145 return nil
147146 }
148147
149- if operateCount == numOfIDs { // all operations are going to be done
148+ if operateCount == numOfIDs { // All operations are going to be done
150149 oldIdToLabelsMap , _ , err := podopslifecycle .PodIDAndTypesMap (oldPod )
151150 if err != nil {
152151 return err
@@ -172,7 +171,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
172171 }
173172 }
174173
175- if operatedCount == numOfIDs { // all operations are done
174+ if operatedCount == numOfIDs { // All operations are done
176175 for id , labels := range newIDToLabelsMap {
177176 if _ , ok := labels [v1alpha1 .PodPostCheckLabelPrefix ]; ! ok {
178177 lc .addLabelWithTime (newPod , fmt .Sprintf ("%s/%s" , v1alpha1 .PodPostCheckLabelPrefix , id )) // post-check
0 commit comments