-
Notifications
You must be signed in to change notification settings - Fork 217
OCPSTRAT-2876: Allow inclusion/exclusion of manifests based on the OCP major version #1282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,14 @@ package payload | |
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "text/template" | ||
|
|
||
| "github.com/blang/semver/v4" | ||
| "github.com/openshift/api/config" | ||
| configv1 "github.com/openshift/api/config/v1" | ||
| "github.com/openshift/library-go/pkg/manifest" | ||
|
|
@@ -40,6 +42,11 @@ func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile str | |
| return fmt.Errorf("error parsing feature gate manifest: %w", err) | ||
| } | ||
|
|
||
| payloadVersion, err := loadReleaseVersion(releaseManifestsDir) | ||
| if err != nil { | ||
| return fmt.Errorf("error loading release version: %w", err) | ||
| } | ||
|
|
||
| tasks := []struct { | ||
| idir string | ||
| odir string | ||
|
|
@@ -70,7 +77,7 @@ func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile str | |
| }} | ||
| var errs []error | ||
| for _, task := range tasks { | ||
| if err := renderDir(renderConfig, task.idir, task.odir, requiredFeatureSet, enabledFeatureGates, &clusterProfile, task.processTemplate, task.skipFiles, task.filterGroupKind); err != nil { | ||
| if err := renderDir(renderConfig, task.idir, task.odir, requiredFeatureSet, enabledFeatureGates, &clusterProfile, ptr.To(payloadVersion.Major), task.processTemplate, task.skipFiles, task.filterGroupKind); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| } | ||
|
|
@@ -82,8 +89,8 @@ func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile str | |
| return nil | ||
| } | ||
|
|
||
| func renderDir(renderConfig manifestRenderConfig, idir, odir string, requiredFeatureSet *string, enabledFeatureGates sets.Set[string], clusterProfile *string, processTemplate bool, skipFiles sets.Set[string], filterGroupKind sets.Set[schema.GroupKind]) error { | ||
| klog.Infof("Filtering manifests in %s for feature set %v, cluster profile %v and enabled feature gates %v", idir, *requiredFeatureSet, *clusterProfile, enabledFeatureGates.UnsortedList()) | ||
| func renderDir(renderConfig manifestRenderConfig, idir, odir string, requiredFeatureSet *string, enabledFeatureGates sets.Set[string], clusterProfile *string, majorVersion *uint64, processTemplate bool, skipFiles sets.Set[string], filterGroupKind sets.Set[schema.GroupKind]) error { | ||
| klog.Infof("Filtering manifests in %s for feature set %v, cluster profile %v, enabled feature gates %v, and major version %v", idir, *requiredFeatureSet, *clusterProfile, enabledFeatureGates.UnsortedList(), ptr.Deref(majorVersion, 0)) | ||
|
|
||
| if err := os.MkdirAll(odir, 0666); err != nil { | ||
| return err | ||
|
|
@@ -133,7 +140,7 @@ func renderDir(renderConfig manifestRenderConfig, idir, odir string, requiredFea | |
| for _, manifest := range manifests { | ||
| if len(filterGroupKind) > 0 && !filterGroupKind.Has(manifest.GVK.GroupKind()) { | ||
| klog.Infof("excluding %s because we do not render that group/kind", manifest.String()) | ||
| } else if err := manifest.Include(nil, requiredFeatureSet, clusterProfile, nil, nil, enabledFeatureGates); err != nil { | ||
| } else if err := manifest.Include(nil, requiredFeatureSet, clusterProfile, nil, nil, enabledFeatureGates, majorVersion); err != nil { | ||
| klog.Infof("excluding %s: %v", manifest.String(), err) | ||
| } else { | ||
| filteredManifests = append(filteredManifests, string(manifest.Raw)) | ||
|
|
@@ -238,3 +245,27 @@ func parseFeatureGateManifest(featureGateManifestPath string) (*string, sets.Set | |
|
|
||
| return requiredFeatureSet, enabledFeatureGates, nil | ||
| } | ||
|
|
||
| func loadReleaseVersion(releaseDir string) (semver.Version, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we start to duplicate some logic. I am curious whether we could leverage the existing The if metadata.Kind != "cincinnati-metadata-v0" {
return release, fmt.Errorf("unrecognized Cincinnati metadata kind %q", metadata.Kind)
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like: func loadReleaseVersion(releaseDir string) (semver.Version, error) {
release, err := loadReleaseMetadata(releaseDir)
if err != nil {
return semver.Version{}, err
}
parsedVersion, err := semver.Parse(release.Version)
if err != nil {
return semver.Version{}, err
}
return parsedVersion, nil
} |
||
| path := filepath.Join(releaseDir, cincinnatiJSONFile) | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| return semver.Version{}, err | ||
| } | ||
|
|
||
| var metadata metadata | ||
| if err := json.Unmarshal(data, &metadata); err != nil { | ||
| return semver.Version{}, fmt.Errorf("unmarshal Cincinnati metadata: %w", err) | ||
| } | ||
|
|
||
| if metadata.Version == "" { | ||
| return semver.Version{}, errors.New("missing required Cincinnati metadata version") | ||
| } | ||
|
|
||
| parsedVersion, err := semver.Parse(metadata.Version) | ||
| if err != nil { | ||
| return semver.Version{}, fmt.Errorf("Cincinnati metadata version %q is not a valid semantic version: %v", metadata.Version, err) | ||
| } | ||
|
|
||
| return parsedVersion, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, the purpose of
MajorVersionis starting to become a bit fuzzy in comparison to theRelease.Versionfield. The meaning ofMajorVersionin the inclusion filtering context is clear; however, here we use it in a general struct type representing the contents of a release image. Thus, their purpose becomes less clear.We could do one of the following:
MajorVersionfield to make the difference betweenRelease.VersionandMajorVersionclearer.Release.Version), and extract the major version when needed using a function.ParsedVersion semver.Version; we could use it to get access to the parsed cached version of the update easily. This could even be utilized in the future when we need easy access to the parsed version of an update, which is more handy for fine grained processing. This would bring additional value to the new field, make it more general, and make its distinction clearer. The call sites requiring theMajorVersionwould need to be updated to justptr.To(payload.ParsedVersion.Major), so it would still be readable. I am more inclined towards this approach, but I am curious what you think.