Skip to content

Commit 8e4d046

Browse files
Merge pull request #1315 from wking/cluster-version-overrides-on-render
OTA-1861: cmd/cluster-version-operator/render: Add --cluster-version-manifest-path option
2 parents 27d70c3 + a837056 commit 8e4d046

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

cmd/cluster-version-operator/render.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ var (
1919
}
2020

2121
renderOpts struct {
22-
releaseImage string
23-
featureGateManifestPath string
24-
outputDir string
22+
releaseImage string
23+
clusterVersionManifestPath string
24+
featureGateManifestPath string
25+
outputDir string
2526
}
2627
)
2728

2829
func init() {
2930
rootCmd.AddCommand(renderCmd)
3031
renderCmd.PersistentFlags().StringVar(&renderOpts.outputDir, "output-dir", "", "The output directory where the manifests will be rendered.")
3132
renderCmd.PersistentFlags().StringVar(&renderOpts.releaseImage, "release-image", "", "The Openshift release image url.")
33+
renderCmd.PersistentFlags().StringVar(&renderOpts.clusterVersionManifestPath, "cluster-version-manifest-path", "", "ClusterVersion manifest input path.")
3234
renderCmd.PersistentFlags().StringVar(&renderOpts.featureGateManifestPath, "feature-gate-manifest-path", "", "FeatureGate manifest input path.")
3335
}
3436

@@ -42,7 +44,7 @@ func runRenderCmd(cmd *cobra.Command, args []string) {
4244
if renderOpts.releaseImage == "" {
4345
klog.Fatalf("missing --release-image flag, it is required")
4446
}
45-
if err := payload.Render(renderOpts.outputDir, renderOpts.releaseImage, renderOpts.featureGateManifestPath, clusterProfile()); err != nil {
47+
if err := payload.Render(renderOpts.outputDir, renderOpts.releaseImage, renderOpts.clusterVersionManifestPath, renderOpts.featureGateManifestPath, clusterProfile()); err != nil {
4648
klog.Fatalf("Render command failed: %v", err)
4749
}
4850
}

pkg/payload/render.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// Render renders critical manifests from /manifests to outputDir.
24-
func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile string) error {
24+
func Render(outputDir, releaseImage, clusterVersionManifestPath, featureGateManifestPath, clusterProfile string) error {
2525
var (
2626
manifestsDir = filepath.Join(DefaultPayloadDir, CVOManifestDir)
2727
releaseManifestsDir = filepath.Join(DefaultPayloadDir, ReleaseManifestDir)
@@ -35,6 +35,11 @@ func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile str
3535
}
3636
)
3737

38+
overrides, err := parseClusterVersionManifest(clusterVersionManifestPath)
39+
if err != nil {
40+
return fmt.Errorf("error parsing cluster version manifest: %w", err)
41+
}
42+
3843
requiredFeatureSet, enabledFeatureGates, err := parseFeatureGateManifest(featureGateManifestPath)
3944
if err != nil {
4045
return fmt.Errorf("error parsing feature gate manifest: %w", err)
@@ -70,7 +75,7 @@ func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile str
7075
}}
7176
var errs []error
7277
for _, task := range tasks {
73-
if err := renderDir(renderConfig, task.idir, task.odir, requiredFeatureSet, enabledFeatureGates, &clusterProfile, task.processTemplate, task.skipFiles, task.filterGroupKind); err != nil {
78+
if err := renderDir(renderConfig, task.idir, task.odir, overrides, requiredFeatureSet, enabledFeatureGates, &clusterProfile, task.processTemplate, task.skipFiles, task.filterGroupKind); err != nil {
7479
errs = append(errs, err)
7580
}
7681
}
@@ -82,7 +87,7 @@ func Render(outputDir, releaseImage, featureGateManifestPath, clusterProfile str
8287
return nil
8388
}
8489

85-
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 {
90+
func renderDir(renderConfig manifestRenderConfig, idir, odir string, overrides []configv1.ComponentOverride, requiredFeatureSet *string, enabledFeatureGates sets.Set[string], clusterProfile *string, processTemplate bool, skipFiles sets.Set[string], filterGroupKind sets.Set[schema.GroupKind]) error {
8691
klog.Infof("Filtering manifests in %s for feature set %v, cluster profile %v and enabled feature gates %v", idir, *requiredFeatureSet, *clusterProfile, enabledFeatureGates.UnsortedList())
8792

8893
if err := os.MkdirAll(odir, 0666); err != nil {
@@ -133,7 +138,7 @@ func renderDir(renderConfig manifestRenderConfig, idir, odir string, requiredFea
133138
for _, manifest := range manifests {
134139
if len(filterGroupKind) > 0 && !filterGroupKind.Has(manifest.GVK.GroupKind()) {
135140
klog.Infof("excluding %s because we do not render that group/kind", manifest.String())
136-
} else if err := manifest.Include(nil, requiredFeatureSet, clusterProfile, nil, nil, enabledFeatureGates); err != nil {
141+
} else if err := manifest.Include(nil, requiredFeatureSet, clusterProfile, nil, overrides, enabledFeatureGates); err != nil {
137142
klog.Infof("excluding %s: %v", manifest.String(), err)
138143
} else {
139144
filteredManifests = append(filteredManifests, string(manifest.Raw))
@@ -185,6 +190,35 @@ func renderManifest(config manifestRenderConfig, manifestBytes []byte) ([]byte,
185190
return buf.Bytes(), nil
186191
}
187192

193+
func parseClusterVersionManifest(clusterVersionManifestPath string) ([]configv1.ComponentOverride, error) {
194+
if clusterVersionManifestPath == "" {
195+
return nil, nil
196+
}
197+
198+
manifests, err := manifest.ManifestsFromFiles([]string{clusterVersionManifestPath})
199+
if err != nil {
200+
return nil, fmt.Errorf("loading ClusterVersion manifest: %w", err)
201+
}
202+
203+
if len(manifests) != 1 {
204+
return nil, fmt.Errorf("ClusterVersion manifest %s contains %d manifests, but expected only one", clusterVersionManifestPath, len(manifests))
205+
}
206+
207+
clusterVersionManifest := manifests[0]
208+
expectedGVK := schema.GroupVersionKind{Kind: "ClusterVersion", Version: configv1.GroupVersion.Version, Group: config.GroupName}
209+
if clusterVersionManifest.GVK != expectedGVK {
210+
return nil, fmt.Errorf("ClusterVersion manifest %s GroupVersionKind %v, but expected %v", clusterVersionManifest.OriginalFilename, clusterVersionManifest.GVK, expectedGVK)
211+
}
212+
213+
// Convert unstructured object to structured ClusterVersion
214+
var clusterVersion configv1.ClusterVersion
215+
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(clusterVersionManifest.Obj.Object, &clusterVersion); err != nil {
216+
return nil, fmt.Errorf("failed to convert ClusterVersion manifest %s to structured object: %w", clusterVersionManifest.OriginalFilename, err)
217+
}
218+
219+
return clusterVersion.Spec.Overrides, nil
220+
}
221+
188222
func parseFeatureGateManifest(featureGateManifestPath string) (*string, sets.Set[string], error) {
189223
if featureGateManifestPath == "" {
190224
return ptr.To(""), sets.Set[string]{}, nil

0 commit comments

Comments
 (0)