Skip to content

Commit ba5bc05

Browse files
committed
combine extra kernel params from different sources
This commit: - Combines the extra kernel params from both BMH and the PreprovisioningImage CRs. Signed-off-by: Adam Rozman <adam.rozman@est.tech>
1 parent 7ae19c9 commit ba5bc05

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

internal/controller/metal3.io/baremetalhost_controller.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,30 @@ func (info *reconcileInfo) publishEvent(reason, message string) {
8484
}
8585

8686
// return the PreprovisioningExtraKernelParams from the reconciliation info.
87-
func retrievePreprovisioningExtraKernelParamsSpec(info *reconcileInfo) string {
87+
func (r *BareMetalHostReconciler) retrievePreprovisioningExtraKernelParamsSpec(info *reconcileInfo, prov provisioner.Provisioner) string {
8888
if info == nil || info.host == nil {
8989
return ""
9090
}
91-
return info.host.Spec.PreprovisioningExtraKernelParams
91+
kernelExtraPreprovParams := info.host.Spec.PreprovisioningExtraKernelParams
92+
preprovImgFormats, err := prov.PreprovisioningImageFormats()
93+
if err != nil {
94+
return kernelExtraPreprovParams
95+
}
96+
preprovImg, err := r.getPreprovImage(info, preprovImgFormats)
97+
if err != nil {
98+
return kernelExtraPreprovParams
99+
}
100+
// Make sure kernel extra params coming from dynamically generater preprov
101+
// Image are also represented in every life cycle operation
102+
if preprovImg != nil {
103+
trimmedParams := strings.TrimSpace(kernelExtraPreprovParams)
104+
if trimmedParams == "" {
105+
kernelExtraPreprovParams = preprovImg.GeneratedImage.ExtraKernelParams
106+
} else {
107+
kernelExtraPreprovParams += " " + preprovImg.GeneratedImage.ExtraKernelParams
108+
}
109+
}
110+
return kernelExtraPreprovParams
92111
}
93112

94113
// +kubebuilder:rbac:groups=metal3.io,resources=baremetalhosts,verbs=get;list;watch;create;update;patch;delete
@@ -853,7 +872,7 @@ func (r *BareMetalHostReconciler) registerHost(prov provisioner.Provisioner, inf
853872
CurrentImage: getCurrentImage(info.host),
854873
PreprovisioningImage: preprovImg,
855874
PreprovisioningNetworkData: preprovisioningNetworkData,
856-
PreprovisioningExtraKernelParams: retrievePreprovisioningExtraKernelParamsSpec(info),
875+
PreprovisioningExtraKernelParams: r.retrievePreprovisioningExtraKernelParamsSpec(info, prov),
857876
HasCustomDeploy: hasCustomDeploy(info.host),
858877
DisablePowerOff: info.host.Spec.DisablePowerOff,
859878
CPUArchitecture: getHostArchitecture(info.host),
@@ -997,7 +1016,7 @@ func (r *BareMetalHostReconciler) actionInspecting(prov provisioner.Provisioner,
9971016
provResult, started, details, err := prov.InspectHardware(
9981017
provisioner.InspectData{
9991018
BootMode: info.host.Status.Provisioning.BootMode,
1000-
PreprovisioningExtraKernelParams: retrievePreprovisioningExtraKernelParamsSpec(info),
1019+
PreprovisioningExtraKernelParams: r.retrievePreprovisioningExtraKernelParamsSpec(info, prov),
10011020
},
10021021
info.host.Status.ErrorType == metal3api.InspectionError,
10031022
refresh,
@@ -1171,7 +1190,7 @@ func (r *BareMetalHostReconciler) actionPreparing(prov provisioner.Provisioner,
11711190
ActualRAIDConfig: info.host.Status.Provisioning.RAID.DeepCopy(),
11721191
RootDeviceHints: newStatus.Provisioning.RootDeviceHints.DeepCopy(),
11731192
FirmwareConfig: newStatus.Provisioning.Firmware.DeepCopy(),
1174-
PreprovisioningExtraKernelParams: retrievePreprovisioningExtraKernelParamsSpec(info),
1193+
PreprovisioningExtraKernelParams: r.retrievePreprovisioningExtraKernelParamsSpec(info, prov),
11751194
}
11761195
// When manual cleaning fails, we think that the existing RAID configuration
11771196
// is invalid and needs to be reconfigured.
@@ -1299,7 +1318,7 @@ func (r *BareMetalHostReconciler) actionProvisioning(prov provisioner.Provisione
12991318
BootMode: info.host.Status.Provisioning.BootMode,
13001319
HardwareProfile: hwProf,
13011320
RootDeviceHints: info.host.Status.Provisioning.RootDeviceHints.DeepCopy(),
1302-
PreprovisioningExtraKernelParams: retrievePreprovisioningExtraKernelParamsSpec(info),
1321+
PreprovisioningExtraKernelParams: r.retrievePreprovisioningExtraKernelParamsSpec(info, prov),
13031322
}, forceReboot)
13041323
if err != nil {
13051324
return actionError{fmt.Errorf("failed to provision: %w", err)}
@@ -1415,7 +1434,7 @@ func (r *BareMetalHostReconciler) actionDeprovisioning(prov provisioner.Provisio
14151434

14161435
func (r *BareMetalHostReconciler) doServiceIfNeeded(prov provisioner.Provisioner, info *reconcileInfo, hup *metal3api.HostUpdatePolicy) (result actionResult) {
14171436
servicingData := provisioner.ServicingData{}
1418-
servicingData.PreprovisioningExtraKernelParams = retrievePreprovisioningExtraKernelParamsSpec(info)
1437+
servicingData.PreprovisioningExtraKernelParams = r.retrievePreprovisioningExtraKernelParamsSpec(info, prov)
14191438

14201439
// (NOTE)janders: since Servicing is an opt-in feature that requires HostUpdatePolicy to be created and set to onReboot
14211440
// set below booleans to false by default and change to true based on policy settings

pkg/provisioner/ironic/ironic.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func fmtPreprovExtraKernParams(params string) string {
331331
func (p *ironicProvisioner) configureNode(data provisioner.ManagementAccessData, ironicNode *nodes.Node, bmcAccess bmc.AccessDetails) (result provisioner.Result, err error) {
332332
updater := clients.UpdateOptsBuilder(p.log)
333333

334-
deployImageInfo := setDeployImage(p.config, bmcAccess, data.PreprovisioningImage)
334+
deployImageInfo := setDeployImage(p.config, bmcAccess, data.PreprovisioningImage, data)
335335
updater.SetDriverInfoOpts(deployImageInfo, ironicNode)
336336

337337
updater.SetTopLevelOpt("automated_clean",
@@ -445,7 +445,7 @@ func setExternalURL(p *ironicProvisioner, driverInfo map[string]interface{}) map
445445

446446
// setDeployImage configures the IPA ramdisk parameters in the Node's DriverInfo.
447447
// It can use either the provided PreprovisioningImage or the global configuration from ironicConfig.
448-
func setDeployImage(config ironicConfig, accessDetails bmc.AccessDetails, hostImage *provisioner.PreprovisioningImage) clients.UpdateOptsData {
448+
func setDeployImage(config ironicConfig, accessDetails bmc.AccessDetails, hostImage *provisioner.PreprovisioningImage, data provisioner.ManagementAccessData) clients.UpdateOptsData {
449449
deployImageInfo := clients.UpdateOptsData{
450450
deployKernelKey: nil,
451451
deployRamdiskKey: nil,
@@ -471,9 +471,22 @@ func setDeployImage(config ironicConfig, accessDetails bmc.AccessDetails, hostIm
471471
deployImageInfo[deployKernelKey] = config.deployKernelURL
472472
}
473473
deployImageInfo[deployRamdiskKey] = hostImage.ImageURL
474+
// Extra params from the kernel have been already posted to
475+
// Ironic node API in the Register function, so extra kernel args in driver info need
476+
// update only if the dynamically generated preprov image requires it
474477
if hostImage.ExtraKernelParams != "" {
475-
// Using %default% prevents overriding the config in ironic-image
476-
deployImageInfo[kernelParamsKey] = "%default% " + hostImage.ExtraKernelParams
478+
// Combine the default ironic node kernel params with the extra
479+
// params from the BMH and the dynamically generated preprov image
480+
comExtraKernelParams := defaultKernelParam
481+
trimDataKParams := strings.TrimSpace(data.PreprovisioningExtraKernelParams)
482+
trimPreprovImgKParams := strings.TrimSpace(hostImage.ExtraKernelParams)
483+
if trimDataKParams != "" {
484+
comExtraKernelParams += " " + data.PreprovisioningExtraKernelParams
485+
}
486+
if trimPreprovImgKParams != "" {
487+
comExtraKernelParams += " " + hostImage.ExtraKernelParams
488+
}
489+
deployImageInfo[kernelParamsKey] = comExtraKernelParams
477490
}
478491
return deployImageInfo
479492
}

pkg/provisioner/ironic/register_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ func TestSetDeployImage(t *testing.T) {
10321032
Config ironicConfig
10331033
Driver bmc.AccessDetails
10341034
Image *provisioner.PreprovisioningImage
1035+
Data provisioner.ManagementAccessData
10351036
ExpectBuild bool
10361037
ExpectISO bool
10371038
ExpectPXE bool
@@ -1248,7 +1249,7 @@ func TestSetDeployImage(t *testing.T) {
12481249

12491250
for _, tc := range testCases {
12501251
t.Run(tc.Scenario, func(t *testing.T) {
1251-
opts := setDeployImage(tc.Config, tc.Driver, tc.Image)
1252+
opts := setDeployImage(tc.Config, tc.Driver, tc.Image, tc.Data)
12521253

12531254
switch {
12541255
case tc.ExpectISO:

0 commit comments

Comments
 (0)