-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add live-iso support #759
Add live-iso support #759
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,6 +372,7 @@ func (p *ironicProvisioner) ValidateManagementAccess(credentialsChanged, force b | |
BootInterface: p.bmcAccess.BootInterface(), | ||
Name: p.host.Name, | ||
DriverInfo: driverInfo, | ||
DeployInterface: p.deployInterface(), | ||
InspectInterface: "inspector", | ||
ManagementInterface: p.bmcAccess.ManagementInterface(), | ||
PowerInterface: p.bmcAccess.PowerInterface(), | ||
|
@@ -736,8 +737,72 @@ func (p *ironicProvisioner) getImageUpdateOptsForNode(ironicNode *nodes.Node, im | |
Value: string(p.host.ObjectMeta.UID), | ||
}, | ||
) | ||
// image_source | ||
// live-iso format | ||
var op nodes.UpdateOp | ||
if imageData.DiskFormat != nil && *imageData.DiskFormat == "live-iso" { | ||
if _, ok := ironicNode.InstanceInfo["boot_iso"]; !ok { | ||
op = nodes.AddOp | ||
p.log.Info("adding boot_iso") | ||
} else { | ||
op = nodes.ReplaceOp | ||
p.log.Info("updating boot_iso") | ||
} | ||
updates = append( | ||
updates, | ||
nodes.UpdateOperation{ | ||
Op: op, | ||
Path: "/instance_info/boot_iso", | ||
Value: imageData.URL, | ||
}, | ||
) | ||
updates = append( | ||
updates, | ||
nodes.UpdateOperation{ | ||
Op: nodes.ReplaceOp, | ||
Path: "/deploy_interface", | ||
hardys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Value: "ramdisk", | ||
}, | ||
) | ||
// remove any image_source or checksum options | ||
removals := []string{ | ||
"image_source", "image_os_hash_value", "image_os_hash_algo", "image_checksum"} | ||
op = nodes.RemoveOp | ||
for _, item := range removals { | ||
if _, ok := ironicNode.InstanceInfo[item]; ok { | ||
p.log.Info("removing " + item) | ||
updates = append( | ||
updates, | ||
nodes.UpdateOperation{ | ||
Op: op, | ||
Path: "/instance_info/" + item, | ||
}, | ||
) | ||
} | ||
} | ||
hardys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return updates, nil | ||
} | ||
|
||
// Set deploy_interface direct when not booting a live-iso | ||
updates = append( | ||
updates, | ||
nodes.UpdateOperation{ | ||
Op: nodes.ReplaceOp, | ||
Path: "/deploy_interface", | ||
Value: "direct", | ||
}, | ||
) | ||
// Remove any boot_iso field | ||
if _, ok := ironicNode.InstanceInfo["boot_iso"]; ok { | ||
p.log.Info("removing boot_iso") | ||
updates = append( | ||
updates, | ||
nodes.UpdateOperation{ | ||
Op: nodes.RemoveOp, | ||
Path: "/instance_info/boot_iso", | ||
}, | ||
) | ||
} | ||
// image_source | ||
if _, ok := ironicNode.InstanceInfo["image_source"]; !ok { | ||
op = nodes.AddOp | ||
p.log.Info("adding image_source") | ||
|
@@ -1016,6 +1081,14 @@ func (p *ironicProvisioner) setUpForProvisioning(ironicNode *nodes.Node, hostCon | |
return | ||
} | ||
|
||
func (p *ironicProvisioner) deployInterface() (result string) { | ||
result = "direct" | ||
if p.host.Spec.Image != nil && p.host.Spec.Image.DiskFormat != nil && *p.host.Spec.Image.DiskFormat == "live-iso" { | ||
result = "ramdisk" | ||
} | ||
return result | ||
} | ||
|
||
// Adopt allows an externally-provisioned server to be adopted by Ironic. | ||
func (p *ironicProvisioner) Adopt(force bool) (result provisioner.Result, err error) { | ||
var ironicNode *nodes.Node | ||
|
@@ -1058,6 +1131,30 @@ func (p *ironicProvisioner) Adopt(force bool) (result provisioner.Result, err er | |
return operationComplete() | ||
} | ||
|
||
func (p *ironicProvisioner) ironicHasSameImage(ironicNode *nodes.Node) (sameImage bool) { | ||
// To make it easier to test if ironic is configured with | ||
// the same image we are trying to provision to the host. | ||
if p.host.Spec.Image != nil && p.host.Spec.Image.DiskFormat != nil && *p.host.Spec.Image.DiskFormat == "live-iso" { | ||
sameImage = (ironicNode.InstanceInfo["boot_iso"] == p.host.Spec.Image.URL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not cleared from Ironic when switching back from live-iso to a regular boot, so it may not be operative. I think we should either clear it at the same time as setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah thanks, good catch - I updated I'm not sure adding an explicit check for deploy_interface here gains us much though, since in that case we expect That said, it does raise the question of whether we should check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree that doing both is redundant. (Wouldn't hurt, in a belt-and-braces sense, but this is fine too.) You make a good point though that if provisioning fails because you specified the wrong image format, and you then fix it, it currently won't retry, at least on paper. I'm not actually even 100% sure this code is still needed, since after a failure is first recorded we change the state to Deprovisioning. Definitely a question for elsewhere though. |
||
p.log.Info("checking image settings", | ||
"boot_iso", ironicNode.InstanceInfo["boot_iso"], | ||
"same", sameImage, | ||
"provisionState", ironicNode.ProvisionState) | ||
} else { | ||
checksum, checksumType, _ := p.host.GetImageChecksum() | ||
sameImage = (ironicNode.InstanceInfo["image_source"] == p.host.Spec.Image.URL && | ||
ironicNode.InstanceInfo["image_os_hash_algo"] == checksumType && | ||
ironicNode.InstanceInfo["image_os_hash_value"] == checksum) | ||
p.log.Info("checking image settings", | ||
"source", ironicNode.InstanceInfo["image_source"], | ||
"image_os_hash_algo", checksumType, | ||
"image_os_has_value", checksum, | ||
"same", sameImage, | ||
"provisionState", ironicNode.ProvisionState) | ||
} | ||
return sameImage | ||
} | ||
|
||
// Provision writes the image from the host spec to the host. It may | ||
// be called multiple times, and should return true for its dirty flag | ||
// until the deprovisioning operation is completed. | ||
|
@@ -1073,20 +1170,7 @@ func (p *ironicProvisioner) Provision(hostConf provisioner.HostConfigData) (resu | |
|
||
p.log.Info("provisioning image to host", "state", ironicNode.ProvisionState) | ||
|
||
checksum, checksumType, _ := p.host.GetImageChecksum() | ||
|
||
// Local variable to make it easier to test if ironic is | ||
// configured with the same image we are trying to provision to | ||
// the host. | ||
ironicHasSameImage := (ironicNode.InstanceInfo["image_source"] == p.host.Spec.Image.URL && | ||
ironicNode.InstanceInfo["image_os_hash_algo"] == checksumType && | ||
ironicNode.InstanceInfo["image_os_hash_value"] == checksum) | ||
p.log.Info("checking image settings", | ||
"source", ironicNode.InstanceInfo["image_source"], | ||
"image_os_hash_algo", checksumType, | ||
"image_os_has_value", checksum, | ||
"same", ironicHasSameImage, | ||
"provisionState", ironicNode.ProvisionState) | ||
ironicHasSameImage := p.ironicHasSameImage(ironicNode) | ||
|
||
// Ironic has the settings it needs, see if it finds any issues | ||
// with them. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A weird property of JSON patch (at least as applied in ironic): add can be used to replace values (but not the other way).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that sounds like a potential simplification we could address via a followup