-
Notifications
You must be signed in to change notification settings - Fork 465
Add helper functions to work with Ignition Configs #2870
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
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 |
|---|---|---|
|
|
@@ -658,3 +658,60 @@ func dedupePasswdUserSSHKeys(passwdUser ign2types.PasswdUser) ign2types.PasswdUs | |
|
|
||
| return passwdUser | ||
| } | ||
|
|
||
| // CalculateConfigFileDiffs compares the files present in two ignition configurations and returns the list of files | ||
| // that are different between them | ||
| func CalculateConfigFileDiffs(oldIgnConfig, newIgnConfig *ign3types.Config) []string { | ||
| // Go through the files and see what is new or different | ||
| oldFileSet := make(map[string]ign3types.File) | ||
| for _, f := range oldIgnConfig.Storage.Files { | ||
| oldFileSet[f.Path] = f | ||
| } | ||
| newFileSet := make(map[string]ign3types.File) | ||
| for _, f := range newIgnConfig.Storage.Files { | ||
| newFileSet[f.Path] = f | ||
| } | ||
| diffFileSet := []string{} | ||
|
|
||
| // First check if any files were removed | ||
| for path := range oldFileSet { | ||
| _, ok := newFileSet[path] | ||
| if !ok { | ||
| // debug: remove | ||
|
||
| glog.Infof("File diff: %v was deleted", path) | ||
| diffFileSet = append(diffFileSet, path) | ||
| } | ||
| } | ||
|
|
||
| // Now check if any files were added/changed | ||
| for path, newFile := range newFileSet { | ||
| oldFile, ok := oldFileSet[path] | ||
| if !ok { | ||
| // debug: remove | ||
| glog.Infof("File diff: %v was added", path) | ||
| diffFileSet = append(diffFileSet, path) | ||
| } else if !reflect.DeepEqual(oldFile, newFile) { | ||
| // debug: remove | ||
| glog.Infof("File diff: detected change to %v", newFile.Path) | ||
| diffFileSet = append(diffFileSet, path) | ||
| } | ||
| } | ||
| return diffFileSet | ||
| } | ||
|
|
||
| // GetIgnitionFileDataByPath retrieves the file data for a specified path from a given ignition config | ||
| func GetIgnitionFileDataByPath(config *ign3types.Config, path string) ([]byte, error) { | ||
| for _, f := range config.Storage.Files { | ||
| if path == f.Path { | ||
| // Convert whatever we have to the actual bytes so we can inspect them | ||
| if f.Contents.Source != nil { | ||
| contents, err := dataurl.DecodeString(*f.Contents.Source) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return contents.Data, err | ||
| } | ||
| } | ||
| } | ||
| return nil, nil | ||
| } | ||
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.
WDYT about returning a struct type with the diff that distinguishes add/remove/modify?
This is like https://github.com/coreos/bootupd/blob/499e2af364dee4bbc9811c62ddfd001b4686cd9d/src/filetree.rs#L46
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.
Do we need that info somewhere in MCO?
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.
We could use it for
isDrainRequired(see #2851)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 can be at least useful to log messages by caller instead of doing it here,in the context of https://github.com/openshift/machine-config-operator/pull/2870/files#r768161851
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.
@jkyros wdyt? Time to pull out the howitzer or not?
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.
I think given this is needed for #2851 which I think we want to get in before Friday, it might be better to fix this later if we decide it's worth it
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.
I think we end up having to someday, but that day doesn't necessarily have to be today if there are timeline concerns.
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.
sure, let's create a card for this in Jira so that someone pick this up later on.