Skip to content

Commit 779d9e1

Browse files
authored
support for vpc nat gateway without eip (#5605)
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent 554039c commit 779d9e1

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

charts/kube-ovn-v2/crds/kube-ovn-crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ spec:
506506
type: string
507507
qosPolicy:
508508
type: string
509+
noDefaultEIP:
510+
type: boolean
509511
bgpSpeaker:
510512
type: object
511513
properties:

charts/kube-ovn/templates/kube-ovn-crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ spec:
506506
type: string
507507
qosPolicy:
508508
type: string
509+
noDefaultEIP:
510+
type: boolean
509511
bgpSpeaker:
510512
type: object
511513
properties:

dist/images/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ spec:
751751
type: string
752752
qosPolicy:
753753
type: string
754+
noDefaultEIP:
755+
type: boolean
754756
bgpSpeaker:
755757
type: object
756758
properties:

dist/images/vpcnatgateway/nat-gateway.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function init() {
137137

138138
# Send gratuitous ARP for all the IPs on the external network interface at initialization
139139
# This is especially useful to update the MAC of the nexthop we announce to the BGP speaker
140-
ip -4 addr show dev net1 | awk '/inet /{print $2}' | cut -d/ -f1 | xargs -n1 arping -I net1 -c 3 -U
140+
ip -4 addr show dev $EXTERNAL_INTERFACE | awk '/inet /{print $2}' | cut -d/ -f1 | xargs -n1 arping -I $EXTERNAL_INTERFACE -c 3 -U
141141
}
142142

143143

@@ -195,6 +195,14 @@ function add_eip() {
195195
exec_cmd "ip addr replace $eip dev $EXTERNAL_INTERFACE"
196196
exec_cmd "arping -I $EXTERNAL_INTERFACE -c 3 -U $eip_without_prefix"
197197
done
198+
199+
if [ -n "$GATEWAY_V4" ]; then
200+
exec_cmd "ip route replace default via $GATEWAY_V4 dev $EXTERNAL_INTERFACE"
201+
fi
202+
203+
if [ -n "$GATEWAY_V6" ]; then
204+
exec_cmd "ip -6 route replace default via $GATEWAY_V6 dev $EXTERNAL_INTERFACE"
205+
fi
198206
}
199207

200208
function del_eip() {

pkg/apis/kubeovn/v1/vpc-nat-gateway.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type VpcNatGatewaySpec struct {
4040
QoSPolicy string `json:"qosPolicy"`
4141
BgpSpeaker VpcBgpSpeaker `json:"bgpSpeaker"`
4242
Routes []Route `json:"routes"`
43+
NoDefaultEIP bool `json:"noDefaultEIP"`
4344
}
4445

4546
type VpcBgpSpeaker struct {

pkg/controller/vpc_nat_gateway.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,13 @@ func (c *Controller) handleAddOrUpdateVpcNatGw(key string) error {
192192
}
193193

194194
var natGwPodContainerRestartCount int32
195-
pod, _err := c.getNatGwPod(key)
196-
if _err == nil {
197-
for _, psc := range pod.Status.ContainerStatuses {
198-
if psc.Name != "vpc-nat-gw" {
199-
continue
195+
pod, err := c.getNatGwPod(key)
196+
if err == nil {
197+
for _, containerStatus := range pod.Status.ContainerStatuses {
198+
if containerStatus.Name == "vpc-nat-gw" {
199+
natGwPodContainerRestartCount = containerStatus.RestartCount
200+
break
200201
}
201-
natGwPodContainerRestartCount = psc.RestartCount
202-
break
203202
}
204203
}
205204

@@ -972,10 +971,13 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
972971
if v6Gateway != "" {
973972
routes = append(routes, request.Route{Destination: "::/0", Gateway: v6Gateway})
974973
}
975-
976-
if err = setPodRoutesAnnotation(annotations, subnet.Spec.Provider, routes); err != nil {
977-
klog.Error(err)
978-
return nil, err
974+
if !gw.Spec.NoDefaultEIP {
975+
if err = setPodRoutesAnnotation(annotations, subnet.Spec.Provider, routes); err != nil {
976+
klog.Error(err)
977+
return nil, err
978+
}
979+
} else {
980+
annotations[fmt.Sprintf(util.AllocatedAnnotationTemplate, subnet.Spec.Provider)] = "true"
979981
}
980982

981983
selectors := util.GenNatGwSelectors(gw.Spec.Selector)
@@ -1006,6 +1008,16 @@ func (c *Controller) genNatGwStatefulSet(gw *kubeovnv1.VpcNatGateway, oldSts *v1
10061008
Image: vpcNatImage,
10071009
Command: []string{"sleep", "infinity"},
10081010
ImagePullPolicy: corev1.PullIfNotPresent,
1011+
Env: []corev1.EnvVar{
1012+
{
1013+
Name: "GATEWAY_V4",
1014+
Value: v4Gateway,
1015+
},
1016+
{
1017+
Name: "GATEWAY_V6",
1018+
Value: v6Gateway,
1019+
},
1020+
},
10091021
SecurityContext: &corev1.SecurityContext{
10101022
Privileged: ptr.To(true),
10111023
AllowPrivilegeEscalation: ptr.To(true),

0 commit comments

Comments
 (0)