Skip to content

Commit 8df7701

Browse files
committed
bugfixes from testing
Signed-off-by: grokspawn <jordan@nimblewidget.com>
1 parent 677995d commit 8df7701

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

alpha/declcfg/declcfg_to_model.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ func ConvertToModel(cfg DeclarativeConfig) (model.Model, error) {
142142
if err != nil {
143143
return nil, fmt.Errorf("error parsing bundle %q release version %q: %v", b.Name, props.Packages[0].Release, err)
144144
}
145-
if relver.Major != 0 || relver.Minor != 0 || relver.Patch != 0 || len(relver.Build) != 0 {
146-
return nil, fmt.Errorf("bundle %q release version %q must only contain prerelease", b.Name, props.Packages[0].Release)
145+
// only need to check for build metadata since we are using explicit zero major, minor, and patch versions above
146+
if len(relver.Build) != 0 {
147+
return nil, fmt.Errorf("bundle %q release version %q cannot contain build metadata", b.Name, props.Packages[0].Release)
147148
}
148149
}
149150

alpha/template/substitutes/substitutes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"slices"
89

910
"k8s.io/apimachinery/pkg/util/yaml"
1011

@@ -144,6 +145,15 @@ func (t Template) processSubstitution(ctx context.Context, cfg *declcfg.Declarat
144145
entry.Replaces = substituteBundle.Name
145146
entry.Skips = append(entry.Skips, substitution.Base)
146147
}
148+
149+
// If this entry skips substitution.base, update it to skip substitution.name
150+
// and remove substitution.base from the skips list
151+
if entry.Skips != nil && slices.Contains(entry.Skips, substitution.Base) {
152+
entry.Skips = append(entry.Skips, substituteBundle.Name)
153+
entry.Skips = slices.DeleteFunc(entry.Skips, func(skip string) bool {
154+
return skip == substitution.Base
155+
})
156+
}
147157
}
148158
}
149159

pkg/lib/validation/bundle.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@ func validateBundle(bundle *registry.Bundle) errors.ManifestResult {
3939
result.Add(errors.ErrInvalidParse("error getting bundle CSV version", err))
4040
return result
4141
}
42-
if result.Name, err = csv.GetRelease(); err != nil {
42+
if _, err = csv.GetRelease(); err != nil {
4343
result.Add(errors.ErrInvalidParse("error getting bundle CSV release version", err))
4444
return result
4545
}
46-
rel, _ := csv.GetRelease()
47-
if rel == "" {
48-
result.Add(errors.ErrInvalidParse("bundle CSV release version is not defined", errors.Error{}))
49-
}
5046
return result
5147
}
5248

pkg/registry/parse.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ func (b *bundleParser) derivedProperties(bundle *Bundle) ([]Property, error) {
197197
}
198198
}
199199

200+
// nolint:nestif
201+
// existing code triggering nested complexity, but at least will not make worse with release processing
200202
if bundle.Annotations != nil && bundle.Annotations.PackageName != "" {
201203
pkg := bundle.Annotations.PackageName
202204
version, err := bundle.Version()
@@ -208,18 +210,9 @@ func (b *bundleParser) derivedProperties(bundle *Bundle) ([]Property, error) {
208210
return nil, err
209211
}
210212
if release == "" && csv.GetSubstitutesFor() != "" {
211-
// if the bundle expresses no release version, but
212-
// includes the substitutesFor annotation, then we
213-
// interpret any build metadata in the version as
214-
// the release version.
215-
// failure to parse build metadata under these conditions is fatal,
216-
// though validation is later
217-
parts := strings.SplitN(version, "+", 2)
218-
if len(parts) == 2 {
219-
version = parts[0]
220-
release = parts[1]
221-
} else {
222-
return nil, fmt.Errorf("bundle %q with has substitutesFor annotation but release version not expressed as build metadata: %q", bundle.Name, version)
213+
version, release, err = extractReleaseVersionFromBuildMetadata(version)
214+
if err != nil {
215+
return nil, fmt.Errorf("bundle %q error: %v", bundle.Name, err)
223216
}
224217
}
225218

@@ -232,7 +225,7 @@ func (b *bundleParser) derivedProperties(bundle *Bundle) ([]Property, error) {
232225
return nil, fmt.Errorf("failed to marshal package property: %s", err)
233226
}
234227

235-
// Annotations file takes precedent over CSV annotations
228+
// Annotations file takes precedence over CSV annotations
236229
derived = append([]Property{{Type: PackageType, Value: value}}, derived...)
237230
}
238231

@@ -273,3 +266,21 @@ func propertySet(properties []Property) []Property {
273266

274267
return set
275268
}
269+
270+
func extractReleaseVersionFromBuildMetadata(substitutesFor string) (string, string, error) {
271+
var version, release string
272+
// if the bundle expresses no release version, but
273+
// includes the substitutesFor annotation, then we
274+
// interpret any build metadata in the version as
275+
// the release version.
276+
// failure to parse build metadata under these conditions is fatal,
277+
// though validation is later
278+
parts := strings.SplitN(substitutesFor, "+", 2)
279+
if len(parts) == 2 {
280+
version = parts[0]
281+
release = parts[1]
282+
} else {
283+
return "", "", fmt.Errorf("no release version expressed as build metadata: %q", version)
284+
}
285+
return version, release, nil
286+
}

0 commit comments

Comments
 (0)