@@ -256,6 +256,19 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
256
256
return err
257
257
}
258
258
259
+ var natGwPodContainerRestartCount int32
260
+ oriPod , _err := c .getNatGwPod (key )
261
+ if _err == nil {
262
+ pod := oriPod .DeepCopy ()
263
+ for _ , psc := range pod .Status .ContainerStatuses {
264
+ if psc .Name != "vpc-nat-gw" {
265
+ continue
266
+ }
267
+ natGwPodContainerRestartCount = psc .RestartCount
268
+ break
269
+ }
270
+ }
271
+
259
272
// check or create statefulset
260
273
needToCreate := false
261
274
needToUpdate := false
@@ -269,11 +282,10 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
269
282
return err
270
283
}
271
284
}
272
- newSts := c .genNatGwStatefulSet (gw , oldSts .DeepCopy ())
273
- if ! needToCreate && isVpcNatGwChanged (gw ) {
285
+ newSts := c .genNatGwStatefulSet (gw , oldSts .DeepCopy (), natGwPodContainerRestartCount )
286
+ if ! needToCreate && ( isVpcNatGwChanged (gw ) || natGwPodContainerRestartCount > 0 ) {
274
287
needToUpdate = true
275
288
}
276
-
277
289
switch {
278
290
case needToCreate :
279
291
// if pod create successfully, will add initVpcNatGatewayQueue
@@ -729,7 +741,7 @@ func (c *Controller) execNatGwRules(pod *corev1.Pod, operation string, rules []s
729
741
return nil
730
742
}
731
743
732
- func (c * Controller ) genNatGwStatefulSet (gw * kubeovnv1.VpcNatGateway , oldSts * v1.StatefulSet ) (newSts * v1.StatefulSet ) {
744
+ func (c * Controller ) genNatGwStatefulSet (gw * kubeovnv1.VpcNatGateway , oldSts * v1.StatefulSet , natGwPodContainerRestartCount int32 ) (newSts * v1.StatefulSet ) {
733
745
replicas := int32 (1 )
734
746
name := util .GenNatGwStsName (gw .Name )
735
747
allowPrivilegeEscalation := true
@@ -749,6 +761,14 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
749
761
util .LogicalSwitchAnnotation : gw .Spec .Subnet ,
750
762
util .IPAddressAnnotation : gw .Spec .LanIP ,
751
763
}
764
+
765
+ if oldSts != nil && len (oldSts .Spec .Template .Annotations ) != 0 {
766
+ if _ , ok := oldSts .Spec .Template .Annotations [util .VpcNatGatewayContainerRestartAnnotation ]; ! ok && natGwPodContainerRestartCount > 0 {
767
+ podAnnotations [util .VpcNatGatewayContainerRestartAnnotation ] = ""
768
+ }
769
+ }
770
+ klog .V (3 ).Infof ("%s podAnnotations:%v" , gw .Name , podAnnotations )
771
+
752
772
for key , value := range podAnnotations {
753
773
newPodAnnotations [key ] = value
754
774
}
0 commit comments