diff --git a/cloudmock/aws/mockautoscaling/group.go b/cloudmock/aws/mockautoscaling/group.go index 13d38bda1dd8b..b57126f31885e 100644 --- a/cloudmock/aws/mockautoscaling/group.go +++ b/cloudmock/aws/mockautoscaling/group.go @@ -17,6 +17,7 @@ limitations under the License. package mockautoscaling import ( + "context" "fmt" "time" @@ -44,7 +45,7 @@ func (m *MockAutoscaling) AttachInstances(input *autoscaling.AttachInstancesInpu return &autoscaling.AttachInstancesOutput{}, nil } -func (m *MockAutoscaling) CreateAutoScalingGroup(input *autoscaling.CreateAutoScalingGroupInput) (*autoscaling.CreateAutoScalingGroupOutput, error) { +func (m *MockAutoscaling) CreateAutoScalingGroupWithContext(ctx aws.Context, input *autoscaling.CreateAutoScalingGroupInput, options ...request.Option) (*autoscaling.CreateAutoScalingGroupOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() @@ -102,7 +103,7 @@ func (m *MockAutoscaling) CreateAutoScalingGroup(input *autoscaling.CreateAutoSc return &autoscaling.CreateAutoScalingGroupOutput{}, nil } -func (m *MockAutoscaling) UpdateAutoScalingGroup(request *autoscaling.UpdateAutoScalingGroupInput) (*autoscaling.UpdateAutoScalingGroupOutput, error) { +func (m *MockAutoscaling) UpdateAutoScalingGroupWithContext(ctx context.Context, request *autoscaling.UpdateAutoScalingGroupInput, opts ...request.Option) (*autoscaling.UpdateAutoScalingGroupOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() klog.V(2).Infof("Mock UpdateAutoScalingGroup %v", request) @@ -163,7 +164,7 @@ func (m *MockAutoscaling) UpdateAutoScalingGroup(request *autoscaling.UpdateAuto return &autoscaling.UpdateAutoScalingGroupOutput{}, nil } -func (m *MockAutoscaling) EnableMetricsCollection(request *autoscaling.EnableMetricsCollectionInput) (*autoscaling.EnableMetricsCollectionOutput, error) { +func (m *MockAutoscaling) EnableMetricsCollectionWithContext(ctx aws.Context, request *autoscaling.EnableMetricsCollectionInput, opts ...request.Option) (*autoscaling.EnableMetricsCollectionOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() @@ -195,7 +196,7 @@ func (m *MockAutoscaling) EnableMetricsCollection(request *autoscaling.EnableMet return response, nil } -func (m *MockAutoscaling) SuspendProcesses(input *autoscaling.ScalingProcessQuery) (*autoscaling.SuspendProcessesOutput, error) { +func (m *MockAutoscaling) SuspendProcessesWithContext(ctx aws.Context, input *autoscaling.ScalingProcessQuery, opts ...request.Option) (*autoscaling.SuspendProcessesOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() @@ -290,7 +291,7 @@ func (m *MockAutoscaling) DescribeAutoScalingGroupsRequest(*autoscaling.Describe return nil, nil } -func (m *MockAutoscaling) DescribeAutoScalingGroupsPages(request *autoscaling.DescribeAutoScalingGroupsInput, callback func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool) error { +func (m *MockAutoscaling) DescribeAutoScalingGroupsPagesWithContext(ctx aws.Context, request *autoscaling.DescribeAutoScalingGroupsInput, callback func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool, options ...request.Option) error { if request.MaxRecords != nil { klog.Fatalf("MaxRecords not implemented") } @@ -309,12 +310,11 @@ func (m *MockAutoscaling) DescribeAutoScalingGroupsPages(request *autoscaling.De return nil } -func (m *MockAutoscaling) DescribeAutoScalingGroupsPagesWithContext(aws.Context, *autoscaling.DescribeAutoScalingGroupsInput, func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool, ...request.Option) error { - klog.Fatalf("Not implemented") - return nil +func (m *MockAutoscaling) DescribeAutoScalingGroupsPages(request *autoscaling.DescribeAutoScalingGroupsInput, callback func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool) error { + return m.DescribeAutoScalingGroupsPagesWithContext(context.TODO(), request, callback) } -func (m *MockAutoscaling) DeleteAutoScalingGroup(request *autoscaling.DeleteAutoScalingGroupInput) (*autoscaling.DeleteAutoScalingGroupOutput, error) { +func (m *MockAutoscaling) DeleteAutoScalingGroupWithContext(ctx aws.Context, request *autoscaling.DeleteAutoScalingGroupInput, options ...request.Option) (*autoscaling.DeleteAutoScalingGroupOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() @@ -330,17 +330,12 @@ func (m *MockAutoscaling) DeleteAutoScalingGroup(request *autoscaling.DeleteAuto return &autoscaling.DeleteAutoScalingGroupOutput{}, nil } -func (m *MockAutoscaling) DeleteAutoScalingGroupWithContext(aws.Context, *autoscaling.DeleteAutoScalingGroupInput, ...request.Option) (*autoscaling.DeleteAutoScalingGroupOutput, error) { - klog.Fatalf("Not implemented") - return nil, nil -} - func (m *MockAutoscaling) DeleteAutoScalingGroupRequest(*autoscaling.DeleteAutoScalingGroupInput) (*request.Request, *autoscaling.DeleteAutoScalingGroupOutput) { klog.Fatalf("Not implemented") return nil, nil } -func (m *MockAutoscaling) PutLifecycleHook(input *autoscaling.PutLifecycleHookInput) (*autoscaling.PutLifecycleHookOutput, error) { +func (m *MockAutoscaling) PutLifecycleHookWithContext(ctx aws.Context, input *autoscaling.PutLifecycleHookInput, options ...request.Option) (*autoscaling.PutLifecycleHookOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() hook := &autoscaling.LifecycleHook{ @@ -364,7 +359,7 @@ func (m *MockAutoscaling) PutLifecycleHook(input *autoscaling.PutLifecycleHookIn return &autoscaling.PutLifecycleHookOutput{}, nil } -func (m *MockAutoscaling) DescribeLifecycleHooks(input *autoscaling.DescribeLifecycleHooksInput) (*autoscaling.DescribeLifecycleHooksOutput, error) { +func (m *MockAutoscaling) DescribeLifecycleHooksWithContext(ctx aws.Context, input *autoscaling.DescribeLifecycleHooksInput, options ...request.Option) (*autoscaling.DescribeLifecycleHooksOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/cloudmock/aws/mockautoscaling/tags.go b/cloudmock/aws/mockautoscaling/tags.go index f3ca923d542cd..e92b5f0a3e077 100644 --- a/cloudmock/aws/mockautoscaling/tags.go +++ b/cloudmock/aws/mockautoscaling/tags.go @@ -72,7 +72,7 @@ func (m *MockAutoscaling) DescribeTagsRequest(*autoscaling.DescribeTagsInput) (* return nil, nil } -func (m *MockAutoscaling) DescribeTagsPages(request *autoscaling.DescribeTagsInput, callback func(*autoscaling.DescribeTagsOutput, bool) bool) error { +func (m *MockAutoscaling) DescribeTagsPagesWithContext(ctx aws.Context, request *autoscaling.DescribeTagsInput, callback func(*autoscaling.DescribeTagsOutput, bool) bool, options ...request.Option) error { // For the mock, we just send everything in one page page, err := m.DescribeTags(request) if err != nil { @@ -83,8 +83,3 @@ func (m *MockAutoscaling) DescribeTagsPages(request *autoscaling.DescribeTagsInp return nil } - -func (m *MockAutoscaling) DescribeTagsPagesWithContext(aws.Context, *autoscaling.DescribeTagsInput, func(*autoscaling.DescribeTagsOutput, bool) bool, ...request.Option) error { - klog.Fatalf("Not implemented") - return nil -} diff --git a/cloudmock/aws/mockautoscaling/warmpool.go b/cloudmock/aws/mockautoscaling/warmpool.go index 841d48e348470..51de5bfa5bfb5 100644 --- a/cloudmock/aws/mockautoscaling/warmpool.go +++ b/cloudmock/aws/mockautoscaling/warmpool.go @@ -16,9 +16,13 @@ limitations under the License. package mockautoscaling -import "github.com/aws/aws-sdk-go/service/autoscaling" +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/request" + "github.com/aws/aws-sdk-go/service/autoscaling" +) -func (m *MockAutoscaling) DescribeWarmPool(input *autoscaling.DescribeWarmPoolInput) (*autoscaling.DescribeWarmPoolOutput, error) { +func (m *MockAutoscaling) DescribeWarmPoolWithContext(ctx aws.Context, input *autoscaling.DescribeWarmPoolInput, options ...request.Option) (*autoscaling.DescribeWarmPoolOutput, error) { instances, found := m.WarmPoolInstances[*input.AutoScalingGroupName] if !found { return &autoscaling.DescribeWarmPoolOutput{}, nil diff --git a/cloudmock/aws/mockec2/launch_templates.go b/cloudmock/aws/mockec2/launch_templates.go index 4aebef9fdb56d..4a24c3e1ab58a 100644 --- a/cloudmock/aws/mockec2/launch_templates.go +++ b/cloudmock/aws/mockec2/launch_templates.go @@ -17,10 +17,12 @@ limitations under the License. package mockec2 import ( + "context" "fmt" "strings" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/service/ec2" "k8s.io/klog/v2" ) @@ -43,6 +45,11 @@ func (m *MockEC2) DescribeLaunchTemplatesPages(request *ec2.DescribeLaunchTempla return nil } +// DescribeLaunchTemplatesPagesWithContext mocks the describing the launch templates +func (m *MockEC2) DescribeLaunchTemplatesPagesWithContext(ctx context.Context, request *ec2.DescribeLaunchTemplatesInput, callback func(*ec2.DescribeLaunchTemplatesOutput, bool) bool, option ...request.Option) error { + return m.DescribeLaunchTemplatesPages(request, callback) +} + // DescribeLaunchTemplates mocks the describing the launch templates func (m *MockEC2) DescribeLaunchTemplates(request *ec2.DescribeLaunchTemplatesInput) (*ec2.DescribeLaunchTemplatesOutput, error) { m.mutex.Lock() @@ -116,6 +123,11 @@ func (m *MockEC2) DescribeLaunchTemplateVersions(request *ec2.DescribeLaunchTemp return o, nil } +// DescribeLaunchTemplateVersionsWithContext mocks the retrieval of launch template versions - we don't use this at the moment so we can just return the template +func (m *MockEC2) DescribeLaunchTemplateVersionsWithContext(ctx context.Context, request *ec2.DescribeLaunchTemplateVersionsInput, option ...request.Option) (*ec2.DescribeLaunchTemplateVersionsOutput, error) { + return m.DescribeLaunchTemplateVersions(request) +} + // CreateLaunchTemplate mocks the ec2 create launch template func (m *MockEC2) CreateLaunchTemplate(request *ec2.CreateLaunchTemplateInput) (*ec2.CreateLaunchTemplateOutput, error) { m.mutex.Lock() diff --git a/pkg/instancegroups/rollingupdate_test.go b/pkg/instancegroups/rollingupdate_test.go index 767aca626b1df..af449ec554d09 100644 --- a/pkg/instancegroups/rollingupdate_test.go +++ b/pkg/instancegroups/rollingupdate_test.go @@ -26,6 +26,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface" "github.com/aws/aws-sdk-go/service/ec2" @@ -137,6 +138,8 @@ func (v *assertNotCalledClusterValidator) Validate() (*validation.ValidationClus } func makeGroup(groups map[string]*cloudinstances.CloudInstanceGroup, k8sClient kubernetes.Interface, cloud awsup.AWSCloud, name string, role kopsapi.InstanceGroupRole, count int, needUpdate int) { + ctx := context.TODO() + fakeClient := k8sClient.(*fake.Clientset) group := &cloudinstances.CloudInstanceGroup{ @@ -153,7 +156,7 @@ func makeGroup(groups map[string]*cloudinstances.CloudInstanceGroup, k8sClient k } groups[name] = group - cloud.Autoscaling().CreateAutoScalingGroup(&autoscaling.CreateAutoScalingGroupInput{ + cloud.Autoscaling().CreateAutoScalingGroupWithContext(ctx, &autoscaling.CreateAutoScalingGroupInput{ AutoScalingGroupName: aws.String(name), DesiredCapacity: aws.Int64(int64(count)), MinSize: aws.Int64(1), @@ -938,7 +941,7 @@ type disabledSurgeTest struct { numDetached int } -func (m *disabledSurgeTest) DetachInstances(input *autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) { +func (m *disabledSurgeTest) DetachInstancesWithContext(ctx context.Context, input *autoscaling.DetachInstancesInput, option ...request.Option) (*autoscaling.DetachInstancesOutput, error) { m.mutex.Lock() defer m.mutex.Unlock() @@ -1233,7 +1236,7 @@ type concurrentTestAutoscaling struct { ConcurrentTest *concurrentTest } -func (m *concurrentTestAutoscaling) DetachInstances(input *autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) { +func (m *concurrentTestAutoscaling) DetachInstancesWithContext(ctx context.Context, input *autoscaling.DetachInstancesInput, option ...request.Option) (*autoscaling.DetachInstancesOutput, error) { m.ConcurrentTest.mutex.Lock() defer m.ConcurrentTest.mutex.Unlock() @@ -1315,7 +1318,7 @@ type countDetach struct { Count int } -func (c *countDetach) DetachInstances(input *autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) { +func (c *countDetach) DetachInstancesWithContext(ctx context.Context, input *autoscaling.DetachInstancesInput, option ...request.Option) (*autoscaling.DetachInstancesOutput, error) { c.Count += len(input.InstanceIds) return &autoscaling.DetachInstancesOutput{}, nil } @@ -1345,7 +1348,7 @@ type failDetachAutoscaling struct { autoscalingiface.AutoScalingAPI } -func (m *failDetachAutoscaling) DetachInstances(input *autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) { +func (m *failDetachAutoscaling) DetachInstancesWithContext(ctx context.Context, input *autoscaling.DetachInstancesInput, option ...request.Option) (*autoscaling.DetachInstancesOutput, error) { return nil, fmt.Errorf("testing error") } @@ -1453,7 +1456,7 @@ type alreadyDetachedTestAutoscaling struct { AlreadyDetachedTest *alreadyDetachedTest } -func (m *alreadyDetachedTestAutoscaling) DetachInstances(input *autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) { +func (m *alreadyDetachedTestAutoscaling) DetachInstancesWithContext(ctx aws.Context, input *autoscaling.DetachInstancesInput, options ...request.Option) (*autoscaling.DetachInstancesOutput, error) { m.AlreadyDetachedTest.mutex.Lock() defer m.AlreadyDetachedTest.mutex.Unlock() diff --git a/pkg/resources/aws/aws.go b/pkg/resources/aws/aws.go index 6c153f2e2401b..42f95fe7831ad 100644 --- a/pkg/resources/aws/aws.go +++ b/pkg/resources/aws/aws.go @@ -17,6 +17,7 @@ limitations under the License. package aws import ( + "context" "errors" "fmt" "strings" @@ -1199,6 +1200,8 @@ func DescribeEgressOnlyInternetGateways(cloud fi.Cloud) ([]*ec2.EgressOnlyIntern } func DeleteAutoScalingGroup(cloud fi.Cloud, r *resources.Resource) error { + ctx := context.TODO() + c := cloud.(awsup.AWSCloud) id := r.ID @@ -1208,7 +1211,7 @@ func DeleteAutoScalingGroup(cloud fi.Cloud, r *resources.Resource) error { AutoScalingGroupName: &id, ForceDelete: aws.Bool(true), } - _, err := c.Autoscaling().DeleteAutoScalingGroup(request) + _, err := c.Autoscaling().DeleteAutoScalingGroupWithContext(ctx, request) if err != nil { if IsDependencyViolation(err) { return err diff --git a/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go b/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go index 3216e4f05343b..02b6a87983d10 100644 --- a/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go +++ b/upup/pkg/fi/cloudup/awstasks/autoscalinggroup.go @@ -17,6 +17,7 @@ limitations under the License. package awstasks import ( + "context" "fmt" "reflect" "sort" @@ -137,9 +138,11 @@ func (e *AutoscalingGroup) GetDependencies(tasks map[string]fi.CloudupTask) []fi // Find is used to discover the ASG in the cloud provider func (e *AutoscalingGroup) Find(c *fi.CloudupContext) (*AutoscalingGroup, error) { + ctx := c.Context() + cloud := c.T.Cloud.(awsup.AWSCloud) - g, err := findAutoscalingGroup(cloud, fi.ValueOf(e.Name)) + g, err := findAutoscalingGroup(ctx, cloud, fi.ValueOf(e.Name)) if err != nil { return nil, err } @@ -305,13 +308,13 @@ func (e *AutoscalingGroup) Find(c *fi.CloudupContext) (*AutoscalingGroup, error) } // findAutoscalingGroup is responsible for finding all the autoscaling groups for us -func findAutoscalingGroup(cloud awsup.AWSCloud, name string) (*autoscaling.Group, error) { +func findAutoscalingGroup(ctx context.Context, cloud awsup.AWSCloud, name string) (*autoscaling.Group, error) { request := &autoscaling.DescribeAutoScalingGroupsInput{ AutoScalingGroupNames: []*string{&name}, } var found []*autoscaling.Group - err := cloud.Autoscaling().DescribeAutoScalingGroupsPages(request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) (shouldContinue bool) { + err := cloud.Autoscaling().DescribeAutoScalingGroupsPagesWithContext(ctx, request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) (shouldContinue bool) { for _, g := range p.AutoScalingGroups { // Check for "Delete in progress" (the only use .Status). We won't be able to update or create while // this is true, but filtering it out here makes the messages slightly clearer. @@ -368,6 +371,8 @@ func (e *AutoscalingGroup) CheckChanges(a, ex, changes *AutoscalingGroup) error // RenderAWS is responsible for building the autoscaling group via AWS API func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *AutoscalingGroup) error { + ctx := context.TODO() + // @step: did we find an autoscaling group? if a == nil { klog.V(2).Infof("Creating autoscaling group with name: %s", fi.ValueOf(e.Name)) @@ -445,7 +450,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos } // @step: attempt to create the autoscaling group for us - if _, err := t.Cloud.Autoscaling().CreateAutoScalingGroup(request); err != nil { + if _, err := t.Cloud.Autoscaling().CreateAutoScalingGroupWithContext(ctx, request); err != nil { code := awsup.AWSErrorCode(err) message := awsup.AWSErrorMessage(err) if code == "ValidationError" && strings.Contains(message, "Invalid IAM Instance Profile name") { @@ -456,7 +461,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos } // @step: attempt to enable the metrics for us - if _, err := t.Cloud.Autoscaling().EnableMetricsCollection(&autoscaling.EnableMetricsCollectionInput{ + if _, err := t.Cloud.Autoscaling().EnableMetricsCollectionWithContext(ctx, &autoscaling.EnableMetricsCollectionInput{ AutoScalingGroupName: e.Name, Granularity: e.Granularity, Metrics: aws.StringSlice(e.Metrics), @@ -474,7 +479,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos processQuery.AutoScalingGroupName = e.Name processQuery.ScalingProcesses = toSuspend - if _, err := t.Cloud.Autoscaling().SuspendProcesses(processQuery); err != nil { + if _, err := t.Cloud.Autoscaling().SuspendProcessesWithContext(ctx, processQuery); err != nil { return fmt.Errorf("error suspending processes: %v", err) } } @@ -632,7 +637,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos if changes.Metrics != nil || changes.Granularity != nil { // TODO: Support disabling metrics? if len(e.Metrics) != 0 { - _, err := t.Cloud.Autoscaling().EnableMetricsCollection(&autoscaling.EnableMetricsCollectionInput{ + _, err := t.Cloud.Autoscaling().EnableMetricsCollectionWithContext(ctx, &autoscaling.EnableMetricsCollectionInput{ AutoScalingGroupName: e.Name, Granularity: e.Granularity, Metrics: aws.StringSlice(e.Metrics), @@ -654,7 +659,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos suspendProcessQuery.AutoScalingGroupName = e.Name suspendProcessQuery.ScalingProcesses = toSuspend - _, err := t.Cloud.Autoscaling().SuspendProcesses(suspendProcessQuery) + _, err := t.Cloud.Autoscaling().SuspendProcessesWithContext(ctx, suspendProcessQuery) if err != nil { return fmt.Errorf("error suspending processes: %v", err) } @@ -664,7 +669,7 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos resumeProcessQuery.AutoScalingGroupName = e.Name resumeProcessQuery.ScalingProcesses = toResume - _, err := t.Cloud.Autoscaling().ResumeProcesses(resumeProcessQuery) + _, err := t.Cloud.Autoscaling().ResumeProcessesWithContext(ctx, resumeProcessQuery) if err != nil { return fmt.Errorf("error resuming processes: %v", err) } @@ -689,41 +694,41 @@ func (v *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos klog.V(2).Infof("Updating autoscaling group %s", fi.ValueOf(e.Name)) - if _, err := t.Cloud.Autoscaling().UpdateAutoScalingGroup(request); err != nil { + if _, err := t.Cloud.Autoscaling().UpdateAutoScalingGroupWithContext(ctx, request); err != nil { return fmt.Errorf("error updating AutoscalingGroup: %v", err) } if deleteTagsRequest != nil && len(deleteTagsRequest.Tags) > 0 { - if _, err := t.Cloud.Autoscaling().DeleteTags(deleteTagsRequest); err != nil { + if _, err := t.Cloud.Autoscaling().DeleteTagsWithContext(ctx, deleteTagsRequest); err != nil { return fmt.Errorf("error deleting old AutoscalingGroup tags: %v", err) } } if updateTagsRequest != nil { - if _, err := t.Cloud.Autoscaling().CreateOrUpdateTags(updateTagsRequest); err != nil { + if _, err := t.Cloud.Autoscaling().CreateOrUpdateTagsWithContext(ctx, updateTagsRequest); err != nil { return fmt.Errorf("error updating AutoscalingGroup tags: %v", err) } } if detachLBRequest != nil { - if _, err := t.Cloud.Autoscaling().DetachLoadBalancers(detachLBRequest); err != nil { + if _, err := t.Cloud.Autoscaling().DetachLoadBalancersWithContext(ctx, detachLBRequest); err != nil { return fmt.Errorf("error detatching LoadBalancers: %v", err) } } if attachLBRequest != nil { - if _, err := t.Cloud.Autoscaling().AttachLoadBalancers(attachLBRequest); err != nil { + if _, err := t.Cloud.Autoscaling().AttachLoadBalancersWithContext(ctx, attachLBRequest); err != nil { return fmt.Errorf("error attaching LoadBalancers: %v", err) } } if len(detachTGRequests) > 0 { for _, detachTGRequest := range detachTGRequests { - if _, err := t.Cloud.Autoscaling().DetachLoadBalancerTargetGroups(detachTGRequest); err != nil { + if _, err := t.Cloud.Autoscaling().DetachLoadBalancerTargetGroupsWithContext(ctx, detachTGRequest); err != nil { return fmt.Errorf("failed to detach target groups: %v", err) } } } if len(attachTGRequests) > 0 { for _, attachTGRequest := range attachTGRequests { - if _, err := t.Cloud.Autoscaling().AttachLoadBalancerTargetGroups(attachTGRequest); err != nil { + if _, err := t.Cloud.Autoscaling().AttachLoadBalancerTargetGroupsWithContext(ctx, attachTGRequest); err != nil { return fmt.Errorf("failed to attach target groups: %v", err) } } diff --git a/upup/pkg/fi/cloudup/awstasks/autoscalinglifecyclehook.go b/upup/pkg/fi/cloudup/awstasks/autoscalinglifecyclehook.go index d6428161a5b08..d8fef481f170f 100644 --- a/upup/pkg/fi/cloudup/awstasks/autoscalinglifecyclehook.go +++ b/upup/pkg/fi/cloudup/awstasks/autoscalinglifecyclehook.go @@ -17,6 +17,7 @@ limitations under the License. package awstasks import ( + "context" "fmt" "github.com/aws/aws-sdk-go/service/autoscaling" @@ -53,6 +54,7 @@ func (h *AutoscalingLifecycleHook) CompareWithID() *string { } func (h *AutoscalingLifecycleHook) Find(c *fi.CloudupContext) (*AutoscalingLifecycleHook, error) { + ctx := c.Context() cloud := c.T.Cloud.(awsup.AWSCloud) request := &autoscaling.DescribeLifecycleHooksInput{ @@ -60,7 +62,7 @@ func (h *AutoscalingLifecycleHook) Find(c *fi.CloudupContext) (*AutoscalingLifec LifecycleHookNames: []*string{h.GetHookName()}, } - response, err := cloud.Autoscaling().DescribeLifecycleHooks(request) + response, err := cloud.Autoscaling().DescribeLifecycleHooksWithContext(ctx, request) if err != nil { return nil, fmt.Errorf("error listing ASG Lifecycle Hooks: %v", err) } @@ -109,6 +111,8 @@ func (_ *AutoscalingLifecycleHook) CheckChanges(a, e, changes *AutoscalingLifecy } func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *AutoscalingLifecycleHook) error { + ctx := context.TODO() + if changes != nil { if fi.ValueOf(e.Enabled) { request := &autoscaling.PutLifecycleHookInput{ @@ -118,7 +122,7 @@ func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes LifecycleHookName: e.GetHookName(), LifecycleTransition: e.LifecycleTransition, } - _, err := t.Cloud.Autoscaling().PutLifecycleHook(request) + _, err := t.Cloud.Autoscaling().PutLifecycleHookWithContext(ctx, request) if err != nil { return err } @@ -127,7 +131,7 @@ func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes AutoScalingGroupName: e.AutoscalingGroup.Name, LifecycleHookName: e.GetHookName(), } - _, err := t.Cloud.Autoscaling().DeleteLifecycleHook(request) + _, err := t.Cloud.Autoscaling().DeleteLifecycleHookWithContext(ctx, request) if err != nil { return err } diff --git a/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go b/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go index 0a2d8d7dd3645..6c0cb5923be53 100644 --- a/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go +++ b/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go @@ -342,6 +342,8 @@ func (t *LaunchTemplate) Find(c *fi.CloudupContext) (*LaunchTemplate, error) { // findAllLaunchTemplates returns all the launch templates for us func (t *LaunchTemplate) findAllLaunchTemplates(c *fi.CloudupContext) ([]*ec2.LaunchTemplate, error) { + ctx := c.Context() + cloud, ok := c.T.Cloud.(awsup.AWSCloud) if !ok { return nil, fmt.Errorf("invalid cloud provider: %v, expected: %s", c.T.Cloud, "awsup.AWSCloud") @@ -357,7 +359,7 @@ func (t *LaunchTemplate) findAllLaunchTemplates(c *fi.CloudupContext) ([]*ec2.La } var list []*ec2.LaunchTemplate - err := cloud.EC2().DescribeLaunchTemplatesPages(input, func(p *ec2.DescribeLaunchTemplatesOutput, lastPage bool) (shouldContinue bool) { + err := cloud.EC2().DescribeLaunchTemplatesPagesWithContext(ctx, input, func(p *ec2.DescribeLaunchTemplatesOutput, lastPage bool) (shouldContinue bool) { list = append(list, p.LaunchTemplates...) return true }) @@ -370,6 +372,8 @@ func (t *LaunchTemplate) findAllLaunchTemplates(c *fi.CloudupContext) ([]*ec2.La // findLatestLaunchTemplateVersion returns the latest template version func (t *LaunchTemplate) findLatestLaunchTemplateVersion(c *fi.CloudupContext) (*ec2.LaunchTemplateVersion, error) { + ctx := c.Context() + cloud, ok := c.T.Cloud.(awsup.AWSCloud) if !ok { return nil, fmt.Errorf("invalid cloud provider: %v, expected: awsup.AWSCloud", c.T.Cloud) @@ -380,7 +384,7 @@ func (t *LaunchTemplate) findLatestLaunchTemplateVersion(c *fi.CloudupContext) ( Versions: []*string{aws.String("$Latest")}, } - output, err := cloud.EC2().DescribeLaunchTemplateVersions(input) + output, err := cloud.EC2().DescribeLaunchTemplateVersionsWithContext(ctx, input) if err != nil { if awsup.AWSErrorCode(err) == "InvalidLaunchTemplateName.NotFoundException" { klog.V(4).Infof("Got InvalidLaunchTemplateName.NotFoundException error describing latest launch template version: %q", aws.StringValue(t.Name)) diff --git a/upup/pkg/fi/cloudup/awstasks/warmpool.go b/upup/pkg/fi/cloudup/awstasks/warmpool.go index 521eb5e9e234c..0a797ff9d9258 100644 --- a/upup/pkg/fi/cloudup/awstasks/warmpool.go +++ b/upup/pkg/fi/cloudup/awstasks/warmpool.go @@ -17,6 +17,7 @@ limitations under the License. package awstasks import ( + "context" "fmt" "github.com/aws/aws-sdk-go/service/autoscaling" @@ -45,9 +46,10 @@ type WarmPool struct { // Find is used to discover the ASG in the cloud provider. func (e *WarmPool) Find(c *fi.CloudupContext) (*WarmPool, error) { + ctx := c.Context() cloud := c.T.Cloud.(awsup.AWSCloud) svc := cloud.Autoscaling() - warmPool, err := svc.DescribeWarmPool(&autoscaling.DescribeWarmPoolInput{ + warmPool, err := svc.DescribeWarmPoolWithContext(ctx, &autoscaling.DescribeWarmPoolInput{ AutoScalingGroupName: e.AutoscalingGroup.Name, }) if err != nil { @@ -85,6 +87,7 @@ func (*WarmPool) CheckChanges(a, e, changes *WarmPool) error { } func (*WarmPool) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *WarmPool) error { + ctx := context.TODO() svc := t.Cloud.Autoscaling() if changes != nil { if fi.ValueOf(e.Enabled) { @@ -99,7 +102,7 @@ func (*WarmPool) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *WarmPool) error MinSize: fi.PtrTo(minSize), } - _, err := svc.PutWarmPool(request) + _, err := svc.PutWarmPoolWithContext(ctx, request) if err != nil { if awsup.AWSErrorCode(err) == "ValidationError" { return fi.NewTryAgainLaterError("waiting for ASG to become ready").WithError(err) @@ -107,7 +110,7 @@ func (*WarmPool) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *WarmPool) error return fmt.Errorf("error modifying warm pool: %w", err) } } else if a != nil { - _, err := svc.DeleteWarmPool(&autoscaling.DeleteWarmPoolInput{ + _, err := svc.DeleteWarmPoolWithContext(ctx, &autoscaling.DeleteWarmPoolInput{ AutoScalingGroupName: e.AutoscalingGroup.Name, // We don't need to do any cleanup so, the faster the better ForceDelete: fi.PtrTo(true), diff --git a/upup/pkg/fi/cloudup/awsup/aws_cloud.go b/upup/pkg/fi/cloudup/awsup/aws_cloud.go index 9d49bcd25bd16..79919de7918c7 100644 --- a/upup/pkg/fi/cloudup/awsup/aws_cloud.go +++ b/upup/pkg/fi/cloudup/awsup/aws_cloud.go @@ -501,6 +501,8 @@ func NewEC2Filter(name string, values ...string) *ec2.Filter { // DeleteGroup deletes an aws autoscaling group func (c *awsCloudImplementation) DeleteGroup(g *cloudinstances.CloudInstanceGroup) error { + ctx := context.TODO() + if g.InstanceGroup != nil && g.InstanceGroup.Spec.Manager == kops.InstanceManagerKarpenter { return nil } @@ -508,17 +510,17 @@ func (c *awsCloudImplementation) DeleteGroup(g *cloudinstances.CloudInstanceGrou if c.spotinst != nil { if featureflag.SpotinstHybrid.Enabled() { if _, ok := g.Raw.(*autoscaling.Group); ok { - return deleteGroup(c, g) + return deleteGroup(ctx, c, g) } } return spotinst.DeleteInstanceGroup(c.spotinst, g) } - return deleteGroup(c, g) + return deleteGroup(ctx, c, g) } -func deleteGroup(c AWSCloud, g *cloudinstances.CloudInstanceGroup) error { +func deleteGroup(ctx context.Context, c AWSCloud, g *cloudinstances.CloudInstanceGroup) error { asg := g.Raw.(*autoscaling.Group) name := aws.StringValue(asg.AutoScalingGroupName) @@ -552,7 +554,7 @@ func deleteGroup(c AWSCloud, g *cloudinstances.CloudInstanceGroup) error { AutoScalingGroupName: aws.String(name), ForceDelete: aws.Bool(true), } - _, err := c.Autoscaling().DeleteAutoScalingGroup(request) + _, err := c.Autoscaling().DeleteAutoScalingGroupWithContext(ctx, request) if err != nil { return fmt.Errorf("error deleting autoscaling group %q: %v", name, err) } @@ -578,7 +580,7 @@ func deleteGroup(c AWSCloud, g *cloudinstances.CloudInstanceGroup) error { request := &autoscaling.DeleteLaunchConfigurationInput{ LaunchConfigurationName: aws.String(template), } - _, err := c.Autoscaling().DeleteLaunchConfiguration(request) + _, err := c.Autoscaling().DeleteLaunchConfigurationWithContext(ctx, request) if err != nil { return fmt.Errorf("error deleting autoscaling launch configuration %q: %v", template, err) } @@ -607,11 +609,13 @@ func (c *awsCloudImplementation) DeleteInstance(i *cloudinstances.CloudInstance) // DeregisterInstance drains a cloud instance and load balancers. func (c *awsCloudImplementation) DeregisterInstance(i *cloudinstances.CloudInstance) error { + ctx := context.TODO() + if c.spotinst != nil || i.CloudInstanceGroup.InstanceGroup.Spec.Manager == kops.InstanceManagerKarpenter { return nil } - err := deregisterInstance(c, i) + err := deregisterInstance(ctx, c, i) if err != nil { return fmt.Errorf("failed to deregister instance from loadBalancer before terminating: %v", err) } @@ -643,10 +647,10 @@ func deleteInstance(c AWSCloud, i *cloudinstances.CloudInstance) error { } // deregisterInstance ensures that the instance is fully drained/removed from all associated loadBalancers and targetGroups before termination. -func deregisterInstance(c AWSCloud, i *cloudinstances.CloudInstance) error { +func deregisterInstance(ctx context.Context, c AWSCloud, i *cloudinstances.CloudInstance) error { asg := i.CloudInstanceGroup.Raw.(*autoscaling.Group) - asgDetails, err := c.Autoscaling().DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{ + asgDetails, err := c.Autoscaling().DescribeAutoScalingGroupsWithContext(ctx, &autoscaling.DescribeAutoScalingGroupsInput{ AutoScalingGroupNames: []*string{asg.AutoScalingGroupName}, }) if err != nil { @@ -792,6 +796,8 @@ func deregisterInstanceFromTargetGroup(c AWSCloud, targetGroupArn string, instan // DetachInstance causes an aws instance to no longer be counted against the ASG's size limits. func (c *awsCloudImplementation) DetachInstance(i *cloudinstances.CloudInstance) error { + ctx := context.TODO() + if i.Status == cloudinstances.CloudInstanceStatusDetached { return nil } @@ -799,10 +805,10 @@ func (c *awsCloudImplementation) DetachInstance(i *cloudinstances.CloudInstance) return spotinst.DetachInstance(c.spotinst, i) } - return detachInstance(c, i) + return detachInstance(ctx, c, i) } -func detachInstance(c AWSCloud, i *cloudinstances.CloudInstance) error { +func detachInstance(ctx context.Context, c AWSCloud, i *cloudinstances.CloudInstance) error { id := i.ID if id == "" { return fmt.Errorf("id was not set on CloudInstance: %v", i) @@ -821,7 +827,7 @@ func detachInstance(c AWSCloud, i *cloudinstances.CloudInstance) error { ShouldDecrementDesiredCapacity: aws.Bool(false), } - if _, err := c.Autoscaling().DetachInstances(input); err != nil { + if _, err := c.Autoscaling().DetachInstancesWithContext(ctx, input); err != nil { return fmt.Errorf("error detaching instance %q: %v", id, err) } @@ -832,6 +838,8 @@ func detachInstance(c AWSCloud, i *cloudinstances.CloudInstance) error { // GetCloudGroups returns a groups of instances that back a kops instance groups func (c *awsCloudImplementation) GetCloudGroups(cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) { + ctx := context.TODO() + if c.spotinst != nil { sgroups, err := spotinst.GetCloudGroups(c.spotinst, cluster, instancegroups, warnUnmatched, nodes) if err != nil { @@ -839,7 +847,7 @@ func (c *awsCloudImplementation) GetCloudGroups(cluster *kops.Cluster, instanceg } if featureflag.SpotinstHybrid.Enabled() { - agroups, err := getCloudGroups(c, cluster, instancegroups, warnUnmatched, nodes) + agroups, err := getCloudGroups(ctx, c, cluster, instancegroups, warnUnmatched, nodes) if err != nil { return nil, err } @@ -852,7 +860,7 @@ func (c *awsCloudImplementation) GetCloudGroups(cluster *kops.Cluster, instanceg return sgroups, nil } - cloudGroups, err := getCloudGroups(c, cluster, instancegroups, warnUnmatched, nodes) + cloudGroups, err := getCloudGroups(ctx, c, cluster, instancegroups, warnUnmatched, nodes) if err != nil { return nil, err } @@ -978,7 +986,7 @@ func buildKarpenterGroup(c AWSCloud, cluster *kops.Cluster, ig *kops.InstanceGro return karpenterGroup, nil } -func getCloudGroups(c AWSCloud, cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) { +func getCloudGroups(ctx context.Context, c AWSCloud, cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) { nodeMap := cloudinstances.GetNodeMap(nodes, cluster) groups := make(map[string]*cloudinstances.CloudInstanceGroup) @@ -1001,7 +1009,7 @@ func getCloudGroups(c AWSCloud, cluster *kops.Cluster, instancegroups []*kops.In continue } - groups[instancegroup.ObjectMeta.Name], err = awsBuildCloudInstanceGroup(c, cluster, instancegroup, asg, nodeMap) + groups[instancegroup.ObjectMeta.Name], err = awsBuildCloudInstanceGroup(ctx, c, cluster, instancegroup, asg, nodeMap) if err != nil { return nil, fmt.Errorf("error getting cloud instance group %q: %v", instancegroup.ObjectMeta.Name, err) } @@ -1013,6 +1021,8 @@ func getCloudGroups(c AWSCloud, cluster *kops.Cluster, instancegroups []*kops.In // FindAutoscalingGroups finds autoscaling groups matching the specified tags // This isn't entirely trivial because autoscaling doesn't let us filter with as much precision as we would like func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.Group, error) { + ctx := context.TODO() + var asgs []*autoscaling.Group klog.V(2).Infof("Listing all Autoscaling groups matching cluster tags") @@ -1030,7 +1040,7 @@ func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.G Filters: asFilters, } - err := c.Autoscaling().DescribeTagsPages(request, func(p *autoscaling.DescribeTagsOutput, lastPage bool) bool { + err := c.Autoscaling().DescribeTagsPagesWithContext(ctx, request, func(p *autoscaling.DescribeTagsOutput, lastPage bool) bool { for _, t := range p.Tags { switch *t.ResourceType { case "auto-scaling-group": @@ -1053,7 +1063,7 @@ func FindAutoscalingGroups(c AWSCloud, tags map[string]string) ([]*autoscaling.G request := &autoscaling.DescribeAutoScalingGroupsInput{ AutoScalingGroupNames: batch, } - err := c.Autoscaling().DescribeAutoScalingGroupsPages(request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) bool { + err := c.Autoscaling().DescribeAutoScalingGroupsPagesWithContext(ctx, request, func(p *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) bool { for _, asg := range p.AutoScalingGroups { if !matchesAsgTags(tags, asg.Tags) { // We used an inexact filter above @@ -1172,7 +1182,7 @@ func findInstanceLaunchConfiguration(i *autoscaling.Instance) string { return "" } -func awsBuildCloudInstanceGroup(c AWSCloud, cluster *kops.Cluster, ig *kops.InstanceGroup, g *autoscaling.Group, nodeMap map[string]*v1.Node) (*cloudinstances.CloudInstanceGroup, error) { +func awsBuildCloudInstanceGroup(ctx context.Context, c AWSCloud, cluster *kops.Cluster, ig *kops.InstanceGroup, g *autoscaling.Group, nodeMap map[string]*v1.Node) (*cloudinstances.CloudInstanceGroup, error) { newConfigName, err := findAutoscalingGroupLaunchConfiguration(c, g) if err != nil { return nil, err @@ -1200,7 +1210,7 @@ func awsBuildCloudInstanceGroup(c AWSCloud, cluster *kops.Cluster, ig *kops.Inst } } - result, err := c.Autoscaling().DescribeWarmPool(&autoscaling.DescribeWarmPoolInput{ + result, err := c.Autoscaling().DescribeWarmPoolWithContext(ctx, &autoscaling.DescribeWarmPoolInput{ AutoScalingGroupName: g.AutoScalingGroupName, }) if err != nil { diff --git a/upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go b/upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go index 82741ff774893..7a9d75f91155c 100644 --- a/upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go +++ b/upup/pkg/fi/cloudup/awsup/mock_aws_cloud.go @@ -17,6 +17,7 @@ limitations under the License. package awsup import ( + "context" "fmt" "github.com/aws/aws-sdk-go/aws" @@ -90,7 +91,9 @@ type MockCloud struct { } func (c *MockAWSCloud) DeleteGroup(g *cloudinstances.CloudInstanceGroup) error { - return deleteGroup(c, g) + ctx := context.TODO() + + return deleteGroup(ctx, c, g) } func (c *MockAWSCloud) DeleteInstance(i *cloudinstances.CloudInstance) error { @@ -102,11 +105,14 @@ func (c *MockAWSCloud) DeregisterInstance(i *cloudinstances.CloudInstance) error } func (c *MockAWSCloud) DetachInstance(i *cloudinstances.CloudInstance) error { - return detachInstance(c, i) + ctx := context.TODO() + + return detachInstance(ctx, c, i) } func (c *MockAWSCloud) GetCloudGroups(cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) { - return getCloudGroups(c, cluster, instancegroups, warnUnmatched, nodes) + ctx := context.TODO() + return getCloudGroups(ctx, c, cluster, instancegroups, warnUnmatched, nodes) } func (c *MockCloud) ProviderID() kops.CloudProviderID { diff --git a/upup/pkg/fi/nodeup/command.go b/upup/pkg/fi/nodeup/command.go index 412a8f36341c0..1388cc33a7330 100644 --- a/upup/pkg/fi/nodeup/command.go +++ b/upup/pkg/fi/nodeup/command.go @@ -244,7 +244,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error { } modelContext.InstanceID = string(instanceIDBytes) - modelContext.ConfigurationMode, err = getAWSConfigurationMode(modelContext) + modelContext.ConfigurationMode, err = getAWSConfigurationMode(ctx, modelContext) if err != nil { return err } @@ -364,7 +364,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error { if nodeupConfig.EnableLifecycleHook { if bootConfig.CloudProvider == api.CloudProviderAWS { - err := completeWarmingLifecycleAction(cloud.(awsup.AWSCloud), modelContext) + err := completeWarmingLifecycleAction(ctx, cloud.(awsup.AWSCloud), modelContext) if err != nil { return fmt.Errorf("failed to complete lifecylce action: %w", err) } @@ -388,11 +388,11 @@ func getMachineType() (string, error) { return instanceTypeName, err } -func completeWarmingLifecycleAction(cloud awsup.AWSCloud, modelContext *model.NodeupModelContext) error { +func completeWarmingLifecycleAction(ctx context.Context, cloud awsup.AWSCloud, modelContext *model.NodeupModelContext) error { asgName := modelContext.BootConfig.InstanceGroupName + "." + modelContext.NodeupConfig.ClusterName hookName := "kops-warmpool" svc := cloud.Autoscaling() - hooks, err := svc.DescribeLifecycleHooks(&autoscaling.DescribeLifecycleHooksInput{ + hooks, err := svc.DescribeLifecycleHooksWithContext(ctx, &autoscaling.DescribeLifecycleHooksInput{ AutoScalingGroupName: &asgName, LifecycleHookNames: []*string{&hookName}, }) @@ -402,7 +402,7 @@ func completeWarmingLifecycleAction(cloud awsup.AWSCloud, modelContext *model.No if len(hooks.LifecycleHooks) > 0 { klog.Info("Found ASG lifecycle hook") - _, err := svc.CompleteLifecycleAction(&autoscaling.CompleteLifecycleActionInput{ + _, err := svc.CompleteLifecycleActionWithContext(ctx, &autoscaling.CompleteLifecycleActionInput{ AutoScalingGroupName: &asgName, InstanceId: &modelContext.InstanceID, LifecycleHookName: &hookName, @@ -710,7 +710,7 @@ func getNodeConfigFromServers(ctx context.Context, bootConfig *nodeup.BootConfig return nil, merr } -func getAWSConfigurationMode(c *model.NodeupModelContext) (string, error) { +func getAWSConfigurationMode(ctx context.Context, c *model.NodeupModelContext) (string, error) { // Only worker nodes and apiservers can actually autoscale. // We are not adding describe permissions to the other roles role := c.BootConfig.InstanceGroupRole @@ -720,7 +720,7 @@ func getAWSConfigurationMode(c *model.NodeupModelContext) (string, error) { svc := c.Cloud.(awsup.AWSCloud).Autoscaling() - result, err := svc.DescribeAutoScalingInstances(&autoscaling.DescribeAutoScalingInstancesInput{ + result, err := svc.DescribeAutoScalingInstancesWithContext(ctx, &autoscaling.DescribeAutoScalingInstancesInput{ InstanceIds: []*string{&c.InstanceID}, }) if err != nil {