Skip to content

Commit 4846f09

Browse files
authoredMar 16, 2025··
Add support for AWS China's different domain suffix (#872)
Interestingly, this doesn't show up unless you are in "no copy" mode- it looks like in copy mode, k8s-image-mapper gets the docker URI from the authorization token, passes it through skopeo, and get it back, but where we're forced to generate the domain, we need a little extra magic.
1 parent a6a2fcb commit 4846f09

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
 

‎pkg/config/config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package config
2323

2424
import (
2525
"fmt"
26+
"strings"
2627
"time"
2728

2829
"github.com/spf13/viper"
@@ -102,7 +103,11 @@ type EncryptionConfiguration struct {
102103
}
103104

104105
func (a *AWS) EcrDomain() string {
105-
return fmt.Sprintf("%s.dkr.ecr.%s.amazonaws.com", a.AccountID, a.Region)
106+
domain := "amazonaws.com"
107+
if strings.HasPrefix(a.Region, "cn-") {
108+
domain = "amazonaws.com.cn"
109+
}
110+
return fmt.Sprintf("%s.dkr.ecr.%s.%s", a.AccountID, a.Region, domain)
106111
}
107112

108113
func (g *GCP) GarDomain() string {

‎pkg/config/config_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,44 @@ target:
231231
})
232232
}
233233
}
234+
235+
func TestEcrDomain(t *testing.T) {
236+
tests := []struct {
237+
name string
238+
cfg Config
239+
domain string
240+
}{
241+
{
242+
name: "commercial aws",
243+
cfg: Config{
244+
Target: Registry{
245+
Type: "aws",
246+
AWS: AWS{
247+
AccountID: "123456789",
248+
Region: "ap-southeast-2",
249+
},
250+
},
251+
},
252+
domain: "123456789.dkr.ecr.ap-southeast-2.amazonaws.com",
253+
},
254+
{
255+
name: "aws in china",
256+
cfg: Config{
257+
Target: Registry{
258+
Type: "aws",
259+
AWS: AWS{
260+
AccountID: "123456789",
261+
Region: "cn-north-1",
262+
},
263+
},
264+
},
265+
domain: "123456789.dkr.ecr.cn-north-1.amazonaws.com.cn",
266+
},
267+
}
268+
for _, test := range tests {
269+
t.Run(test.name, func(t *testing.T) {
270+
assert := assert.New(t)
271+
assert.Equal(test.cfg.Target.AWS.EcrDomain(), test.domain)
272+
})
273+
}
274+
}

0 commit comments

Comments
 (0)
Please sign in to comment.