Skip to content

Commit ab7f7f1

Browse files
feat: Support OCI repositories by using distribution/v3 (argoproj-labs#249)
* upgrade registry dependencies to distribution v3 Signed-off-by: ludovicMercier <[email protected]> * upgrade registry dependencies to distribution v3 Signed-off-by: ludovicMercier <[email protected]> * upgrade registry dependencies to distribution v3 Signed-off-by: ludovicMercier <[email protected]> * upgrade registry dependencies to distribution v3 Signed-off-by: ludovicMercier <[email protected]> * upgrade to distribution v3 an implement ocischema Signed-off-by: ludovicMercier <[email protected]> * upgrade to distribution v3 an implement ocischema Signed-off-by: ludovicMercier <[email protected]> * go mod tidy Signed-off-by: ludovicMercier <[email protected]> * lint Signed-off-by: ludovicMercier <[email protected]> * fix broken tests Signed-off-by: ludovicMercier <[email protected]> * Update to changes from master branch Signed-off-by: jannfis <[email protected]> Co-authored-by: jannfis <[email protected]>
1 parent 9aa295f commit ab7f7f1

File tree

9 files changed

+330
-297
lines changed

9 files changed

+330
-297
lines changed

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ require (
77
github.com/argoproj/argo-cd/v2 v2.1.2
88
github.com/argoproj/gitops-engine v0.4.1
99
github.com/argoproj/pkg v0.9.1
10+
github.com/distribution/distribution/v3 v3.0.0-20210820130019-1cdeff259b9d
1011
github.com/docker/distribution v2.7.1+incompatible
1112
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
12-
github.com/nokia/docker-registry-client v0.0.0-20201015093031-af1a6d3b4fb1
13+
github.com/opencontainers/go-digest v1.0.0
1314
github.com/patrickmn/go-cache v2.1.0+incompatible
1415
github.com/prometheus/client_golang v1.7.1
15-
github.com/sirupsen/logrus v1.7.0
16+
github.com/sirupsen/logrus v1.8.1
1617
github.com/spf13/cobra v1.1.3
1718
github.com/spf13/pflag v1.0.5
1819
github.com/stretchr/testify v1.7.0
1920
go.uber.org/ratelimit v0.1.1-0.20201110185707-e86515f0dda9
2021
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
22+
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
2123
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
2224
gopkg.in/src-d/go-git.v4 v4.13.1
2325
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 37 additions & 4 deletions
Large diffs are not rendered by default.

pkg/argocd/update_test.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ func Test_UpdateApplication(t *testing.T) {
3333
t.Run("Test successful update", func(t *testing.T) {
3434
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
3535
regMock := regmock.RegistryClient{}
36-
regMock.On("Tags", mock.MatchedBy(func(s string) bool {
36+
regMock.On("NewRepository", mock.MatchedBy(func(s string) bool {
3737
return s == "jannfis/foobar"
38-
})).Return([]string{"1.0.1"}, nil)
38+
})).Return(nil)
39+
regMock.On("Tags").Return([]string{"1.0.1"}, nil)
3940
return &regMock, nil
4041
}
4142

@@ -91,7 +92,10 @@ func Test_UpdateApplication(t *testing.T) {
9192
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
9293
regMock := regmock.RegistryClient{}
9394
assert.Equal(t, endpoint.RegistryPrefix, "quay.io")
94-
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
95+
regMock.On("NewRepository", mock.MatchedBy(func(s string) bool {
96+
return s == "jannfis/foobar"
97+
})).Return(nil)
98+
regMock.On("Tags").Return([]string{"1.0.1"}, nil)
9599
return &regMock, nil
96100
}
97101

@@ -152,9 +156,10 @@ func Test_UpdateApplication(t *testing.T) {
152156
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
153157
regMock := regmock.RegistryClient{}
154158
assert.Equal(t, endpoint.RegistryPrefix, "quay.io")
155-
regMock.On("Tags", mock.MatchedBy(func(s string) bool {
159+
regMock.On("NewRepository", mock.MatchedBy(func(s string) bool {
156160
return s == "someorg/foobar"
157-
})).Return([]string{"1.0.1"}, nil)
161+
})).Return(nil)
162+
regMock.On("Tags").Return([]string{"1.0.1"}, nil)
158163
return &regMock, nil
159164
}
160165

@@ -214,6 +219,7 @@ func Test_UpdateApplication(t *testing.T) {
214219
t.Run("Test successful update when no tag is set in running workload", func(t *testing.T) {
215220
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
216221
regMock := regmock.RegistryClient{}
222+
regMock.On("NewRepository", mock.Anything).Return(nil)
217223
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
218224
return &regMock, nil
219225
}
@@ -271,6 +277,7 @@ func Test_UpdateApplication(t *testing.T) {
271277
regMock := regmock.RegistryClient{}
272278
assert.Equal(t, "myuser", username)
273279
assert.Equal(t, "mypass", password)
280+
regMock.On("NewRepository", mock.Anything).Return(nil)
274281
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
275282
return &regMock, nil
276283
}
@@ -384,6 +391,7 @@ func Test_UpdateApplication(t *testing.T) {
384391
t.Run("Test skip because of image up-to-date", func(t *testing.T) {
385392
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
386393
regMock := regmock.RegistryClient{}
394+
regMock.On("NewRepository", mock.Anything).Return(nil)
387395
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
388396
return &regMock, nil
389397
}
@@ -439,6 +447,7 @@ func Test_UpdateApplication(t *testing.T) {
439447
t.Run("Test update because of image registry changed", func(t *testing.T) {
440448
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
441449
regMock := regmock.RegistryClient{}
450+
regMock.On("NewRepository", mock.Anything).Return(nil)
442451
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
443452
return &regMock, nil
444453
}
@@ -497,6 +506,7 @@ func Test_UpdateApplication(t *testing.T) {
497506
t.Run("Test not updated because kustomize image is the same", func(t *testing.T) {
498507
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
499508
regMock := regmock.RegistryClient{}
509+
regMock.On("NewRepository", mock.Anything).Return(nil)
500510
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
501511
return &regMock, nil
502512
}
@@ -569,8 +579,9 @@ func Test_UpdateApplication(t *testing.T) {
569579
called := 0
570580
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
571581
regMock := regmock.RegistryClient{}
582+
regMock.On("NewRepository", mock.Anything).Return(nil)
572583
regMock.On("Tags", mock.Anything).Return([]string{"one", "two", "three", "four"}, nil)
573-
regMock.On("ManifestV1", mock.Anything).Return(meta[called], nil)
584+
regMock.On("Manifest", mock.Anything).Return(meta[called], nil)
574585
called += 1
575586
return &regMock, nil
576587
}
@@ -644,8 +655,9 @@ func Test_UpdateApplication(t *testing.T) {
644655
called := 0
645656
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
646657
regMock := regmock.RegistryClient{}
658+
regMock.On("NewRepository", mock.Anything).Return(nil)
647659
regMock.On("Tags", mock.Anything).Return([]string{"one", "two", "three", "four"}, nil)
648-
regMock.On("ManifestV1", mock.Anything).Return(meta[called], nil)
660+
regMock.On("Manifest", mock.Anything).Return(meta[called], nil)
649661
called += 1
650662
return &regMock, nil
651663
}
@@ -705,6 +717,7 @@ func Test_UpdateApplication(t *testing.T) {
705717
t.Run("Error - unknown registry", func(t *testing.T) {
706718
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
707719
regMock := regmock.RegistryClient{}
720+
regMock.On("NewRepository", mock.Anything).Return(nil)
708721
regMock.On("Tags", mock.Anything).Return([]string{"1.0.1"}, nil)
709722
return &regMock, nil
710723
}
@@ -813,6 +826,7 @@ func Test_UpdateApplication(t *testing.T) {
813826
t.Run("Test error on failure to list tags", func(t *testing.T) {
814827
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
815828
regMock := regmock.RegistryClient{}
829+
regMock.On("NewRepository", mock.Anything).Return(nil)
816830
regMock.On("Tags", mock.Anything).Return(nil, errors.New("some error"))
817831
return &regMock, nil
818832
}
@@ -868,6 +882,7 @@ func Test_UpdateApplication(t *testing.T) {
868882
t.Run("Test error on improper semver in tag", func(t *testing.T) {
869883
mockClientFn := func(endpoint *registry.RegistryEndpoint, username, password string) (registry.RegistryClient, error) {
870884
regMock := regmock.RegistryClient{}
885+
regMock.On("NewRepository", mock.Anything).Return(nil)
871886
regMock.On("Tags", mock.Anything).Return([]string{"1.0.0", "1.0.1"}, nil)
872887
return &regMock, nil
873888
}

pkg/image/credentials.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ func parseDockerConfigJson(registryURL string, jsonSource string) (string, strin
229229
regPrefix = registryURL
230230
}
231231

232-
if strings.HasSuffix(regPrefix, "/") {
233-
regPrefix = strings.TrimSuffix(regPrefix, "/")
234-
}
232+
regPrefix = strings.TrimSuffix(regPrefix, "/")
235233

236234
for registry, authConf := range auths {
237235
if !strings.HasPrefix(registry, registryURL) && !strings.HasPrefix(registry, regPrefix) {

0 commit comments

Comments
 (0)