-
Notifications
You must be signed in to change notification settings - Fork 0
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
Remove Template Capture from ARM Builder And Fail Fast when SIG Version already exists #3
Conversation
…eplicated to DTL/Chroot
@@ -206,6 +203,14 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) | |||
if err != nil { | |||
return nil, fmt.Errorf("the Shared Gallery Image '%s' to which to publish the managed image version to does not exist in the resource group '%s' or does not contain managed image '%s'", b.config.SharedGalleryDestination.SigDestinationGalleryName, b.config.SharedGalleryDestination.SigDestinationResourceGroup, b.config.SharedGalleryDestination.SigDestinationImageName) | |||
} | |||
|
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.
This change allows us to fail faster when the SIG version we're already publishing to exists, this would previously fail after the creation of the Build VM when trying to create the SIG version
s.say("Capturing VHD ...") | ||
err = s.captureVhd(ctx, vmId, vmCaptureParameters) | ||
if err != nil { | ||
state.Put(constants.Error, err) |
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.
This code is a bit messy now but I was having errors where the error was not correctly being passed into nested loops, so this felt simpler
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.
Couple suggestions/questions, but the code looks good to me, it's always nice to see some HACK
removed :)
Good job!
return nil | ||
} | ||
|
||
// HACK(chrboum): This method is a hack. It was written to work around this issue |
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.
Love it when we remove code that starts with a comment like this one :D
vmId := vmResponse.Model.Properties.VMId | ||
return *vmId, nil | ||
} | ||
return "", nil |
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.
I wonder when does that happen? Shouldn't that be an error if no ID is found in this case?
return "", err | ||
} | ||
if vmResponse.Model != nil { | ||
vmId := vmResponse.Model.Properties.VMId |
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.
Also, don't know how likely it is to happen, but can Properties
be nil
here? If so this will crash upon dereferencing it.
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.
TBH I think I need to standardize this across the plugin, null checking returned Models/properties from the new SDK, so I'd like to push off figuring that out to a later PR
state.Put(constants.Error, err) | ||
s.error(err) | ||
return multistep.ActionHalt | ||
} else { |
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.
Since the if
ends with a return
statement, you can remove this else
and move the contents one level up
state.Put(constants.Error, err) | ||
s.error(err) | ||
return multistep.ActionHalt | ||
} else { |
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.
Same here, this else
is unnecessary since the if
ends with a return
Remove Template Capture, defeating a legacy TODO from 2016!
There's a lot of history here but the TL;Dr is we had to use TemplateCapture to get the
VMID
a UUID that is an internal ID that is used when capturing a VHD with the plugin. We can just query the VM API now though unlike in 2016 to get this ID, removing the need for this messy solution