Skip to content

Commit

Permalink
chore: lint, again
Browse files Browse the repository at this point in the history
Signed-off-by: Blake Pettersson <[email protected]>
  • Loading branch information
blakepettersson committed Jan 25, 2025
1 parent 87e1ab0 commit 7659b60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/TomOnTime/utfutil"
"github.com/google/go-jsonnet"
"github.com/google/uuid"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
imagev1 "github.com/opencontainers/image-spec/specs-go/v1"
"sigs.k8s.io/yaml"

"github.com/argoproj/argo-cd/v3/util/oci"
Expand Down Expand Up @@ -1792,7 +1792,7 @@ func getObjsFromYAMLOrJson(logCtx *log.Entry, manifestPath string, filename stri
return status.Errorf(codes.FailedPrecondition, "Failed to open %q", manifestPath)
}
defer closeReader(reader)
manifest := v1.Manifest{}
manifest := imagev1.Manifest{}
decoder := json.NewDecoder(reader)
err = decoder.Decode(&manifest)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions util/oci/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
"time"

securejoin "github.com/cyphar/filepath-securejoin"
imagev1 "github.com/opencontainers/image-spec/specs-go/v1"
"oras.land/oras-go/v2/content/oci"

v1 "github.com/opencontainers/image-spec/specs-go/v1"

"github.com/Masterminds/semver/v3"
"github.com/argoproj/pkg/sync"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -58,7 +57,7 @@ type Client interface {
ResolveRevision(ctx context.Context, revision string, noCache bool) (string, error)

// DigestMetadata retrieves an OCI manifest for a given digest and project.
DigestMetadata(ctx context.Context, digest, project string) (*v1.Manifest, error)
DigestMetadata(ctx context.Context, digest, project string) (*imagev1.Manifest, error)

// CleanCache is invoked on a hard-refresh or when the manifest cache has expired. This removes the OCI image from
// the cached path, which is looked up by the specified revision and project.
Expand Down Expand Up @@ -262,7 +261,7 @@ func (c *nativeOCIClient) CleanCache(revision, project string) error {
}

// DigestMetadata extracts the OCI manifest for a given revision and returns it to the caller.
func (c *nativeOCIClient) DigestMetadata(ctx context.Context, digest, project string) (*v1.Manifest, error) {
func (c *nativeOCIClient) DigestMetadata(ctx context.Context, digest, project string) (*imagev1.Manifest, error) {
path, err := c.getCachedPath(digest, project)
if err != nil {
return nil, fmt.Errorf("error fetching oci metadata path for digest %s: %w", digest, err)
Expand Down Expand Up @@ -479,7 +478,7 @@ func newCompressedLayerFileStore(dest, tempDir string, maxSize int64, allowedMed

// Push looks in all the layers of an OCI image. Once it finds a layer that is compressed, it extracts the layer to a tempDir
// and then renames the temp dir to the directory where the repo-server expects to find k8s manifests.
func (s *compressedLayerExtracterStore) Push(ctx context.Context, desc v1.Descriptor, content io.Reader) error {
func (s *compressedLayerExtracterStore) Push(ctx context.Context, desc imagev1.Descriptor, content io.Reader) error {
if isCompressedLayer(desc.MediaType) {
tempDir, err := files.CreateTempDir(os.TempDir())
if err != nil {
Expand Down Expand Up @@ -530,7 +529,7 @@ func (s *compressedLayerExtracterStore) Push(ctx context.Context, desc v1.Descri
return s.Store.Push(ctx, desc, content)
}

func getOCIManifest(ctx context.Context, digest string, repo oras.ReadOnlyTarget) (*v1.Manifest, error) {
func getOCIManifest(ctx context.Context, digest string, repo oras.ReadOnlyTarget) (*imagev1.Manifest, error) {
desc, err := repo.Resolve(ctx, digest)
if err != nil {
return nil, fmt.Errorf("error resolving oci repo from digest %s: %w", digest, err)
Expand All @@ -541,7 +540,7 @@ func getOCIManifest(ctx context.Context, digest string, repo oras.ReadOnlyTarget
return nil, fmt.Errorf("error fetching oci manifest for digest %s: %w", digest, err)
}

manifest := v1.Manifest{}
manifest := imagev1.Manifest{}
decoder := json.NewDecoder(rc)
err = decoder.Decode(&manifest)
if err != nil {
Expand Down
36 changes: 18 additions & 18 deletions util/oci/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/opencontainers/go-digest"
"github.com/opencontainers/image-spec/specs-go"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
imagev1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/require"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content"
Expand All @@ -26,28 +26,28 @@ import (
)

type layerConf struct {
desc v1.Descriptor
desc imagev1.Descriptor
bytes []byte
}

func generateManifest(t *testing.T, store *memory.Store, layerDescs ...layerConf) string {
t.Helper()
configBlob := []byte("Hello config")
configDesc := content.NewDescriptorFromBytes(v1.MediaTypeImageConfig, configBlob)
configDesc := content.NewDescriptorFromBytes(imagev1.MediaTypeImageConfig, configBlob)

var layers []v1.Descriptor
var layers []imagev1.Descriptor

for _, layer := range layerDescs {
layers = append(layers, layer.desc)
}

manifestBlob, err := json.Marshal(v1.Manifest{
manifestBlob, err := json.Marshal(imagev1.Manifest{
Config: configDesc,
Layers: layers,
Versioned: specs.Versioned{SchemaVersion: 2},
})
require.NoError(t, err)
manifestDesc := content.NewDescriptorFromBytes(v1.MediaTypeImageManifest, manifestBlob)
manifestDesc := content.NewDescriptorFromBytes(imagev1.MediaTypeImageManifest, manifestBlob)

for _, layer := range layerDescs {
require.NoError(t, store.Push(context.Background(), layer.desc, bytes.NewReader(layer.bytes)))
Expand Down Expand Up @@ -104,12 +104,12 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
{
name: "extraction fails due to size limit",
fields: fields{
allowedMediaTypes: []string{v1.MediaTypeImageLayerGzip},
allowedMediaTypes: []string{imagev1.MediaTypeImageLayerGzip},
},
args: args{
digestFunc: func(store *memory.Store) string {
layerBlob := createGzippedTarWithContent(t, "some-path", "some content")
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
},
manifestMaxExtractedSize: 10,
disableManifestMaxExtractedSize: false,
Expand All @@ -119,13 +119,13 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
{
name: "extraction fails due to multiple layers",
fields: fields{
allowedMediaTypes: []string{v1.MediaTypeImageLayerGzip},
allowedMediaTypes: []string{imagev1.MediaTypeImageLayerGzip},
},
args: args{
digestFunc: func(store *memory.Store) string {
layerBlob := createGzippedTarWithContent(t, "some-path", "some content")
otherLayerBlob := createGzippedTarWithContent(t, "some-other-path", "some other content")
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, layerBlob), layerBlob}, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, otherLayerBlob), otherLayerBlob})
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, layerBlob), layerBlob}, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, otherLayerBlob), otherLayerBlob})
},
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
Expand All @@ -140,7 +140,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
args: args{
digestFunc: func(store *memory.Store) string {
layerBlob := "Hello layer"
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, []byte(layerBlob)), []byte(layerBlob)})
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, []byte(layerBlob)), []byte(layerBlob)})
},
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
Expand Down Expand Up @@ -201,12 +201,12 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
{
name: "extraction with standard gzip layer",
fields: fields{
allowedMediaTypes: []string{v1.MediaTypeImageLayerGzip},
allowedMediaTypes: []string{imagev1.MediaTypeImageLayerGzip},
},
args: args{
digestFunc: func(store *memory.Store) string {
layerBlob := createGzippedTarWithContent(t, "foo.yaml", "some content")
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
},
postValidationFunc: func(_, path string, _ Client, _ fields, _ args) {
manifestDir, err := os.ReadDir(path)
Expand All @@ -226,12 +226,12 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
{
name: "extraction with standard gzip layer using cache",
fields: fields{
allowedMediaTypes: []string{v1.MediaTypeImageLayerGzip},
allowedMediaTypes: []string{imagev1.MediaTypeImageLayerGzip},
},
args: args{
digestFunc: func(store *memory.Store) string {
layerBlob := createGzippedTarWithContent(t, "foo.yaml", "some content")
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
},
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
Expand All @@ -247,12 +247,12 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
{
name: "extraction with standard gzip layer using cache, invalid project",
fields: fields{
allowedMediaTypes: []string{v1.MediaTypeImageLayerGzip},
allowedMediaTypes: []string{imagev1.MediaTypeImageLayerGzip},
},
args: args{
digestFunc: func(store *memory.Store) string {
layerBlob := createGzippedTarWithContent(t, "foo.yaml", "some content")
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(v1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
return generateManifest(t, store, layerConf{content.NewDescriptorFromBytes(imagev1.MediaTypeImageLayerGzip, layerBlob), layerBlob})
},
manifestMaxExtractedSize: 1000,
disableManifestMaxExtractedSize: false,
Expand Down Expand Up @@ -307,7 +307,7 @@ func Test_nativeOCIClient_Extract(t *testing.T) {
func Test_nativeOCIClient_ResolveRevision(t *testing.T) {
store := memory.New()
data := []byte("")
descriptor := v1.Descriptor{
descriptor := imagev1.Descriptor{
MediaType: "",
Digest: digest.FromBytes(data),
}
Expand Down

0 comments on commit 7659b60

Please sign in to comment.