Skip to content

Commit

Permalink
remove chroot top level context
Browse files Browse the repository at this point in the history
  • Loading branch information
JenGoldstrich committed Mar 28, 2024
1 parent 5674958 commit 06081ef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
5 changes: 0 additions & 5 deletions builder/azure/chroot/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"fmt"
"runtime"
"strings"
"time"

"github.com/hashicorp/packer-plugin-azure/builder/azure/common/log"

Expand Down Expand Up @@ -410,10 +409,6 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
return nil, errors.New("the azure-chroot builder only works on Linux and FreeBSD environments")
}

// All requests on the new (non auto rest) base layer of the azure SDK require a context with a timeout for polling purposes
ctx, topLevelCancel := context.WithTimeout(ctx, time.Hour*4)
defer topLevelCancel()

err := b.config.ClientConfig.FillParameters()
if err != nil {
return nil, fmt.Errorf("error setting Azure client defaults: %v", err)
Expand Down
6 changes: 2 additions & 4 deletions builder/azure/chroot/diskattacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,9 @@ func (da *diskAttacher) getThisVM(ctx context.Context) (hashiVMSDK.VirtualMachin
}
da.vm = vm
}

vmID := hashiVMSDK.NewVirtualMachineID(da.azcli.SubscriptionID(), da.vm.ResourceGroupName, da.vm.Name)
// retrieve actual VM
// TODO pass in polling context here
pollingContext, cancel := context.WithTimeout(ctx, time.Minute*5)
vmID := hashiVMSDK.NewVirtualMachineID(da.azcli.SubscriptionID(), da.vm.ResourceGroupName, da.vm.Name)
pollingContext, cancel := context.WithTimeout(ctx, da.azcli.PollingDuration())
defer cancel()
vmResource, err := da.azcli.VirtualMachinesClient().Get(pollingContext, vmID, hashiVMSDK.DefaultGetOperationOptions())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion builder/azure/chroot/step_create_new_diskset.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (s *StepCreateNewDiskset) Cleanup(state multistep.StateBag) {
for _, d := range s.disks {

ui.Say(fmt.Sprintf("Waiting for disk %q detach to complete", d))
err := NewDiskAttacher(azcli, ui).WaitForDetach(context.Background(), d.String())
err := NewDiskAttacher(azcli, ui).WaitForDetach(context.TODO(), d.String())
if err != nil {
ui.Error(fmt.Sprintf("error detaching disk %q: %s", d, err))
}
Expand Down
8 changes: 6 additions & 2 deletions builder/azure/chroot/step_verify_shared_image_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func (s *StepVerifySharedImageDestination) Run(ctx context.Context, state multis
s.Image.GalleryName,
s.Image.ImageName,
)
image, err := s.getImage(ctx, azcli, galleryImageID)
getImagePollingContext, getImageCancel := context.WithTimeout(ctx, azcli.PollingDuration())
defer getImageCancel()
image, err := s.getImage(getImagePollingContext, azcli, galleryImageID)

if err != nil {
return errorMessage("Error retrieving shared image %q: %+v ", imageURI, err)
Expand Down Expand Up @@ -108,7 +110,9 @@ func (s *StepVerifySharedImageDestination) Run(ctx context.Context, state multis
s.Image.GalleryName,
s.Image.ImageName,
)
versions, err := s.listVersions(ctx, azcli,
listVersionsCtx, listVersionsCancel := context.WithTimeout(ctx, azcli.PollingDuration())
defer listVersionsCancel()
versions, err := s.listVersions(listVersionsCtx, azcli,
galleryImageIDForList)

if err != nil {
Expand Down

0 comments on commit 06081ef

Please sign in to comment.