Skip to content

Commit 1c5b668

Browse files
committed
add featureset reading
1 parent e45be83 commit 1c5b668

2 files changed

Lines changed: 51 additions & 4 deletions

File tree

pkg/operator/render/options/generic.go

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ func (o *GenericOptions) FeatureGates() (featuregates.FeatureGateAccess, error)
132132
return nil, fmt.Errorf("cannot return FeatureGate without rendered manifests")
133133
}
134134

135+
manifests, err := o.FeatureGateManifests()
136+
if err != nil {
137+
return nil, fmt.Errorf("error reading input manifests: %w", err)
138+
}
139+
// they're all the same, so just get the first
140+
featureGate, err := manifests[0].GetDecodedObj()
141+
if err != nil {
142+
return nil, fmt.Errorf("error decoding FeatureGates: %w", err)
143+
}
144+
145+
ret, err := featuregates.NewHardcodedFeatureGateAccessFromFeatureGate(featureGate.(*configv1.FeatureGate), o.PayloadVersion)
146+
if err != nil {
147+
return nil, fmt.Errorf("error creating feature accessor: %w", err)
148+
}
149+
150+
return ret, nil
151+
}
152+
153+
// FeatureGateManifests is exposed for usage in getting FeatureGateAccess and for convenient by cluster-config-operator
154+
func (o *GenericOptions) FeatureGateManifests() (RenderedManifests, error) {
155+
if len(o.RenderedManifestInputFilenames) == 0 {
156+
return nil, nil
157+
}
158+
135159
inputManifest, err := o.ReadInputManifests()
136160
if err != nil {
137161
return nil, fmt.Errorf("error reading input manifests: %w", err)
@@ -140,10 +164,15 @@ func (o *GenericOptions) FeatureGates() (featuregates.FeatureGateAccess, error)
140164
if len(featureGates) == 0 {
141165
return nil, fmt.Errorf("no FeatureGates found in manfest dir: %v", o.RenderedManifestInputFilenames)
142166
}
167+
168+
ret := RenderedManifests{}
169+
143170
var prev *RenderedManifest
144171
var featureGate *configv1.FeatureGate
145172
for i := range featureGates {
146173
curr := featureGates[i]
174+
ret = append(ret, curr)
175+
147176
decodedObj, err := curr.GetDecodedObj()
148177
if err != nil {
149178
return nil, fmt.Errorf("decoding failure for %q: %w", curr.OriginalFilename, err)
@@ -163,12 +192,25 @@ func (o *GenericOptions) FeatureGates() (featuregates.FeatureGateAccess, error)
163192
}
164193
}
165194

166-
ret, err := featuregates.NewHardcodedFeatureGateAccessFromFeatureGate(featureGate, o.PayloadVersion)
195+
return ret, nil
196+
}
197+
198+
func (o *GenericOptions) FeatureSetName() (configv1.FeatureSet, error) {
199+
if len(o.RenderedManifestInputFilenames) == 0 {
200+
return configv1.FeatureSet(o.FeatureSet), nil
201+
}
202+
203+
manifests, err := o.FeatureGateManifests()
167204
if err != nil {
168-
return nil, fmt.Errorf("error creating feature accessor: %w", err)
205+
return "MISSING", fmt.Errorf("error reading input manifests: %w", err)
206+
}
207+
// they're all the same, so just get the first
208+
featureGate, err := manifests[0].GetDecodedObj()
209+
if err != nil {
210+
return "MISSING", fmt.Errorf("error decoding FeatureGates: %w", err)
169211
}
170212

171-
return ret, nil
213+
return featureGate.(*configv1.FeatureGate).Spec.FeatureSet, nil
172214
}
173215

174216
// ApplyTo applies the options to the given config struct using the provided text/template data.

pkg/operator/render/render.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ import (
1111

1212
// WriteFiles writes the manifests and the bootstrap config file.
1313
func WriteFiles(opt *options.GenericOptions, fileConfig *options.FileConfig, templateData interface{}, additionalPredicates ...assets.FileInfoPredicate) error {
14+
featureSet, err := opt.FeatureSetName()
15+
if err != nil {
16+
return err
17+
}
18+
1419
defaultPredicates := []assets.FileInfoPredicate{assets.OnlyYaml}
15-
manifestPredicates := []assets.FileContentsPredicate{assets.InstallerFeatureSet(opt.FeatureSet)}
20+
manifestPredicates := []assets.FileContentsPredicate{assets.InstallerFeatureSet(string(featureSet))}
1621

1722
// write assets
1823
for _, manifestDir := range []string{"bootstrap-manifests", "manifests"} {

0 commit comments

Comments
 (0)