Skip to content

Commit 29f5115

Browse files
committed
Validate device path in agent rootDeviceHints
1 parent d27a160 commit 29f5115

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

pkg/asset/agent/agentconfig/agent_config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/openshift/installer/pkg/asset"
1414
"github.com/openshift/installer/pkg/types/agent"
1515
"github.com/openshift/installer/pkg/types/agent/conversion"
16+
"github.com/openshift/installer/pkg/types/baremetal/validation"
1617
"github.com/openshift/installer/pkg/validate"
1718
)
1819

@@ -247,15 +248,16 @@ func (a *AgentConfig) validateHostInterfaces(hostPath *field.Path, host agent.Ho
247248
}
248249

249250
func (a *AgentConfig) validateHostRootDeviceHints(hostPath *field.Path, host agent.Host) field.ErrorList {
250-
var allErrs field.ErrorList
251+
rdhPath := hostPath.Child("rootDeviceHints")
252+
allErrs := validation.ValidateHostRootDeviceHints(&host.RootDeviceHints, rdhPath)
251253

252254
if host.RootDeviceHints.WWNWithExtension != "" {
253255
allErrs = append(allErrs, field.Forbidden(
254-
hostPath.Child("RootDeviceHints", "WWNWithExtension"), "WWN extensions are not supported in root device hints"))
256+
rdhPath.Child("wwnWithExtension"), "WWN extensions are not supported in root device hints"))
255257
}
256258

257259
if host.RootDeviceHints.WWNVendorExtension != "" {
258-
allErrs = append(allErrs, field.Forbidden(hostPath.Child("RootDeviceHints", "WWNVendorExtension"), "WWN vendor extensions are not supported in root device hints"))
260+
allErrs = append(allErrs, field.Forbidden(rdhPath.Child("wwnVendorExtension"), "WWN vendor extensions are not supported in root device hints"))
259261
}
260262

261263
return allErrs

pkg/asset/agent/agentconfig/agent_config_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ hosts:
152152
expectedFound: false,
153153
expectedError: "invalid Agent Config configuration: Hosts[0].Interfaces[0].macAddress: Required value: each interface must have a MAC address defined",
154154
},
155+
{
156+
name: "unsupported device name root device hint",
157+
data: `
158+
apiVersion: v1beta1
159+
metadata:
160+
name: agent-config-cluster0
161+
rendezvousIP: 192.168.111.80
162+
hosts:
163+
- hostname: control-0.example.org
164+
interfaces:
165+
- name: enp2s0
166+
macAddress: 98:af:65:a5:8d:01
167+
rootDeviceHints:
168+
deviceName: "/dev/disk/by-id/wwn-0x600508e000000000ce506dc50ab0ad05"`,
169+
170+
expectedFound: false,
171+
expectedError: "invalid Agent Config configuration: Hosts[0].rootDeviceHints.deviceName: Invalid value: \"/dev/disk/by-id/wwn-0x600508e000000000ce506dc50ab0ad05\": Device Name of root device hint must be path in /dev/ or /dev/disk/by-path/",
172+
},
155173
{
156174
name: "unsupported wwn extension root device hint",
157175
data: `
@@ -168,7 +186,7 @@ hosts:
168186
wwnWithExtension: "wwn-with-extension-value"`,
169187

170188
expectedFound: false,
171-
expectedError: "invalid Agent Config configuration: Hosts[0].RootDeviceHints.WWNWithExtension: Forbidden: WWN extensions are not supported in root device hints",
189+
expectedError: "invalid Agent Config configuration: Hosts[0].rootDeviceHints.wwnWithExtension: Forbidden: WWN extensions are not supported in root device hints",
172190
},
173191
{
174192
name: "unsupported wwn vendor extension root device hint",
@@ -186,7 +204,7 @@ hosts:
186204
wwnVendorExtension: "wwn-with-vendor-extension-value"`,
187205

188206
expectedFound: false,
189-
expectedError: "invalid Agent Config configuration: Hosts[0].RootDeviceHints.WWNVendorExtension: Forbidden: WWN vendor extensions are not supported in root device hints",
207+
expectedError: "invalid Agent Config configuration: Hosts[0].rootDeviceHints.wwnVendorExtension: Forbidden: WWN vendor extensions are not supported in root device hints",
190208
},
191209
{
192210
name: "node-hostname-and-role-are-not-required",

0 commit comments

Comments
 (0)