Skip to content

Commit

Permalink
oci/client: drop custom platfrom & default client options
Browse files Browse the repository at this point in the history
In OCI terms having platform `flux/flux/v2` implies that the image
is runnable on some OS called "flux" on architecture called "flux".
In reality there is no such platform and there is no good reason
for Flux to pretend. OCI 1.1 (albeit still and RC at the moment),
doesn't mandate artifact to define a platform at all.

When client is constructed with a platform selector, many functions
will apply the selector, which is often undesirable.

The `flux/flux/v2` platform was only defined in client options, so
it wasn't set on any images and is safe to drop; source-controller
doesn't use `DefaultOptions`, so there is no concern.

Another inconvenient behaviour of GGCR is that some functions will pick
just the very first element that matches the platform and ignore any
additional elements, e.g. elements with same platform, but different
media type. That behaviour prevents searching for artefacts by media
type.

Signed-off-by: Ilya Dmitrichenko <[email protected]>
  • Loading branch information
errordeveloper committed Sep 22, 2023
1 parent ab26c6b commit b70d673
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion oci/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func TestBuild(t *testing.T) {
g := NewWithT(t)
c := NewClient(DefaultOptions())
c := NewClient(nil)

absPath := fmt.Sprintf("%s/deployment.yaml", t.TempDir())
err := copyFile(absPath, "testdata/artifact/deployment.yaml")
Expand Down
13 changes: 0 additions & 13 deletions oci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"

"github.com/google/go-containerregistry/pkg/crane"
gcrv1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"

"github.com/fluxcd/pkg/oci"
Expand All @@ -41,18 +40,6 @@ func NewClient(opts []crane.Option) *Client {
return &Client{options: options}
}

// DefaultOptions returns an array containing crane.WithPlatform
// to set the platform to flux.
func DefaultOptions() []crane.Option {
return []crane.Option{
crane.WithPlatform(&gcrv1.Platform{
Architecture: "flux",
OS: "flux",
OSVersion: "v2",
}),
}
}

// GetOptions returns the list of crane.Option used by this Client.
func (c *Client) GetOptions() []crane.Option {
return c.options
Expand Down
7 changes: 4 additions & 3 deletions oci/client/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ package client
import (
"context"
"fmt"
"testing"
"time"

"github.com/google/go-containerregistry/pkg/crane"
gcrv1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/random"
. "github.com/onsi/gomega"
"testing"
"time"
)

func TestDelete(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
c := NewClient(DefaultOptions())
c := NewClient(nil)
repo := "test-delete" + randStringRunes(5)
tags := []string{"v0.0.1", "v0.0.2", "v0.0.3", "latest"}
source := "github.com/fluxcd/fluxv2"
Expand Down
2 changes: 1 addition & 1 deletion oci/client/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func TestClient_Diff(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
c := NewClient(DefaultOptions())
c := NewClient(nil)
tag := "v0.0.1"
repo := "test-push" + randStringRunes(5)

Expand Down
2 changes: 1 addition & 1 deletion oci/client/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
func Test_List(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
c := NewClient(DefaultOptions())
c := NewClient(nil)
repo := "test-list" + randStringRunes(5)
appTags := []string{
"v0.0.1", "v0.0.2", "v0.0.3", "v6.0.0", "v6.0.1", "v6.0.2", "v6.0.2-rc.1", "v6.0.2-alpha",
Expand Down
2 changes: 1 addition & 1 deletion oci/client/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Test_Login(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
c := NewClient(DefaultOptions())
c := NewClient(nil)
ctx := context.Background()
err := c.LoginWithCredentials(tt.creds)
g.Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion oci/client/push_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
func Test_Push_Pull(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
c := NewClient(DefaultOptions())
c := NewClient(nil)
testDir := "testdata/artifact"
tag := "v0.0.1"
source := "github.com/fluxcd/flux2"
Expand Down
2 changes: 1 addition & 1 deletion oci/client/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func Test_Tag(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
c := NewClient(DefaultOptions())
c := NewClient(nil)
testRepo := "test-tag"
url := fmt.Sprintf("%s/%s:v0.0.1", dockerReg, testRepo)
img, err := random.Image(1024, 1)
Expand Down

0 comments on commit b70d673

Please sign in to comment.