@@ -179,6 +179,18 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
179
179
return err
180
180
}
181
181
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
+
182
194
// check or create statefulset
183
195
needToCreate := false
184
196
needToUpdate := false
@@ -191,12 +203,12 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
191
203
}
192
204
needToCreate , oldSts = true , nil
193
205
}
194
- newSts , err := c .genNatGwStatefulSet (gw , oldSts )
206
+ newSts , err := c .genNatGwStatefulSet (gw , oldSts , natGwPodContainerRestartCount )
195
207
if err != nil {
196
208
klog .Error (err )
197
209
return err
198
210
}
199
- if ! needToCreate && isVpcNatGwChanged (gw ) {
211
+ if ! needToCreate && ( isVpcNatGwChanged (gw ) || natGwPodContainerRestartCount > 0 ) {
200
212
needToUpdate = true
201
213
}
202
214
@@ -717,7 +729,7 @@ func (c *Controller) setNatGwAPIRoute(annotations map[string]string, nadNamespac
717
729
return nil
718
730
}
719
731
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 ) {
721
733
annotations := make (map [string ]string , 7 )
722
734
if oldSts != nil && len (oldSts .Annotations ) != 0 {
723
735
annotations = maps .Clone (oldSts .Annotations )
@@ -731,6 +743,13 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
731
743
util .IPAddressAnnotation : gw .Spec .LanIP ,
732
744
}
733
745
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
+
734
753
// Add an interface that can reach the API server, we need access to it to probe Kube-OVN resources
735
754
if gw .Spec .BgpSpeaker .Enabled {
736
755
if err := c .setNatGwAPIAccess (podAnnotations , externalNetworkNad ); err != nil {
0 commit comments