-
Notifications
You must be signed in to change notification settings - Fork 441
Let payload provider render feature gate yaml #2664
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
Merged
openshift-merge-robot
merged 1 commit into
openshift:main
from
enxebre:feature-gate-nodepools
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,23 +240,6 @@ func (p *LocalIgnitionProvider) GetPayload(ctx context.Context, releaseImage str | |
| return nil, fmt.Errorf("failed to extract templates from image: %w", err) | ||
| } | ||
|
|
||
| // Write out the feature gate manifest to the MCC dir. | ||
| // Use the feature gate from the hosted control plane which should reflect the feature gate of the cluster. | ||
| if err := func() error { | ||
| featureGateBytes, err := os.ReadFile(p.FeatureGateManifest) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to read feature gate: %w", err) | ||
| } | ||
|
|
||
| if err := os.WriteFile(filepath.Join(mccBaseDir, "99_feature-gate.yaml"), featureGateBytes, 0644); err != nil { | ||
| return fmt.Errorf("failed to write feature gate: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| }(); err != nil { | ||
| return nil, fmt.Errorf("failed to extract feature gate: %w", err) | ||
| } | ||
|
|
||
| // Extract binaries from the MCO image into the bin directory | ||
| err = func() error { | ||
| start := time.Now() | ||
|
|
@@ -276,6 +259,28 @@ func (p *LocalIgnitionProvider) GetPayload(ctx context.Context, releaseImage str | |
| return fmt.Errorf("failed to close file: %w", err) | ||
| } | ||
| } | ||
|
|
||
| component := "cluster-config-operator" | ||
| clusterConfigOperatorImage, ok := imageProvider.ImageExist(component) | ||
| if !ok { | ||
| return fmt.Errorf("release image does not contain cluster-config-operator (images: %v)", imageProvider.ComponentImages()) | ||
| } | ||
| log.Info("discovered cluster config operator image", "image", clusterConfigOperatorImage) | ||
|
|
||
| file, err := os.Create(filepath.Join(binDir, component)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create file: %w", err) | ||
| } | ||
| if err := file.Chmod(0777); err != nil { | ||
| return fmt.Errorf("failed to chmod file: %w", err) | ||
| } | ||
| if err := p.ImageFileCache.extractImageFile(ctx, clusterConfigOperatorImage, pullSecret, filepath.Join("usr/bin/", component), file); err != nil { | ||
| return fmt.Errorf("failed to extract image file: %w", err) | ||
| } | ||
| if err := file.Close(); err != nil { | ||
| return fmt.Errorf("failed to close file: %w", err) | ||
| } | ||
|
|
||
| log.Info("downloaded binaries", "time", time.Since(start).Round(time.Second).String()) | ||
| return nil | ||
| }() | ||
|
|
@@ -288,6 +293,31 @@ func (p *LocalIgnitionProvider) GetPayload(ctx context.Context, releaseImage str | |
| return nil, fmt.Errorf("failed to parse payload version: %w", err) | ||
| } | ||
|
|
||
| featureGateBytes, err := os.ReadFile(p.FeatureGateManifest) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read feature gate: %w", err) | ||
| } | ||
|
|
||
| err = func() error { | ||
| start := time.Now() | ||
|
|
||
| args := []string{ | ||
| "-c", | ||
| invokeFeatureGateRenderScript(filepath.Join(binDir, "cluster-config-operator"), filepath.Join(workDir, "cco"), mccBaseDir, payloadVersion, string(featureGateBytes)), | ||
| } | ||
|
|
||
| cmd := exec.CommandContext(ctx, "/bin/bash", args...) | ||
| out, err := cmd.CombinedOutput() | ||
| log.Info("cluster-config-operator process completed", "time", time.Since(start).Round(time.Second).String(), "output", string(out)) | ||
| if err != nil { | ||
| return fmt.Errorf("cluster-config-operator process failed: %s: %w", string(out), err) | ||
| } | ||
| return nil | ||
| }() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to execute cluster-config-operator: %w", err) | ||
| } | ||
|
|
||
| // First, run the MCO using templates and image refs as input. This generates | ||
| // output for the MCC. | ||
| err = func() error { | ||
|
|
@@ -678,3 +708,50 @@ func findMatchingManifest(imageRef string, deserializedManifestList *manifestlis | |
|
|
||
| return "", fmt.Errorf("imageRef is an unknown format to parse, imageRef: %s", imageRef) | ||
| } | ||
|
|
||
| func invokeFeatureGateRenderScript(binary, workDir, outputDir string, payloadVersion semver.Version, featureGateYAML string) string { | ||
| var script = `#!/bin/bash | ||
| set -e | ||
| mkdir -p %[2]s | ||
|
|
||
| cd %[2]s | ||
| mkdir -p input output manifests | ||
|
|
||
| touch %[2]s/manifests/99_feature-gate.yaml | ||
| cat <<EOF >%[2]s/manifests/99_feature-gate.yaml | ||
| %[5]s | ||
| EOF | ||
|
|
||
| %[1]s render \ | ||
| --config-output-file config \ | ||
| --asset-input-dir %[2]s/input \ | ||
| --asset-output-dir %[2]s/output \ | ||
| --rendered-manifest-files=%[2]s/manifests \ | ||
| --payload-version=%[4]s | ||
| cp %[2]s/manifests/99_feature-gate.yaml %[3]s/99_feature-gate.yaml | ||
| ` | ||
|
|
||
| // Depending on the version, we need different args. | ||
| if payloadVersion.Minor < 14 { | ||
| script = `#!/bin/bash | ||
| set -e | ||
| mkdir -p %[2]s | ||
|
|
||
| cd %[2]s | ||
| mkdir -p input output manifests | ||
|
|
||
| touch %[2]s/manifests/99_feature-gate.yaml | ||
| cat <<EOF >%[2]s/manifests/99_feature-gate.yaml | ||
| %[5]s | ||
| EOF | ||
|
|
||
| %[1]s render \ | ||
| --config-output-file config \ | ||
| --asset-input-dir %[2]s/input \ | ||
| --asset-output-dir %[2]s/output | ||
|
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. don't we need to pass
Member
Author
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. no, only for >= 4.14 |
||
| cp %[2]s/manifests/99_feature-gate.yaml %[3]s/99_feature-gate.yaml | ||
| ` | ||
| } | ||
|
|
||
| return fmt.Sprintf(script, binary, workDir, outputDir, payloadVersion, featureGateYAML) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If all this container is doing is writing out the feature gate yaml, we can likely do without it. The local ignition provider could read the hcp directly and create the yaml.
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.
Makes sense, I'm wanting to keep this PR scope to the minimum.
In follow up we can also consider to let the NodePool controller store the featureGate yaml into the token secret so then we just pass it through the getPayload signature.