From 4ad12d232e7133089841d4fe0eb70aedd89b0e19 Mon Sep 17 00:00:00 2001 From: "justin.miron" Date: Fri, 29 Mar 2024 11:00:22 -0500 Subject: [PATCH] Reduce ec2 instance controller API calls The EC2 instance controller synchronously makes several DescribeInstanceAttribut calls to the EC2 API and does not use the results. This slows down the reconcile time for a single observation. This removes the API calls for attributes that are returned in `RunInstances`. Signed-off-by: justin.miron (cherry picked from commit ac631f9a3730a494f7655a9b54553d2384aa16a5) --- pkg/clients/ec2/instance.go | 4 ++-- pkg/controller/ec2/instance/controller.go | 20 -------------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/pkg/clients/ec2/instance.go b/pkg/clients/ec2/instance.go index ac6eff7103..a62659da33 100644 --- a/pkg/clients/ec2/instance.go +++ b/pkg/clients/ec2/instance.go @@ -190,8 +190,8 @@ func LateInitializeInstance(in *manualv1alpha1.InstanceParameters, instance *typ in.InstanceInitiatedShutdownBehavior = pointer.LateInitializeValueFromPtr(in.InstanceInitiatedShutdownBehavior, attributes.InstanceInitiatedShutdownBehavior.Value) } - if attributes.InstanceType != nil { - in.InstanceType = pointer.LateInitializeValueFromPtr(in.InstanceType, attributes.InstanceType.Value) + if in.InstanceType == "" { + in.InstanceType = string(instance.InstanceType) } if attributes.UserData != nil { diff --git a/pkg/controller/ec2/instance/controller.go b/pkg/controller/ec2/instance/controller.go index 45ceeaf9f9..b81e3c5c3a 100644 --- a/pkg/controller/ec2/instance/controller.go +++ b/pkg/controller/ec2/instance/controller.go @@ -158,11 +158,7 @@ func (e *external) Observe(ctx context.Context, mgd resource.Managed) (managed.E for _, input := range []types.InstanceAttributeName{ types.InstanceAttributeNameDisableApiTermination, - types.InstanceAttributeNameEbsOptimized, types.InstanceAttributeNameInstanceInitiatedShutdownBehavior, - types.InstanceAttributeNameInstanceType, - types.InstanceAttributeNameKernel, - types.InstanceAttributeNameRamdisk, types.InstanceAttributeNameUserData, } { r, err := e.client.DescribeInstanceAttribute(ctx, &awsec2.DescribeInstanceAttributeInput{ @@ -178,26 +174,10 @@ func (e *external) Observe(ctx context.Context, mgd resource.Managed) (managed.E o.DisableApiTermination = r.DisableApiTermination } - if r.EbsOptimized != nil { - o.EbsOptimized = r.EbsOptimized - } - if r.InstanceInitiatedShutdownBehavior != nil { o.InstanceInitiatedShutdownBehavior = r.InstanceInitiatedShutdownBehavior } - if r.InstanceType != nil { - o.InstanceType = r.InstanceType - } - - if r.KernelId != nil { - o.KernelId = r.KernelId - } - - if r.RamdiskId != nil { - o.RamdiskId = r.RamdiskId - } - if r.UserData != nil { o.UserData = r.UserData }