Skip to content

Commit

Permalink
init all not inited vpc nat gw after restarted
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 committed Sep 26, 2023
1 parent 55f254e commit d482b6c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,9 @@ func (c *Controller) initResourceOnce() {
util.LogFatalAndExit(err, "failed to sync crd vpc nat gateways")
}
}

if err := c.initVpcNatGw(); err != nil {
util.LogFatalAndExit(err, "failed to initialize vpc nat gateways")
}
if c.config.EnableLb {
if err := c.initVpcDNSConfig(); err != nil {
util.LogFatalAndExit(err, "failed to initialize vpc-dns")
Expand Down
30 changes: 30 additions & 0 deletions pkg/controller/vpc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,33 @@ func (c *Controller) execNatGwQoSInPod(
}
return nil
}

func (c *Controller) initVpcNatGw() error {
if vpcNatEnabled != "true" {
err := fmt.Errorf("iptables nat gw not enable")
klog.Warning(err)
return nil
}
klog.Infof("init all vpc nat gateways")
gws, err := c.vpcNatGatewayLister.List(labels.Everything())
if err != nil {
err = fmt.Errorf("failed to get vpc nat gw list, %v", err)
klog.Error(err)
return err
}
for _, gw := range gws {
pod, err := c.getNatGwPod(gw.Name)
if err != nil {
// the nat gw maybe deleted
err := fmt.Errorf("failed to get nat gw %s pod: %v", gw.Name, err)
klog.Error(err)
}
if vpcGwName, isVpcNatGw := pod.Annotations[util.VpcNatGatewayAnnotation]; isVpcNatGw {
if _, hasInit := pod.Annotations[util.VpcNatGatewayInitAnnotation]; hasInit {
return nil
}
c.initVpcNatGatewayQueue.Add(vpcGwName)
}
}
return nil
}

0 comments on commit d482b6c

Please sign in to comment.