Skip to content

Commit fcadbcd

Browse files
installer: address review feedback for NetworkDeviceSpec validation
- Reduce nameservers MaxItems from 10 to 3 to match existing Go validation that enforces a maximum of 3 nameservers. - Add unit tests for IPv6 nameserver, invalid nameserver, empty gateway, and IPv6 CIDR ipAddrs to cover the XValidation CEL rules. - Update generated CRD YAML to reflect the MaxItems change. Signed-off-by: Ankit Mahajan <ankimaha@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Ankit Mahajan <ankimaha@redhat.com>
1 parent a7a0b0a commit fcadbcd

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8692,7 +8692,7 @@ spec:
86928692
example: 8.8.8.8
86938693
items:
86948694
type: string
8695-
maxItems: 10
8695+
maxItems: 3
86968696
type: array
86978697
x-kubernetes-validations:
86988698
- message: each nameserver must be a valid IPv4 or IPv6

pkg/types/vsphere/platform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ type NetworkDeviceSpec struct {
348348
// 8.8.8.8. a nameserver is not provided by a fulfilled IPAddressClaim. If DHCP is not the
349349
// source of IP addresses for this network device, nameservers should include a valid nameserver.
350350
// +kubebuilder:validation:XValidation:rule="self.all(x, isIP(x))",message="each nameserver must be a valid IPv4 or IPv6 address"
351-
// +kubebuilder:validation:MaxItems=10
351+
// +kubebuilder:validation:MaxItems=3
352352
// +kubebuilder:example=`8.8.8.8`
353353
Nameservers []string `json:"nameservers,omitempty"`
354354
}

pkg/types/vsphere/validation/platform_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,47 @@ func TestValidatePlatform(t *testing.T) {
898898
config: validStaticIPInstallConfig(),
899899
expectedError: `^test-path.hosts.nameservers: Too many: 4: must have at most 3 items$`,
900900
},
901+
{
902+
name: "Static IP - valid nameserver IPv6",
903+
platform: func() *vsphere.Platform {
904+
p := validPlatform()
905+
p.Hosts = validHosts()
906+
p.Hosts[1].NetworkDevice.Nameservers = []string{"2001:4860:4860::8888"}
907+
return p
908+
}(),
909+
config: validStaticIPInstallConfig(),
910+
},
911+
{
912+
name: "Static IP - invalid nameserver",
913+
platform: func() *vsphere.Platform {
914+
p := validPlatform()
915+
p.Hosts = validHosts()
916+
p.Hosts[1].NetworkDevice.Nameservers = []string{"not-an-ip"}
917+
return p
918+
}(),
919+
config: validStaticIPInstallConfig(),
920+
expectedError: `^test-path.hosts.nameservers: Invalid value: "not-an-ip": "not-an-ip" is not a valid IP$`,
921+
},
922+
{
923+
name: "Static IP - empty gateway is valid",
924+
platform: func() *vsphere.Platform {
925+
p := validPlatform()
926+
p.Hosts = validHosts()
927+
p.Hosts[1].NetworkDevice.Gateway = ""
928+
return p
929+
}(),
930+
config: validStaticIPInstallConfig(),
931+
},
932+
{
933+
name: "Static IP - valid IPv6 CIDR ipAddrs",
934+
platform: func() *vsphere.Platform {
935+
p := validPlatform()
936+
p.Hosts = validHosts()
937+
p.Hosts[1].NetworkDevice.IPAddrs = []string{"2001:db8::1/64"}
938+
return p
939+
}(),
940+
config: validStaticIPInstallConfig(),
941+
},
901942
{
902943
name: "Static IP - No bootstrap host",
903944
platform: func() *vsphere.Platform {

0 commit comments

Comments
 (0)