Skip to content
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

perf(creation): remove polling from creation #249

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions pkg/fake/virtualmachineextensionsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (c *VirtualMachineExtensionsAPI) BeginCreateOrUpdate(_ context.Context, res
})
}

func (c *VirtualMachineExtensionsAPI) Get(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, options *armcompute.VirtualMachineExtensionsClientGetOptions) (armcompute.VirtualMachineExtensionsClientGetResponse, error) {
return armcompute.VirtualMachineExtensionsClientGetResponse{}, nil
}

func mkVMExtensionID(resourceGroupName, vmName, extensionName string) string {
const idFormat = "/subscriptions/subscriptionID/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s/extensions/%s"
return fmt.Sprintf(idFormat, resourceGroupName, vmName, extensionName)
Expand Down
12 changes: 6 additions & 6 deletions pkg/providers/instance/armutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
)

func CreateVirtualMachine(ctx context.Context, client VirtualMachinesAPI, rg, vmName string, vm armcompute.VirtualMachine) (*armcompute.VirtualMachine, error) {
poller, err := client.BeginCreateOrUpdate(ctx, rg, vmName, vm, nil)
_, err := client.BeginCreateOrUpdate(ctx, rg, vmName, vm, nil)
if err != nil {
return nil, err
}
res, err := poller.PollUntilDone(ctx, nil)
vmget, err := client.Get(ctx, rg, vmName, nil)
if err != nil {
return nil, err
}
return &res.VirtualMachine, nil
return &vmget.VirtualMachine, nil
}

func UpdateVirtualMachine(ctx context.Context, client VirtualMachinesAPI, rg, vmName string, updates armcompute.VirtualMachineUpdate) error {
Expand Down Expand Up @@ -64,15 +64,15 @@ func deleteVirtualMachine(ctx context.Context, client VirtualMachinesAPI, rg, vm
}

func createVirtualMachineExtension(ctx context.Context, client VirtualMachineExtensionsAPI, rg, vmName, extensionName string, vmExt armcompute.VirtualMachineExtension) (*armcompute.VirtualMachineExtension, error) {
poller, err := client.BeginCreateOrUpdate(ctx, rg, vmName, extensionName, vmExt, nil)
_, err := client.BeginCreateOrUpdate(ctx, rg, vmName, extensionName, vmExt, nil)
if err != nil {
return nil, err
}
res, err := poller.PollUntilDone(ctx, nil)
getExt, err := client.Get(ctx, rg, vmName, extensionName, nil)
if err != nil {
return nil, err
}
return &res.VirtualMachineExtension, nil
return &getExt.VirtualMachineExtension, nil
}

func createNic(ctx context.Context, client NetworkInterfacesAPI, rg, nicName string, nic armnetwork.Interface) (*armnetwork.Interface, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/instance/azure_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type AzureResourceGraphAPI interface {

type VirtualMachineExtensionsAPI interface {
BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, extensionParameters armcompute.VirtualMachineExtension, options *armcompute.VirtualMachineExtensionsClientBeginCreateOrUpdateOptions) (*runtime.Poller[armcompute.VirtualMachineExtensionsClientCreateOrUpdateResponse], error)
Get(ctx context.Context, resourceGroupName string, vmName string, vmExtensionName string, options *armcompute.VirtualMachineExtensionsClientGetOptions) (armcompute.VirtualMachineExtensionsClientGetResponse, error)
}

type NetworkInterfacesAPI interface {
Expand Down
5 changes: 2 additions & 3 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,8 @@ func setVMPropertiesBillingProfile(vmProperties *armcompute.VirtualMachineProper

// setVMTagsProvisionerName sets "karpenter.sh/provisioner-name" tag
func setVMTagsProvisionerName(tags map[string]*string, nodeClaim *corev1beta1.NodeClaim) {
if val, ok := nodeClaim.Labels[corev1beta1.NodePoolLabelKey]; ok {
tags[NodePoolTagKey] = &val
}
nodePoolLabel := nodeClaim.Labels[corev1beta1.NodePoolLabelKey]
tags[NodePoolTagKey] = &nodePoolLabel
Comment on lines -383 to +384
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we change this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. This is unrelated to the change.

Pretty sure its a bug I found months back. Will separate it out into a new PR.

}

func (p *Provider) createVirtualMachine(ctx context.Context, vm armcompute.VirtualMachine, vmName string) (*armcompute.VirtualMachine, error) {
Expand Down
Loading