Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/data/install.openshift.io_installconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,8 @@ spec:
type: string
name:
type: string
networkConfig:
type: string
role:
type: string
rootDeviceHints:
Expand Down
1 change: 1 addition & 0 deletions docs/user/metal/install_ipi.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ should be used to build the cluster. The number of assets must be at least great
| `bootMACAddress` | | The MAC address of the NIC the host will use to boot on the provisioning network. It must be unique. |
| `rootDeviceHints` | | How to choose the target disk for the OS during provisioning - for more details see [upstream docs](https://github.com/metal3-io/baremetal-operator/blob/master/docs/api.md). |
| `bootMode` | `UEFI` | Choose `legacy` (BIOS) or `UEFI` mode for booting. Use `UEFISecureBoot` to enable UEFI and secure boot on the server. Only some drivers support UEFI secure boot (notably, IPMI does not). |
| `networkConfig` | | Yaml string describing the desired host networking settings. Must be compatible with NMState (for more details see https://nmstate.io/) |

The `bmc` parameter for each host is a set of values for accessing the
baseboard management controller in the host.
Expand Down
1 change: 1 addition & 0 deletions pkg/types/baremetal/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Host struct {
HardwareProfile string `json:"hardwareProfile"`
RootDeviceHints *RootDeviceHints `json:"rootDeviceHints,omitempty"`
BootMode BootMode `json:"bootMode,omitempty"`
NetworkConfig string `json:"networkConfig,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation here for this field so that it shows up in the openshift-install explain output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that Host fields have been documented just here. Do you maybe mean adding a description also for all of them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we want this to be a string rather than a map[string]interface{}? I would expect the user to want to enter in-line yaml rather than a text string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The installer manages it essentially as a blob (it will be stored also in a secret, see PR 5247) and will pass it as it is to the image builder container (with a just a minimal validation).

}

// IsMaster checks if the current host is a master
Expand Down
14 changes: 14 additions & 0 deletions pkg/types/baremetal/validation/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/apparentlymart/go-cidr/cidr"
"github.com/ghodss/yaml"
"github.com/go-playground/validator/v10"
"github.com/metal3-io/baremetal-operator/pkg/bmc"
"github.com/pkg/errors"
Expand Down Expand Up @@ -325,6 +326,18 @@ func validateHostsCount(hosts []*baremetal.Host, installConfig *types.InstallCon
return nil
}

// ensure that the NetworkConfig field contains a valid Yaml string
func validateNetworkConfig(hosts []*baremetal.Host, fldPath *field.Path) (errors field.ErrorList) {
for idx, host := range hosts {
networkConfig := make(map[string]interface{})
err := yaml.Unmarshal([]byte(host.NetworkConfig), &networkConfig)
if err != nil {
errors = append(errors, field.Invalid(fldPath.Index(idx).Child("networkConfig"), host.NetworkConfig, fmt.Sprintf("Not a valid yaml: %s", err.Error())))
}
}
return
}

// ensure that the bootMode field contains a valid value
func validateBootMode(hosts []*baremetal.Host, fldPath *field.Path) (errors field.ErrorList) {
for idx, host := range hosts {
Expand Down Expand Up @@ -404,6 +417,7 @@ func ValidatePlatform(p *baremetal.Platform, n *types.Networking, fldPath *field
allErrs = append(allErrs, validateHostsWithoutBMC(p.Hosts, fldPath)...)

allErrs = append(allErrs, validateBootMode(p.Hosts, fldPath.Child("Hosts"))...)
allErrs = append(allErrs, validateNetworkConfig(p.Hosts, fldPath.Child("Hosts"))...)

return allErrs
}
Expand Down
38 changes: 38 additions & 0 deletions pkg/types/baremetal/validation/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,39 @@ func TestValidatePlatform(t *testing.T) {
platform: platform().ProvisioningNetwork("Invalid").build(),
expected: `Unsupported value: "Invalid": supported values: "Disabled", "Managed", "Unmanaged"`,
},
{
name: "networkConfig_invalid",
platform: platform().Hosts(host1().NetworkConfig("Not a valid yaml content")).build(),
expected: ".*Invalid value.*Not a valid yaml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type map\\[string\\]interface \\{\\}",
},
{
name: "networkConfig_valid_yml",
platform: platform().Hosts(host1().NetworkConfig(`
interfaces:
- name: eth1
type: ethernet
state: up
- name: linux-br0
type: linux-bridge
state: up
bridge:
options:
group-forward-mask: 0
mac-ageing-time: 300
multicast-snooping: true
stp:
enabled: true
forward-delay: 15
hello-time: 2
max-age: 20
priority: 32768
port:
- name: eth1
stp-hairpin-mode: false
stp-path-cost: 100
stp-priority: 32`)).build(),
expected: "",
},
}

for _, tc := range cases {
Expand Down Expand Up @@ -731,6 +764,11 @@ func (hb *hostBuilder) Role(value string) *hostBuilder {
return hb
}

func (hb *hostBuilder) NetworkConfig(value string) *hostBuilder {
hb.Host.NetworkConfig = value
return hb
}

type platformBuilder struct {
baremetal.Platform
}
Expand Down