-
Notifications
You must be signed in to change notification settings - Fork 1.5k
WIP Add Spec3 flag to install config #2147
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package ignition | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // ConvertSpec2ToSpec3 converts Ignition spec2 to ignition spec3 | ||
| func ConvertSpec2ToSpec3(spec2data []byte) ([]byte, error) { | ||
| // Unmarshal | ||
| jsonMap := make(map[string]interface{}) | ||
| err := json.Unmarshal(spec2data, &jsonMap) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to Marshal Ignition config") | ||
| } | ||
|
|
||
| // Replace ignition.version | ||
| ign := jsonMap["ignition"].(map[string]interface{}) | ||
| ign["version"] = "3.0.0" | ||
|
|
||
| // ignition.config.append -> ignition.config.merge | ||
| config := ign["config"].(map[string]interface{}) | ||
| if val, ok := config["append"]; ok { | ||
| config["merge"] = val | ||
| delete(config, "append") | ||
| } | ||
| ign["config"] = config | ||
| jsonMap["ignition"] = ign | ||
|
|
||
| // Delete networkd section | ||
| if _, ok := jsonMap["networkd"]; ok { | ||
| delete(jsonMap, "networkd") | ||
| } | ||
|
|
||
| // Modify storage.files | ||
| if sval, ok := jsonMap["storage"]; ok { | ||
| storage := sval.(map[string]interface{}) | ||
|
|
||
| if fval, ok := storage["files"]; ok { | ||
| files := fval.([]interface{}) | ||
|
|
||
| updatedFiles := make([]interface{}, 0) | ||
|
|
||
| for i := range files { | ||
| file := files[i].(map[string]interface{}) | ||
| // Remove filesystem | ||
| if _, ok := file["filesystem"]; ok { | ||
| delete(file, "filesystem") | ||
| } | ||
| // append is no longer a flag | ||
| if val, ok := file["append"]; ok { | ||
| if val == "true" { | ||
| if contentsval, ok := file["contents"]; ok { | ||
| file["append"] = contentsval | ||
| delete(file, "contents") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| updatedFiles = append(updatedFiles, file) | ||
| } | ||
| storage["files"] = updatedFiles | ||
| } | ||
| jsonMap["storage"] = storage | ||
| } | ||
|
|
||
| // Convert to bytes | ||
| spec3data, err := json.Marshal(jsonMap) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed to Marshal Ignition config") | ||
| } | ||
| return spec3data, nil | ||
| } | ||
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.
This needs to be val == true.
Context, had a try to run OKD4 on FCOS today. Had to fix this, but next bump will be "failed to unmarshal bootstrap.ign: json: cannot unmarshal object into Go struct field File.append of type bool" as it tries to reread the config at some point and uses the old v2_2 config as template. There doesn't seem to be easy fix for that.
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.
Right, the installer would still use v2 ignition when creating new S3 buckets via terraform.
It doesn't look like installer can support both spec2 and spec3