Skip to content

Commit b8ac5ef

Browse files
erdodyDiego Erdody
andauthored
fix: OCI client, avoid calling tags/list if revision is not a constraint argoproj#23580 (argoproj#23581)
Signed-off-by: Diego Erdody <diego.erdody@dexterity.ai> Co-authored-by: Diego Erdody <diego.erdody@dexterity.ai>
1 parent 986e1f8 commit b8ac5ef

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

util/oci/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ func (c *nativeOCIClient) DigestMetadata(ctx context.Context, digest string) (*i
295295
func (c *nativeOCIClient) ResolveRevision(ctx context.Context, revision string, noCache bool) (string, error) {
296296
digest, err := c.resolveDigest(ctx, revision) // Lookup explicit revision
297297
if err != nil {
298+
// If the revision is not a semver constraint, just return the error
299+
if !versions.IsConstraint(revision) {
300+
return digest, err
301+
}
302+
298303
tags, err := c.GetTags(ctx, noCache)
299304
if err != nil {
300305
return "", fmt.Errorf("error fetching tags: %w", err)

util/oci/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func Test_nativeOCIClient_ResolveRevision(t *testing.T) {
374374
fields: fields{repo: store, tagsFunc: func(context.Context, string) (tags []string, err error) {
375375
return []string{"1.0.0", "1.1.0", "1.2.0", "2.0.0"}, nil
376376
}},
377-
expectedError: errors.New("no version for constraints: failed to determine semver constraint: improper constraint: sha256:abc123"),
377+
expectedError: errors.New("cannot get digest for revision sha256:abc123: sha256:abc123: not found"),
378378
},
379379
{
380380
name: "resolve latest tag",

util/versions/tags.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ func MaxVersion(revision string, tags []string) (string, error) {
6262
log.Debugf("Semver constraint '%s' resolved to version '%s'", constraints.String(), maxVersion.Original())
6363
return maxVersion.Original(), nil
6464
}
65+
66+
// Returns true if the given revision is not an exact semver and can be parsed as a semver constraint
67+
func IsConstraint(revision string) bool {
68+
if _, err := semver.NewVersion(revision); err == nil {
69+
return false
70+
}
71+
_, err := semver.NewConstraint(revision)
72+
return err == nil
73+
}

util/versions/tags_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,27 @@ func TestTags_MaxVersion(t *testing.T) {
6565
require.Error(t, err)
6666
})
6767
}
68+
69+
func TestTags_IsConstraint(t *testing.T) {
70+
t.Run("Exact", func(t *testing.T) {
71+
assert.False(t, IsConstraint("0.5.3"))
72+
})
73+
t.Run("Exact nonsemver", func(t *testing.T) {
74+
assert.False(t, IsConstraint("2024.03-LTS-RC19"))
75+
})
76+
t.Run("Constraint", func(t *testing.T) {
77+
assert.True(t, IsConstraint("= 0.5.3"))
78+
})
79+
t.Run("Constraint", func(t *testing.T) {
80+
assert.True(t, IsConstraint("> 0.5.3"))
81+
})
82+
t.Run("Constraint", func(t *testing.T) {
83+
assert.True(t, IsConstraint(">0.5.0,<0.7.0"))
84+
})
85+
t.Run("Constraint", func(t *testing.T) {
86+
assert.True(t, IsConstraint("0.7.*"))
87+
})
88+
t.Run("Constraint", func(t *testing.T) {
89+
assert.True(t, IsConstraint("*"))
90+
})
91+
}

0 commit comments

Comments
 (0)