Skip to content

Commit 3a96257

Browse files
authored
ovn fip spec distributed and support v4:v6 v6:v4 (#5283)
* custom ovn fip has its own type to cut the relationship with ovn-cluster enable eip snat 1. vpc ovn-fip could set its own distributed 2. ovn-fip support v4:v4 v4:v6 --------- Signed-off-by: zbb88888 <[email protected]>
1 parent 82b73fe commit 3a96257

5 files changed

Lines changed: 46 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,9 @@ spec:
16491649
- jsonPath: .status.vpc
16501650
name: Vpc
16511651
type: string
1652+
- jsonPath: .spec.type
1653+
name: Type
1654+
type: string
16521655
- jsonPath: .status.v4Eip
16531656
name: V4Eip
16541657
type: string
@@ -1713,6 +1716,8 @@ spec:
17131716
type: string
17141717
ipType:
17151718
type: string
1719+
type:
1720+
type: string
17161721
ipName:
17171722
type: string
17181723
vpc:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,9 @@ spec:
16651665
- jsonPath: .status.vpc
16661666
name: Vpc
16671667
type: string
1668+
- jsonPath: .spec.type
1669+
name: Type
1670+
type: string
16681671
- jsonPath: .status.v4Eip
16691672
name: V4Eip
16701673
type: string
@@ -1729,6 +1732,8 @@ spec:
17291732
type: string
17301733
ipType:
17311734
type: string
1735+
type:
1736+
type: string
17321737
ipName:
17331738
type: string
17341739
vpc:

dist/images/install.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,9 @@ spec:
19061906
- jsonPath: .status.vpc
19071907
name: Vpc
19081908
type: string
1909+
- jsonPath: .spec.type
1910+
name: Type
1911+
type: string
19091912
- jsonPath: .status.v4Eip
19101913
name: V4Eip
19111914
type: string
@@ -1970,6 +1973,8 @@ spec:
19701973
type: string
19711974
ipType:
19721975
type: string
1976+
type:
1977+
type: string
19731978
ipName:
19741979
type: string
19751980
vpc:

pkg/apis/kubeovn/v1/ovn-fip.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type OvnFipSpec struct {
3434
Vpc string `json:"vpc"`
3535
V4Ip string `json:"v4Ip"`
3636
V6Ip string `json:"v6Ip"`
37+
Type string `json:"type"` // distributed, centralized
3738
}
3839

3940
type OvnFipStatus struct {

pkg/controller/ovn_fip.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,42 @@ func (c *Controller) handleAddOvnFip(key string) error {
177177
return err
178178
}
179179
// ovn add fip
180-
options := map[string]string{"staleless": strconv.FormatBool(c.ExternalGatewayType == kubeovnv1.GWDistributedType)}
180+
var staleless bool
181+
if cachedFip.Spec.Type != "" {
182+
staleless = (cachedFip.Spec.Type == kubeovnv1.GWDistributedType)
183+
} else {
184+
staleless = (c.ExternalGatewayType == kubeovnv1.GWDistributedType)
185+
}
186+
options := map[string]string{"staleless": strconv.FormatBool(staleless)}
187+
188+
// support v4:v4
181189
if v4IP != "" && v4Eip != "" {
182190
if err = c.OVNNbClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, v4Eip, v4IP, mac, cachedFip.Spec.IPName, options); err != nil {
183-
klog.Errorf("failed to create v4 fip, %v", err)
191+
klog.Errorf("failed to create v4:v4 fip, %v", err)
184192
return err
185193
}
186194
}
187-
if v6Eip == "" && v6IP != "" {
195+
196+
// support v6:v6
197+
if v6IP != "" && v6Eip != "" {
188198
if err = c.OVNNbClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, v6Eip, v6IP, mac, cachedFip.Spec.IPName, options); err != nil {
189-
klog.Errorf("failed to create v6 fip, %v", err)
199+
klog.Errorf("failed to create v6:v6 fip, %v", err)
200+
return err
201+
}
202+
}
203+
204+
// support v4:v6
205+
if v4IP != "" && v6IP == "" && v4Eip == "" && v6Eip != "" {
206+
if err = c.OVNNbClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, v6Eip, v4IP, mac, cachedFip.Spec.IPName, options); err != nil {
207+
klog.Errorf("failed to create v4:v6 fip, %v", err)
208+
return err
209+
}
210+
}
211+
212+
// support v6:v4
213+
if v6IP != "" && v4IP == "" && v6Eip == "" && v4Eip != "" {
214+
if err = c.OVNNbClient.AddNat(vpcName, ovnnb.NATTypeDNATAndSNAT, v4Eip, v6IP, mac, cachedFip.Spec.IPName, options); err != nil {
215+
klog.Errorf("failed to create v6:v4 fip, %v", err)
190216
return err
191217
}
192218
}

0 commit comments

Comments
 (0)