Skip to content

Commit d3b8408

Browse files
committed
updated ctx to be propagated , but that resulted in some tests being failed ,updated method signatures for tests to pass
1 parent 2528914 commit d3b8408

File tree

11 files changed

+44
-41
lines changed

11 files changed

+44
-41
lines changed

controllers/awsmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func (r *AWSMachineReconciler) createInstance(ctx context.Context, ec2svc servic
737737
return nil, errors.Wrapf(userDataErr, "failed to resolve userdata")
738738
}
739739

740-
instance, err := ec2svc.CreateInstance(machineScope, userData, userDataFormat)
740+
instance, err := ec2svc.CreateInstance(ctx, machineScope, userData, userDataFormat)
741741
if err != nil {
742742
return nil, errors.Wrapf(err, "failed to create AWSMachine instance")
743743
}

controllers/awsmachine_controller_unit_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func TestAWSMachineReconciler(t *testing.T) {
313313
expectedErr := errors.New("Invalid instance")
314314
ec2Svc.EXPECT().InstanceIfExists(gomock.Any()).Return(nil, nil)
315315
secretSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return("test", int32(1), nil).Times(1)
316-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, expectedErr)
316+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, expectedErr)
317317
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
318318

319319
_, err := reconciler.reconcileNormal(context.Background(), ms, cs, cs, cs, cs)
@@ -349,7 +349,7 @@ func TestAWSMachineReconciler(t *testing.T) {
349349
instance.State = infrav1.InstanceStatePending
350350

351351
ec2Svc.EXPECT().GetRunningInstanceByTags(gomock.Any()).Return(nil, nil)
352-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
352+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
353353
}
354354

355355
t.Run("instance security group errors", func(t *testing.T) {
@@ -785,7 +785,7 @@ func TestAWSMachineReconciler(t *testing.T) {
785785
return elbSvc
786786
}
787787

788-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
788+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
789789
ec2Svc.EXPECT().GetRunningInstanceByTags(gomock.Any()).Return(nil, nil)
790790
elbSvc.EXPECT().IsInstanceRegisteredWithAPIServerELB(gomock.Any()).Return(false, errors.New("error describing ELB"))
791791
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
@@ -811,7 +811,7 @@ func TestAWSMachineReconciler(t *testing.T) {
811811
return elbSvc
812812
}
813813

814-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
814+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
815815
ec2Svc.EXPECT().GetRunningInstanceByTags(gomock.Any()).Return(nil, nil)
816816
elbSvc.EXPECT().IsInstanceRegisteredWithAPIServerELB(gomock.Any()).Return(false, nil)
817817
elbSvc.EXPECT().RegisterInstanceWithAPIServerELB(gomock.Any()).Return(errors.New("failed to attach ELB"))
@@ -842,7 +842,7 @@ func TestAWSMachineReconciler(t *testing.T) {
842842
ensureTag := func(t *testing.T, g *WithT) {
843843
t.Helper()
844844
ec2Svc.EXPECT().InstanceIfExists(gomock.Any()).Return(nil, nil)
845-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
845+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
846846
secretSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return("test", int32(1), nil)
847847
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
848848
}
@@ -888,7 +888,7 @@ func TestAWSMachineReconciler(t *testing.T) {
888888
ensureSecurityGroups := func(t *testing.T, g *WithT) {
889889
t.Helper()
890890
ec2Svc.EXPECT().InstanceIfExists(gomock.Any()).Return(nil, nil)
891-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
891+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil)
892892
secretSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return("test", int32(1), nil)
893893
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil)
894894
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil)
@@ -1011,7 +1011,7 @@ func TestAWSMachineReconciler(t *testing.T) {
10111011

10121012
ec2Svc.EXPECT().GetRunningInstanceByTags(gomock.Any()).Return(nil, nil).AnyTimes()
10131013
secretSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return(secretPrefix, int32(1), nil).Times(1)
1014-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
1014+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
10151015
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
10161016
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil).Times(1)
10171017
ec2Svc.EXPECT().GetCoreSecurityGroups(gomock.Any()).Return([]string{}, nil).Times(1)
@@ -1048,7 +1048,7 @@ func TestAWSMachineReconciler(t *testing.T) {
10481048

10491049
ec2Svc.EXPECT().GetRunningInstanceByTags(gomock.Any()).Return(nil, nil).AnyTimes()
10501050
secretSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return(secretPrefix, int32(1), nil).Times(1)
1051-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
1051+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
10521052
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
10531053
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil).Times(1)
10541054
ec2Svc.EXPECT().GetCoreSecurityGroups(gomock.Any()).Return([]string{}, nil).Times(1)
@@ -1304,7 +1304,7 @@ func TestAWSMachineReconciler(t *testing.T) {
13041304
}
13051305
instance.State = infrav1.InstanceStatePending
13061306
secretSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return(secretPrefix, int32(1), nil).Times(1)
1307-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
1307+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
13081308
secretSvc.EXPECT().UserData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).Times(1)
13091309
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil).Times(1)
13101310
ec2Svc.EXPECT().GetCoreSecurityGroups(gomock.Any()).Return([]string{}, nil).Times(1)
@@ -1357,7 +1357,7 @@ func TestAWSMachineReconciler(t *testing.T) {
13571357
fakeS3URL := "s3://foo"
13581358

13591359
objectStoreSvc.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeS3URL, nil).Times(1)
1360-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
1360+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
13611361
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil).Times(1)
13621362
ec2Svc.EXPECT().GetCoreSecurityGroups(gomock.Any()).Return([]string{}, nil).Times(1)
13631363
ec2Svc.EXPECT().GetAdditionalSecurityGroupsIDs(gomock.Any()).Return(nil, nil)
@@ -1392,7 +1392,7 @@ func TestAWSMachineReconciler(t *testing.T) {
13921392
presigned := "https://cluster-api-aws.s3.us-west-2.amazonaws.com/bootstrap-data.yaml?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA3SGQVQG7FGA6KKA6%2F20221104%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20221104T140227Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=b228dbec8c1008c80c162e1210e4503dceead1e4d4751b4d9787314fd6da4d55"
13931393

13941394
objectStoreSvc.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any()).Return(presigned, nil).Times(1)
1395-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
1395+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
13961396
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil).Times(1)
13971397
ec2Svc.EXPECT().GetCoreSecurityGroups(gomock.Any()).Return([]string{}, nil).Times(1)
13981398
ec2Svc.EXPECT().GetAdditionalSecurityGroupsIDs(gomock.Any()).Return(nil, nil)
@@ -1611,7 +1611,7 @@ func TestAWSMachineReconciler(t *testing.T) {
16111611
// Expect no Cluster Object Store to be created.
16121612
objectStoreSvc.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any()).Return(fakeS3URL, nil).Times(0)
16131613

1614-
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
1614+
ec2Svc.EXPECT().CreateInstance(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(instance, nil).AnyTimes()
16151615
ec2Svc.EXPECT().GetInstanceSecurityGroups(gomock.Any()).Return(map[string][]string{"eid": {}}, nil).Times(1)
16161616
ec2Svc.EXPECT().GetCoreSecurityGroups(gomock.Any()).Return([]string{}, nil).Times(1)
16171617
ec2Svc.EXPECT().GetAdditionalSecurityGroupsIDs(gomock.Any()).Return(nil, nil)

exp/controllers/awsmachinepool_controller_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
703703
defer teardown(t, g)
704704

705705
ec2Svc.EXPECT().GetLaunchTemplate(gomock.Eq("test")).Return(nil, "", nil, nil, nil)
706-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-abcdef123"), nil)
706+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-abcdef123"), nil)
707707
ec2Svc.EXPECT().CreateLaunchTemplate(gomock.Any(), gomock.Eq(ptr.To[string]("ami-abcdef123")), gomock.Eq(userDataSecretKey), gomock.Eq([]byte("shell-script")), gomock.Eq(userdata.ComputeHash([]byte("shell-script")))).Return("lt-ghijkl456", nil)
708708
asgSvc.EXPECT().GetASGByName(gomock.Any()).Return(nil, nil)
709709
asgSvc.EXPECT().CreateASG(gomock.Any()).DoAndReturn(func(scope *scope.MachinePoolScope) (*expinfrav1.AutoScalingGroup, error) {
@@ -740,7 +740,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
740740
&userDataSecretKey,
741741
nil,
742742
nil)
743-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-existing"), nil) // no change
743+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-existing"), nil) // no change
744744
ec2Svc.EXPECT().LaunchTemplateNeedsUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
745745

746746
asgSvc.EXPECT().GetASGByName(gomock.Any()).DoAndReturn(func(scope *scope.MachinePoolScope) (*expinfrav1.AutoScalingGroup, error) {
@@ -789,7 +789,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
789789
&userDataSecretKey,
790790
nil,
791791
nil)
792-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-different"), nil)
792+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-different"), nil)
793793
ec2Svc.EXPECT().LaunchTemplateNeedsUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
794794
asgSvc.EXPECT().CanStartASGInstanceRefresh(gomock.Any()).Return(true, nil)
795795
ec2Svc.EXPECT().PruneLaunchTemplateVersions(gomock.Any()).Return(nil, nil)
@@ -845,7 +845,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
845845
&apimachinerytypes.NamespacedName{Namespace: "default", Name: "previous-secret-name"},
846846
nil,
847847
nil)
848-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
848+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
849849
ec2Svc.EXPECT().LaunchTemplateNeedsUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
850850
asgSvc.EXPECT().CanStartASGInstanceRefresh(gomock.Any()).Return(true, nil)
851851
ec2Svc.EXPECT().PruneLaunchTemplateVersions(gomock.Any()).Return(nil, nil)
@@ -887,7 +887,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
887887
defer teardown(t, g)
888888

889889
ec2Svc.EXPECT().GetLaunchTemplate(gomock.Eq("test")).Return(nil, "", nil, nil, nil)
890-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-abcdef123"), nil)
890+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-abcdef123"), nil)
891891
ec2Svc.EXPECT().CreateLaunchTemplate(gomock.Any(), gomock.Eq(ptr.To[string]("ami-abcdef123")), gomock.Eq(userDataSecretKey), gomock.Eq([]byte("shell-script")), gomock.Eq(userdata.ComputeHash([]byte("shell-script")))).Return("lt-ghijkl456", nil)
892892
asgSvc.EXPECT().GetASGByName(gomock.Any()).Return(nil, nil)
893893
asgSvc.EXPECT().CreateASG(gomock.Any()).DoAndReturn(func(scope *scope.MachinePoolScope) (*expinfrav1.AutoScalingGroup, error) {
@@ -931,7 +931,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
931931
&apimachinerytypes.NamespacedName{Namespace: "default", Name: "bootstrap-data"},
932932
nil,
933933
nil)
934-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
934+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
935935
ec2Svc.EXPECT().LaunchTemplateNeedsUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
936936
asgSvc.EXPECT().CanStartASGInstanceRefresh(gomock.Any()).Return(true, nil)
937937
ec2Svc.EXPECT().PruneLaunchTemplateVersions(gomock.Any()).Return(nil, nil)
@@ -1017,7 +1017,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
10171017
&apimachinerytypes.NamespacedName{Namespace: "default", Name: "previous-secret-name"},
10181018
nil,
10191019
nil)
1020-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
1020+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
10211021
ec2Svc.EXPECT().LaunchTemplateNeedsUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
10221022

10231023
s3Mock.EXPECT().PutObject(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, input *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {
@@ -1063,7 +1063,7 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
10631063
&apimachinerytypes.NamespacedName{Namespace: "default", Name: "previous-secret-name"},
10641064
nil,
10651065
nil)
1066-
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
1066+
ec2Svc.EXPECT().DiscoverLaunchTemplateAMI(gomock.Any(), gomock.Any()).Return(ptr.To[string]("ami-existing"), nil)
10671067
ec2Svc.EXPECT().LaunchTemplateNeedsUpdate(gomock.Any(), gomock.Any(), gomock.Any()).Return(false, nil)
10681068

10691069
s3Mock.EXPECT().PutObject(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, input *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {

pkg/cloud/services/ec2/ami.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (s *Service) defaultBastionAMILookup() (string, error) {
318318
return *latestImage.ImageId, nil
319319
}
320320

321-
func (s *Service) eksAMILookup(kubernetesVersion string, architecture string, amiType *infrav1.EKSAMILookupType) (string, error) {
321+
func (s *Service) eksAMILookup(ctx context.Context, kubernetesVersion string, architecture string, amiType *infrav1.EKSAMILookupType) (string, error) {
322322
// format ssm parameter path properly
323323
formattedVersion, err := formatVersionForEKS(kubernetesVersion)
324324
if err != nil {
@@ -359,7 +359,7 @@ func (s *Service) eksAMILookup(kubernetesVersion string, architecture string, am
359359
Name: aws.String(paramName),
360360
}
361361

362-
out, err := s.SSMClient.GetParameter(context.TODO(), input)
362+
out, err := s.SSMClient.GetParameter(ctx, input)
363363
if err != nil {
364364
record.Eventf(s.scope.InfraCluster(), "FailedGetParameter", "Failed to get ami SSM parameter %q: %v", paramName, err)
365365

pkg/cloud/services/ec2/ami_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ func TestEKSAMILookUp(t *testing.T) {
571571
s := NewService(clusterScope)
572572
s.SSMClient = ssmMock
573573

574-
got, err := s.eksAMILookup(tt.k8sVersion, tt.arch, tt.amiType)
574+
ctx := context.TODO()
575+
got, err := s.eksAMILookup(ctx, tt.k8sVersion, tt.arch, tt.amiType)
575576
if tt.wantErr {
576577
g.Expect(err).To(HaveOccurred())
577578
return

pkg/cloud/services/ec2/instances.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error) {
108108
// CreateInstance runs an ec2 instance.
109109
//
110110
//nolint:gocyclo // this function has multiple processes to perform
111-
func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error) {
111+
func (s *Service) CreateInstance(ctx context.Context, scope *scope.MachineScope, userData []byte, userDataFormat string) (*infrav1.Instance, error) {
112112
s.scope.Debug("Creating an instance for a machine")
113113

114114
input := &infrav1.Instance{
@@ -164,7 +164,7 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
164164
}
165165

166166
if scope.IsEKSManaged() && imageLookupFormat == "" && imageLookupOrg == "" && imageLookupBaseOS == "" {
167-
input.ImageID, err = s.eksAMILookup(*scope.Machine.Spec.Version, imageArchitecture, scope.AWSMachine.Spec.AMI.EKSOptimizedLookupType)
167+
input.ImageID, err = s.eksAMILookup(ctx, *scope.Machine.Spec.Version, imageArchitecture, scope.AWSMachine.Spec.AMI.EKSOptimizedLookupType)
168168
if err != nil {
169169
return nil, err
170170
}

pkg/cloud/services/ec2/instances_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5720,7 +5720,7 @@ func TestCreateInstance(t *testing.T) {
57205720
s := NewService(clusterScope)
57215721
s.EC2Client = ec2Mock
57225722

5723-
instance, err := s.CreateInstance(machineScope, data, "")
5723+
instance, err := s.CreateInstance(context.TODO(), machineScope, data, "")
57245724
tc.check(instance, err)
57255725
})
57265726
}

pkg/cloud/services/ec2/launchtemplate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *Service) ReconcileLaunchTemplate(
8383
return err
8484
}
8585

86-
imageID, err := ec2svc.DiscoverLaunchTemplateAMI(scope)
86+
imageID, err := ec2svc.DiscoverLaunchTemplateAMI(ctx, scope)
8787
if err != nil {
8888
conditions.MarkFalse(scope.GetSetter(), expinfrav1.LaunchTemplateReadyCondition, expinfrav1.LaunchTemplateCreateFailedReason, clusterv1.ConditionSeverityError, "%s", err.Error())
8989
return err
@@ -981,7 +981,7 @@ func (s *Service) LaunchTemplateNeedsUpdate(scope scope.LaunchTemplateScope, inc
981981
}
982982

983983
// DiscoverLaunchTemplateAMI will discover the AMI launch template.
984-
func (s *Service) DiscoverLaunchTemplateAMI(scope scope.LaunchTemplateScope) (*string, error) {
984+
func (s *Service) DiscoverLaunchTemplateAMI(ctx context.Context, scope scope.LaunchTemplateScope) (*string, error) {
985985
lt := scope.GetLaunchTemplate()
986986

987987
if lt.AMI.ID != nil {
@@ -1029,6 +1029,7 @@ func (s *Service) DiscoverLaunchTemplateAMI(scope scope.LaunchTemplateScope) (*s
10291029

10301030
if scope.IsEKSManaged() && imageLookupFormat == "" && imageLookupOrg == "" && imageLookupBaseOS == "" {
10311031
lookupAMI, err = s.eksAMILookup(
1032+
ctx,
10321033
*templateVersion,
10331034
imageArchitecture,
10341035
scope.GetLaunchTemplate().AMI.EKSOptimizedLookupType,

pkg/cloud/services/ec2/launchtemplate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ func TestDiscoverLaunchTemplateAMI(t *testing.T) {
19221922
s := NewService(cs)
19231923
s.EC2Client = ec2Mock
19241924

1925-
id, err := s.DiscoverLaunchTemplateAMI(ms)
1925+
id, err := s.DiscoverLaunchTemplateAMI(context.TODO(), ms)
19261926
tc.check(g, id, err)
19271927
})
19281928
}
@@ -1999,7 +1999,7 @@ func TestDiscoverLaunchTemplateAMIForEKS(t *testing.T) {
19991999
s.EC2Client = ec2Mock
20002000
s.SSMClient = ssmMock
20012001

2002-
id, err := s.DiscoverLaunchTemplateAMI(ms)
2002+
id, err := s.DiscoverLaunchTemplateAMI(context.TODO(), ms)
20032003
tc.check(g, id, err)
20042004
})
20052005
}

0 commit comments

Comments
 (0)