Skip to content

Commit

Permalink
Reduce ec2 instance controller API calls
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
justinmir committed Mar 29, 2024
1 parent 637d383 commit ac631f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pkg/clients/ec2/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 0 additions & 20 deletions pkg/controller/ec2/instance/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down

0 comments on commit ac631f9

Please sign in to comment.