@@ -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
@@ -741,7 +753,7 @@ func (c *Controller) execNatGwRules(pod *corev1.Pod, operation string, rules []s
741
753
return nil
742
754
}
743
755
744
- func (c * Controller ) genNatGwStatefulSet (gw * kubeovnv1.VpcNatGateway , oldSts * v1.StatefulSet ) (newSts * v1.StatefulSet ) {
756
+ func (c * Controller ) genNatGwStatefulSet (gw * kubeovnv1.VpcNatGateway , oldSts * v1.StatefulSet , natGwPodContainerRestartCount int32 ) (newSts * v1.StatefulSet ) {
745
757
replicas := int32 (1 )
746
758
name := util .GenNatGwStsName (gw .Name )
747
759
allowPrivilegeEscalation := true
@@ -761,6 +773,14 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
761
773
util .LogicalSwitchAnnotation : gw .Spec .Subnet ,
762
774
util .IPAddressAnnotation : gw .Spec .LanIP ,
763
775
}
776
+
777
+ if oldSts != nil && len (oldSts .Spec .Template .Annotations ) != 0 {
778
+ if _ , ok := oldSts .Spec .Template .Annotations [util .VpcNatGatewayContainerRestartAnnotation ]; ! ok && natGwPodContainerRestartCount > 0 {
779
+ podAnnotations [util .VpcNatGatewayContainerRestartAnnotation ] = ""
780
+ }
781
+ }
782
+ klog .V (3 ).Infof ("%s podAnnotations:%v" , gw .Name , podAnnotations )
783
+
764
784
for key , value := range podAnnotations {
765
785
newPodAnnotations [key ] = value
766
786
}
0 commit comments