88
99 "github.com/aws/aws-sdk-go-v2/aws"
1010 "github.com/aws/aws-sdk-go-v2/service/ecr"
11+ "go.uber.org/zap"
1112
13+ awsinternal "github.com/aws/eks-hybrid/internal/aws"
1214 "github.com/aws/eks-hybrid/internal/aws/imds"
1315 "github.com/aws/eks-hybrid/internal/system"
1416)
@@ -30,21 +32,21 @@ func (r *ECRRegistry) GetSandboxImage() string {
3032 return r .GetImageReference ("eks/pause" , "3.5" )
3133}
3234
33- func GetEKSRegistry (region string ) (ECRRegistry , error ) {
35+ func GetEKSRegistry (region string , regionConfig * awsinternal. RegionData ) (ECRRegistry , error ) {
3436 servicesDomain , err := imds .GetProperty (imds .ServicesDomain )
3537 if err != nil {
3638 return "" , err
3739 }
3840
39- return getEksRegistryWithServiceDomain (region , servicesDomain )
41+ return getEksRegistryWithServiceDomainAndRegionConfig (region , servicesDomain , regionConfig )
4042}
4143
42- func GetEKSHybridRegistry (region string ) (ECRRegistry , error ) {
43- return getEksRegistryWithServiceDomain (region , hybridServicesDomain )
44+ func GetEKSHybridRegistry (region string , regionConfig * awsinternal. RegionData ) (ECRRegistry , error ) {
45+ return getEksRegistryWithServiceDomainAndRegionConfig (region , hybridServicesDomain , regionConfig )
4446}
4547
46- func getEksRegistryWithServiceDomain (region , servicesDomain string ) (ECRRegistry , error ) {
47- account , region := getEKSRegistryCoordinates (region )
48+ func getEksRegistryWithServiceDomainAndRegionConfig (region , servicesDomain string , regionConfig * awsinternal. RegionData ) (ECRRegistry , error ) {
49+ account , region := getEKSRegistryCoordinatesWithRegionConfig (region , regionConfig )
4850 fipsInstalled , fipsEnabled , err := system .GetFipsInfo ()
4951 if err != nil {
5052 return "" , err
@@ -77,43 +79,9 @@ func getRegistry(accountID, ecrSubdomain, region, servicesDomain string) string
7779const nonOptInRegionAccount = "602401143452"
7880
7981var accountsByRegion = map [string ]string {
80- "ap-northeast-1" : nonOptInRegionAccount ,
81- "ap-northeast-2" : nonOptInRegionAccount ,
82- "ap-northeast-3" : nonOptInRegionAccount ,
83- "ap-south-1" : nonOptInRegionAccount ,
84- "ap-southeast-1" : nonOptInRegionAccount ,
85- "ap-southeast-2" : nonOptInRegionAccount ,
86- "ca-central-1" : nonOptInRegionAccount ,
87- "eu-central-1" : nonOptInRegionAccount ,
88- "eu-north-1" : nonOptInRegionAccount ,
89- "eu-west-1" : nonOptInRegionAccount ,
90- "eu-west-2" : nonOptInRegionAccount ,
91- "eu-west-3" : nonOptInRegionAccount ,
92- "sa-east-1" : nonOptInRegionAccount ,
93- "us-east-1" : nonOptInRegionAccount ,
94- "us-east-2" : nonOptInRegionAccount ,
95- "us-west-1" : nonOptInRegionAccount ,
96- "us-west-2" : nonOptInRegionAccount ,
97-
98- "af-south-1" : "877085696533" ,
99- "ap-east-1" : "800184023465" ,
100- "ap-east-2" : "533267051163" ,
101- "ap-south-2" : "900889452093" ,
102- "ap-southeast-3" : "296578399912" ,
103- "ap-southeast-4" : "491585149902" ,
104- "ap-southeast-5" : "151610086707" ,
105- "ap-southeast-7" : "121268973566" ,
106- "ca-west-1" : "761377655185" ,
10782 "cn-north-1" : "918309763551" ,
10883 "cn-northwest-1" : "961992271922" ,
109- "eu-central-2" : "900612956339" ,
11084 "eu-isoe-west-1" : "249663109785" ,
111- "eu-south-1" : "590381155156" ,
112- "eu-south-2" : "455263428931" ,
113- "il-central-1" : "066635153087" ,
114- "me-central-1" : "759879836304" ,
115- "me-south-1" : "558608220178" ,
116- "mx-central-1" : "730335286997" ,
11785 "us-gov-east-1" : "151742754352" ,
11886 "us-gov-west-1" : "013241004608" ,
11987 "us-iso-east-1" : "725322719131" ,
@@ -128,6 +96,8 @@ func getEKSRegistryCoordinates(region string) (string, string) {
12896 if ok {
12997 return inRegionRegistry , region
13098 }
99+
100+ // Fallback to existing region prefix-based logic
131101 if strings .HasPrefix (region , "us-gov-" ) {
132102 return "013241004608" , "us-gov-west-1"
133103 } else if strings .HasPrefix (region , "cn-" ) {
@@ -139,5 +109,31 @@ func getEKSRegistryCoordinates(region string) (string, string) {
139109 } else if strings .HasPrefix (region , "us-isof-" ) {
140110 return "676585237158" , "us-isof-south-1"
141111 }
142- return "602401143452" , "us-west-2"
112+ return nonOptInRegionAccount , "us-west-2"
113+ }
114+
115+ // getEKSRegistryCoordinatesWithRegionConfig returns an AWS region and account ID for the default EKS ECR container image registry
116+ // using region configuration from manifest when available
117+ func getEKSRegistryCoordinatesWithRegionConfig (region string , regionConfig * awsinternal.RegionData ) (string , string ) {
118+ if regionConfig != nil && regionConfig .EcrAccountID != "" {
119+ zap .L ().Info ("Using ECR account from manifest" ,
120+ zap .String ("region" , region ),
121+ zap .String ("ecrAccount" , regionConfig .EcrAccountID ))
122+ return regionConfig .EcrAccountID , region
123+ }
124+
125+ // Fall back to existing logic
126+ account , fallbackRegion := getEKSRegistryCoordinates (region )
127+ if account == nonOptInRegionAccount {
128+ zap .L ().Warn ("Region not found in manifest. Attempting to use default ECR account..." )
129+ zap .L ().Info ("Using default non-opt-in region ECR account" ,
130+ zap .String ("requestedRegion" , region ),
131+ zap .String ("fallbackRegion" , fallbackRegion ),
132+ zap .String ("ecrAccount" , account ))
133+ } else {
134+ zap .L ().Info ("Using region-specific ECR account" ,
135+ zap .String ("region" , region ),
136+ zap .String ("ecrAccount" , account ))
137+ }
138+ return account , fallbackRegion
143139}
0 commit comments