Skip to content

Commit

Permalink
add route for service ip range when init vpc-nat-gw (#2821)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed May 17, 2023
1 parent 4f015f6 commit 3b8c9ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 9 additions & 0 deletions dist/images/vpcnatgateway/nat-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ function init() {
iptables -t nat -A POSTROUTING -j SNAT_FILTER
iptables -t nat -A SNAT_FILTER -j EXCLUSIVE_SNAT
iptables -t nat -A SNAT_FILTER -j SHARED_SNAT

for rule in $@
do
arr=(${rule//,/ })
cidr=${arr[0]}
nextHop=${arr[1]}

exec_cmd "ip route replace $cidr via $nextHop dev eth0"
done
}


Expand Down
9 changes: 2 additions & 7 deletions pkg/controller/vpc_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,7 @@ func (c *Controller) handleInitVpcNatGw(key string) error {
}
return err
}
var v4Cidr string
if subnet, ok := c.ipam.Subnets[gw.Spec.Subnet]; ok {
v4Cidr = subnet.V4CIDR.String()
} else {
return fmt.Errorf("failed to get subnet %s", gw.Spec.Subnet)
}
// subnet for vpc-nat-gw has been checked when create vpc-nat-gw

oriPod, err := c.getNatGwPod(key)
if err != nil {
Expand All @@ -382,7 +377,7 @@ func (c *Controller) handleInitVpcNatGw(key string) error {
}
NAT_GW_CREATED_AT = pod.CreationTimestamp.Format("2006-01-02T15:04:05")
klog.V(3).Infof("nat gw pod '%s' inited at %s", key, NAT_GW_CREATED_AT)
if err = c.execNatGwRules(pod, natGwInit, []string{v4Cidr}); err != nil {
if err = c.execNatGwRules(pod, natGwInit, []string{fmt.Sprintf("%s,%s", c.config.ServiceClusterIPRange, pod.Annotations[util.GatewayAnnotation])}); err != nil {
err = fmt.Errorf("failed to init vpc nat gateway, %v", err)
klog.Error(err)
return err
Expand Down

0 comments on commit 3b8c9ed

Please sign in to comment.