@@ -179,6 +179,18 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
179179 return err
180180 }
181181
182+ var natGwPodContainerRestartCount int32
183+ pod , _err := c .getNatGwPod (key )
184+ if _err == nil {
185+ for _ , psc := range pod .Status .ContainerStatuses {
186+ if psc .Name != "vpc-nat-gw" {
187+ continue
188+ }
189+ natGwPodContainerRestartCount = psc .RestartCount
190+ break
191+ }
192+ }
193+
182194 // check or create statefulset
183195 needToCreate := false
184196 needToUpdate := false
@@ -191,12 +203,12 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
191203 }
192204 needToCreate , oldSts = true , nil
193205 }
194- newSts , err := c .genNatGwStatefulSet (gw , oldSts )
206+ newSts , err := c .genNatGwStatefulSet (gw , oldSts , natGwPodContainerRestartCount )
195207 if err != nil {
196208 klog .Error (err )
197209 return err
198210 }
199- if ! needToCreate && isVpcNatGwChanged (gw ) {
211+ if ! needToCreate && ( isVpcNatGwChanged (gw ) || natGwPodContainerRestartCount > 0 ) {
200212 needToUpdate = true
201213 }
202214
@@ -717,7 +729,7 @@ func (c *Controller) setNatGwAPIRoute(annotations map[string]string, nadNamespac
717729 return nil
718730}
719731
720- func (c * Controller ) genNatGwStatefulSet (gw * kubeovnv1.VpcNatGateway , oldSts * v1.StatefulSet ) (* v1.StatefulSet , error ) {
732+ func (c * Controller ) genNatGwStatefulSet (gw * kubeovnv1.VpcNatGateway , oldSts * v1.StatefulSet , natGwPodContainerRestartCount int32 ) (* v1.StatefulSet , error ) {
721733 annotations := make (map [string ]string , 7 )
722734 if oldSts != nil && len (oldSts .Annotations ) != 0 {
723735 annotations = maps .Clone (oldSts .Annotations )
@@ -731,6 +743,13 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
731743 util .IPAddressAnnotation : gw .Spec .LanIP ,
732744 }
733745
746+ if oldSts != nil && len (oldSts .Spec .Template .Annotations ) != 0 {
747+ if _ , ok := oldSts .Spec .Template .Annotations [util .VpcNatGatewayContainerRestartAnnotation ]; ! ok && natGwPodContainerRestartCount > 0 {
748+ podAnnotations [util .VpcNatGatewayContainerRestartAnnotation ] = ""
749+ }
750+ }
751+ klog .V (3 ).Infof ("%s podAnnotations:%v" , gw .Name , podAnnotations )
752+
734753 // Add an interface that can reach the API server, we need access to it to probe Kube-OVN resources
735754 if gw .Spec .BgpSpeaker .Enabled {
736755 if err := c .setNatGwAPIAccess (podAnnotations , externalNetworkNad ); err != nil {
0 commit comments