@@ -36,7 +36,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
36
36
return nil
37
37
}
38
38
39
- // add readiness gate when pod is created
39
+ // Add readiness gate when pod is created
40
40
if operation == admissionv1 .Create {
41
41
addReadinessGates (newPod , v1alpha1 .ReadinessGatePodServiceReady )
42
42
}
@@ -50,14 +50,14 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
50
50
var operatingCount , operateCount , operatedCount , completeCount int
51
51
var undoTypeToNumsMap = map [string ]int {}
52
52
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
54
54
if _ , ok := undoTypeToNumsMap [undoOperationType ]; ! ok {
55
55
undoTypeToNumsMap [undoOperationType ] = 1
56
56
} else {
57
57
undoTypeToNumsMap [undoOperationType ] = undoTypeToNumsMap [undoOperationType ] + 1
58
58
}
59
59
60
- // clean up these labels with id
60
+ // Clean up these labels with the ID
61
61
for _ , v := range []string {v1alpha1 .PodOperatingLabelPrefix ,
62
62
v1alpha1 .PodOperationTypeLabelPrefix ,
63
63
v1alpha1 .PodPreCheckLabelPrefix ,
@@ -76,19 +76,18 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
76
76
operatingCount ++
77
77
78
78
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 {
83
81
delete (newPod .Labels , v1alpha1 .PodServiceAvailableLabel )
84
82
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 ))
89
89
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
92
91
}
93
92
} else {
94
93
if _ , ok := labels [v1alpha1 .PodPreCheckLabelPrefix ]; ! ok {
@@ -116,17 +115,17 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
116
115
klog .Infof ("pod: %s/%s, numOfIDs: %d, operatingCount: %d, operateCount: %d, operatedCount: %d, completeCount: %d" , newPod .Namespace , newPod .Name , numOfIDs , operatingCount , operateCount , operatedCount , completeCount )
117
116
118
117
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
120
119
delete (newPod .Labels , fmt .Sprintf ("%s/%s" , v1alpha1 .PodOperationPermissionLabelPrefix , t ))
121
120
}
122
121
}
123
122
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
125
124
return nil
126
125
}
127
126
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
130
129
if err != nil || ! satisfied {
131
130
klog .Infof ("pod: %s/%s, satisfied: %v, expectedFinalizer: %v, err: %v" , newPod .Namespace , newPod .Name , satisfied , notSatisfiedFinalizers , err )
132
131
return err
@@ -146,7 +145,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
146
145
return nil
147
146
}
148
147
149
- if operateCount == numOfIDs { // all operations are going to be done
148
+ if operateCount == numOfIDs { // All operations are going to be done
150
149
oldIdToLabelsMap , _ , err := podopslifecycle .PodIDAndTypesMap (oldPod )
151
150
if err != nil {
152
151
return err
@@ -172,7 +171,7 @@ func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, n
172
171
}
173
172
}
174
173
175
- if operatedCount == numOfIDs { // all operations are done
174
+ if operatedCount == numOfIDs { // All operations are done
176
175
for id , labels := range newIDToLabelsMap {
177
176
if _ , ok := labels [v1alpha1 .PodPostCheckLabelPrefix ]; ! ok {
178
177
lc .addLabelWithTime (newPod , fmt .Sprintf ("%s/%s" , v1alpha1 .PodPostCheckLabelPrefix , id )) // post-check
0 commit comments