Skip to content

init all not inited vpc nat gw after k8s cluster restarted #3261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions pkg/controller/vpc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,32 @@ func (c *Controller) execNatGwQoSInPod(
}
return nil
}

func (c *Controller) initVpcNatGw() error {
if vpcNatEnabled != "true" {
klog.Info("iptables nat gw not enable")
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.Warning(err)
}
if vpcGwName, isVpcNatGw := pod.Annotations[util.VpcNatGatewayAnnotation]; isVpcNatGw {
if _, hasInit := pod.Annotations[util.VpcNatGatewayInitAnnotation]; hasInit {
return nil
}
c.initVpcNatGatewayQueue.Add(vpcGwName)
}
}
return nil
}