go.mod: update osbuild/images to v0.174.0

Also update the minimum required osbuild version by the osbuild/images
library.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2025-08-11 13:40:51 +02:00 committed by Tomáš Hozza
parent 3d0110f14e
commit 74d2edb772
110 changed files with 1218 additions and 1104 deletions

View file

@ -643,30 +643,29 @@ func (a *AWS) RunInstanceEC2(imageID, secGroupID, userData, instanceType string)
return reservation, nil
}
func (a *AWS) TerminateInstanceEC2(instanceID string) (*ec2.TerminateInstancesOutput, error) {
// We need to terminate the instance now and wait until the termination is done.
// Otherwise, it wouldn't be possible to delete the image.
// TerminateInstancesEC2 terminates the specified EC2 instances and waits for them to be terminated if timeout is greater than 0.
func (a *AWS) TerminateInstancesEC2(instanceIDs []string, timeout time.Duration) (*ec2.TerminateInstancesOutput, error) {
res, err := a.ec2.TerminateInstances(
context.TODO(),
&ec2.TerminateInstancesInput{
InstanceIds: []string{
instanceID,
},
InstanceIds: slices.Clone(instanceIDs),
})
if err != nil {
return nil, err
}
instanceWaiter := newTerminateInstancesWaiterEC2(a.ec2)
err = instanceWaiter.Wait(
context.TODO(),
&ec2.DescribeInstancesInput{
InstanceIds: []string{instanceID},
},
time.Hour,
)
if err != nil {
return nil, err
if timeout > 0 {
instanceWaiter := newTerminateInstancesWaiterEC2(a.ec2)
err = instanceWaiter.Wait(
context.TODO(),
&ec2.DescribeInstancesInput{
InstanceIds: slices.Clone(instanceIDs),
},
timeout,
)
if err != nil {
return nil, err
}
}
return res, nil
@ -681,30 +680,56 @@ func (a *AWS) GetInstanceAddress(instanceID string) (string, error) {
return *reservation.Instances[0].PublicIpAddress, nil
}
// DeleteEC2Image deletes the specified image and its associated snapshot
func (a *AWS) DeleteEC2Image(imageID, snapshotID string) error {
var retErr error
// DeleteEC2Image deletes the specified image and all of its associated snapshots
func (a *AWS) DeleteEC2Image(imageID string) error {
img, err := a.ec2.DescribeImages(
context.TODO(),
&ec2.DescribeImagesInput{
ImageIds: []string{imageID},
},
)
if err != nil {
return err
}
if len(img.Images) == 0 {
return fmt.Errorf("image %s not found", imageID)
}
var snapshotIDs []string
for _, bdm := range img.Images[0].BlockDeviceMappings {
if bdm.Ebs != nil && bdm.Ebs.SnapshotId != nil {
snapshotIDs = append(snapshotIDs, *bdm.Ebs.SnapshotId)
}
}
var retErr error
// firstly, deregister the image
_, err := a.ec2.DeregisterImage(
_, err = a.ec2.DeregisterImage(
context.TODO(),
&ec2.DeregisterImageInput{
ImageId: &imageID,
})
if err != nil {
return err
retErr = fmt.Errorf("failed to deregister image %s: %w", imageID, err)
}
// now it's possible to delete the snapshot
_, err = a.ec2.DeleteSnapshot(
context.TODO(),
&ec2.DeleteSnapshotInput{
SnapshotId: &snapshotID,
})
// now it's possible to delete snapshots
for _, snapshotID := range snapshotIDs {
_, err = a.ec2.DeleteSnapshot(
context.TODO(),
&ec2.DeleteSnapshotInput{
SnapshotId: &snapshotID,
})
if err != nil {
return err
if err != nil {
if retErr != nil {
retErr = fmt.Errorf("%w; failed to delete snapshot %s: %v", retErr, snapshotID, err)
continue
}
retErr = fmt.Errorf("failed to delete snapshot %s: %w", snapshotID, err)
}
}
return retErr