@@ -38,6 +38,7 @@ import (
3838 "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/endpoints"
3939 "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/common"
4040 "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/record"
41+ "sigs.k8s.io/cluster-api-provider-aws/v2/util/cache"
4142)
4243
4344const (
@@ -124,6 +125,15 @@ func GenerateAmiName(amiNameFormat, baseOS, kubernetesVersion string) (string, e
124125
125126// Determine architecture based on instance type.
126127func (s * Service ) pickArchitectureForInstanceType (instanceType ec2types.InstanceType ) (string , error ) {
128+ logger := s .scope .GetLogger ().WithValues ("instance type" , instanceType )
129+
130+ if s .InstanceTypeArchitectureCache != nil {
131+ if entry , ok := s .InstanceTypeArchitectureCache .Has (string (instanceType )); ok {
132+ logger .Info ("Chosen architecture from cache" , "architecture" , entry .Architecture )
133+ return entry .Architecture , nil
134+ }
135+ }
136+
127137 descInstanceTypeInput := & ec2.DescribeInstanceTypesInput {
128138 InstanceTypes : []ec2types.InstanceType {instanceType },
129139 }
@@ -144,7 +154,7 @@ func (s *Service) pickArchitectureForInstanceType(instanceType ec2types.Instance
144154
145155 supportedArchs := describeInstanceTypeResult .InstanceTypes [0 ].ProcessorInfo .SupportedArchitectures
146156
147- logger := s . scope . GetLogger (). WithValues ("instance type" , instanceType , "supported architectures " , supportedArchs )
157+ logger = logger . WithValues ("supportedArchs " , supportedArchs )
148158 logger .Info ("Obtained a list of supported architectures for instance type" )
149159
150160 // Loop over every supported architecture for the instance type
@@ -165,6 +175,13 @@ archCheck:
165175 return "" , fmt .Errorf ("unable to find preferred architecture for instance type %q" , instanceType )
166176 }
167177
178+ if s .InstanceTypeArchitectureCache != nil {
179+ s .InstanceTypeArchitectureCache .Add (cache.InstanceTypeArchitectureCacheEntry {
180+ InstanceType : instanceType ,
181+ Architecture : architecture ,
182+ })
183+ }
184+
168185 logger .Info ("Chosen architecture" , "architecture" , architecture )
169186
170187 return architecture , nil
0 commit comments