Skip to content

Commit 6f1a7de

Browse files
committed
add HostSubnet.EgressCIDRs
1 parent 9453185 commit 6f1a7de

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

pkg/network/apis/network/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ type HostSubnet struct {
5151
HostIP string
5252
Subnet string
5353

54-
EgressIPs []string
54+
EgressIPs []string
55+
EgressCIDRs []string
5556
}
5657

5758
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/network/apis/network/validation/validation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ func ValidateHostSubnet(hs *networkapi.HostSubnet) field.ErrorList {
174174
}
175175
}
176176

177+
for i, egressCIDR := range hs.EgressCIDRs {
178+
if _, err := validateCIDRv4(egressCIDR); err != nil {
179+
allErrs = append(allErrs, field.Invalid(field.NewPath("egressCIDRs").Index(i), egressCIDR, err.Error()))
180+
}
181+
}
182+
177183
return allErrs
178184
}
179185

pkg/network/apis/network/validation/validation_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,39 @@ func TestValidateHostSubnet(t *testing.T) {
405405
},
406406
expectedErrors: 2,
407407
},
408+
{
409+
name: "Good one with EgressCIDRs",
410+
hs: &networkapi.HostSubnet{
411+
ObjectMeta: metav1.ObjectMeta{
412+
Name: "abc.def.com",
413+
},
414+
Host: "abc.def.com",
415+
HostIP: "10.20.30.40",
416+
Subnet: "8.8.8.0/24",
417+
EgressCIDRs: []string{
418+
"192.168.1.99/32",
419+
"192.168.2.0/24",
420+
},
421+
},
422+
expectedErrors: 0,
423+
},
424+
{
425+
name: "Malformed EgressCIDRs",
426+
hs: &networkapi.HostSubnet{
427+
ObjectMeta: metav1.ObjectMeta{
428+
Name: "abc.def.com",
429+
},
430+
Host: "abc.def.com",
431+
HostIP: "10.20.30.40",
432+
Subnet: "8.8.8.0/24",
433+
EgressCIDRs: []string{
434+
"192.168.1.99",
435+
"bob/32",
436+
"1234::5678/64",
437+
},
438+
},
439+
expectedErrors: 3,
440+
},
408441
{
409442
name: "IPv6 subnet",
410443
hs: &networkapi.HostSubnet{

0 commit comments

Comments
 (0)