Skip to content

Commit

Permalink
adding IP Protocol enumeration to CRD can reduce the kube-ovn Control…
Browse files Browse the repository at this point in the history
…ler judgment logic (#1391)
  • Loading branch information
wangyd1988 committed Mar 22, 2022
1 parent dcc7971 commit 7bd25c6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ spec:
type: boolean
protocol:
type: string
enum:
- IPv4
- IPv6
- Dual
cidrBlock:
type: string
namespaces:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {
changed = true
}
newCIDRBlock := subnet.Spec.CIDRBlock
if subnet.Spec.Protocol == "" || subnet.Spec.Protocol != util.CheckProtocol(newCIDRBlock) {
if subnet.Spec.Protocol != util.CheckProtocol(newCIDRBlock) {
subnet.Spec.Protocol = util.CheckProtocol(subnet.Spec.CIDRBlock)
changed = true
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e-ebpf/e2e_ebpf_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
Spec: kubeovn.SubnetSpec{
CIDRBlock: "12.10.0.0/16",
Namespaces: []string{namespace},
Protocol: util.CheckProtocol("12.10.0.0/16"),
},
}
_, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{})
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
Spec: kubeovn.SubnetSpec{
CIDRBlock: "12.10.0.0/16",
Namespaces: []string{namespace},
Protocol: util.CheckProtocol("12.10.0.0/16"),
},
}
_, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{})
Expand Down Expand Up @@ -287,6 +288,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
ExcludeIps: underlayNodeIPs,
Vlan: vlan.Name,
Namespaces: []string{underlay.Namespace},
Protocol: util.CheckProtocol(underlayCIDR),
},
}
if _, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &subnet, metav1.CreateOptions{}); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/subnet/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var _ = Describe("[Subnet]", func() {
},
Spec: kubeovn.SubnetSpec{
CIDRBlock: cidr,
Protocol: util.CheckProtocol(cidr),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{})
Expand Down Expand Up @@ -126,6 +127,7 @@ var _ = Describe("[Subnet]", func() {
CIDRBlock: cidr,
GatewayType: kubeovn.GWCentralizedType,
GatewayNode: "kube-ovn-control-plane,kube-ovn-worker,kube-ovn-worker2",
Protocol: util.CheckProtocol(cidr),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{})
Expand Down Expand Up @@ -158,6 +160,7 @@ var _ = Describe("[Subnet]", func() {
},
Spec: kubeovn.SubnetSpec{
CIDRBlock: cidr,
Protocol: util.CheckProtocol(cidr),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), s, metav1.CreateOptions{})
Expand Down Expand Up @@ -196,6 +199,7 @@ var _ = Describe("[Subnet]", func() {
},
Spec: kubeovn.SubnetSpec{
CIDRBlock: cidr,
Protocol: util.CheckProtocol(cidr),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{})
Expand Down Expand Up @@ -231,6 +235,7 @@ var _ = Describe("[Subnet]", func() {
},
Spec: kubeovn.SubnetSpec{
CIDRBlock: cidr,
Protocol: util.CheckProtocol(cidr),
},
}

Expand Down Expand Up @@ -262,6 +267,7 @@ var _ = Describe("[Subnet]", func() {
Spec: kubeovn.SubnetSpec{
CIDRBlock: "19.0.0.0/31",
ExcludeIps: []string{"179.17.0.0..179.17.0.10"},
Protocol: util.CheckProtocol("19.0.0.0/31"),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), s, metav1.CreateOptions{})
Expand All @@ -285,6 +291,7 @@ var _ = Describe("[Subnet]", func() {
Spec: kubeovn.SubnetSpec{
CIDRBlock: "29.0.0.0/30",
ExcludeIps: []string{"179.17.0.0..179.17.0.10"},
Protocol: util.CheckProtocol("29.0.0.0/30"),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), s, metav1.CreateOptions{})
Expand All @@ -308,6 +315,7 @@ var _ = Describe("[Subnet]", func() {
Spec: kubeovn.SubnetSpec{
CIDRBlock: "179.17.0.0/24",
ExcludeIps: []string{"179.17.0.0..179.17.0.10"},
Protocol: util.CheckProtocol("179.17.0.0/24"),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), s, metav1.CreateOptions{})
Expand Down Expand Up @@ -375,6 +383,7 @@ var _ = Describe("[Subnet]", func() {
ExternalEgressGateway: egw,
PolicyRoutingPriority: priority,
PolicyRoutingTableID: tableID,
Protocol: util.CheckProtocol(cidr),
},
}
_, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), subnet, metav1.CreateOptions{})
Expand Down Expand Up @@ -520,6 +529,7 @@ var _ = Describe("[Subnet]", func() {
PolicyRoutingPriority: priority,
PolicyRoutingTableID: tableID,
Namespaces: []string{namespace},
Protocol: util.CheckProtocol(cidr),
},
}
_, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{})
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/underlay/underlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ var _ = Describe("[Underlay]", func() {
CIDRBlock: "99.11.0.0/16",
Vlan: Vlan,
LogicalGateway: true,
Protocol: util.CheckProtocol(cidr),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), subnet, metav1.CreateOptions{})
Expand Down Expand Up @@ -281,6 +282,7 @@ var _ = Describe("[Underlay]", func() {
CIDRBlock: "99.12.0.0/16",
Vlan: Vlan,
DisableGatewayCheck: true,
Protocol: util.CheckProtocol(cidr),
},
}
_, err := f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), subnet, metav1.CreateOptions{})
Expand Down
4 changes: 4 additions & 0 deletions yamls/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ spec:
type: boolean
protocol:
type: string
enum:
- IPv4
- IPv6
- Dual
cidrBlock:
type: string
namespaces:
Expand Down

0 comments on commit 7bd25c6

Please sign in to comment.