-
Notifications
You must be signed in to change notification settings - Fork 413
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
Create machine_config_to_ignition #2960
Create machine_config_to_ignition #2960
Conversation
type OriginFile struct { | ||
Packages []string `yaml:"packages"` | ||
OverrideRemove []string `yaml:"override-remove"` | ||
} | ||
|
||
func (originFile OriginFile) isEmpty() bool { | ||
return len(originFile.Packages) == 0 && len(originFile.OverrideRemove) == 0 | ||
} | ||
|
||
func (originFile OriginFile) toIgnFile(allowCompression bool) (ign3types.File, error) { | ||
treeFileContents, err := yaml.Marshal(originFile) | ||
if err != nil { | ||
return ign3types.File{}, fmt.Errorf("failed to marshal extensions as yaml: %w", err) | ||
} | ||
fullYamlContents := append([]byte("# Generated by the MCO\n\n"), treeFileContents...) | ||
src, gzipped, err := baseutil.MakeDataURL(fullYamlContents, nil, allowCompression) | ||
if err != nil { | ||
return ign3types.File{}, fmt.Errorf("could not encode extensions file: %w", err) | ||
} | ||
hash := sha256.New() | ||
hash.Write([]byte(src)) | ||
sha := hex.EncodeToString(hash.Sum(nil))[0:7] | ||
file := ign3types.File{ | ||
Node: ign3types.Node{ | ||
Path: "/etc/rpm-ostree/origin.d/extensions-" + sha + ".yaml", | ||
}, | ||
FileEmbedded1: ign3types.FileEmbedded1{ | ||
Contents: ign3types.Resource{ | ||
Source: util.StrToPtr(src), | ||
}, | ||
Mode: util.IntToPtr(0644), | ||
}, | ||
} | ||
if gzipped { | ||
file.Contents.Compression = util.StrToPtr("gzip") | ||
} | ||
|
||
return file, 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.
@jmarrero @jlebon this is mostly just copy pasted from @jmarrero 's code, but I did tweak it to allow OverrideRemove.
- Is there somewhere we could move this to that both the MCO and Butane could use? Seems like "create an Ignition file with the first 8 characters of the hash of its contents added to its path" is not a very clean API. Maybe I just need to get over that for now 😂
- Is this correct syntax for override-remove?
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'm using github.com/coreos/butane/base/util and github.com/coreos/ignition/v2/config/util, is that okay? On a related note, I wonder if some Ignition helpers should be moved to a lib? Eg the MCO has helpers like https://github.com/openshift/machine-config-operator/blob/master/test/helpers/helpers.go#L155. That helper uses EncodeBytes from github.com/vincent-petithory/dataurl while the Butane code is using baseutil.MakeDataURL. Which is leading to different encodings being used, which I ran into when writing the unit tests
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.
- The reason I used a SHA with the first characters is trying to mimic how github shows commits. The SHA is not really important the important part is that the filename is unique and reproducible. If the MCO is doing something similar somewhere else or have a better approach it's ok to change it. rpm-ostree does not care about the filename. I am not sure if there is a good place to put shared code or if this is big enough to put in a library of sorts.
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.
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.
Re. 2, override-remove
is not supported yet in the CoreOS layering flow, but I'm working on 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.
related coreos/rpm-ostree#3364
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.
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.
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.
Chatted with @mkenigs about this too. Generating a Butane fragment and then rendering that seems fine, but personally my vote is to keep those ~30 duplicated lines here for now as we iterate on getting something working and add a TODO
we can circle back to. Once we gain more confidence in how everything is connected, we can start looking at optimizing and deduping things.
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.
Just to xref, #2976 is going to update our butane vendoring, which would unblock the choice to either generate Butane directly, or expose a Go API in butane.
/assign @jkyros @yuqi-zhang |
|
||
// MCDContent | ||
type MCDContent struct { |
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.
Is factoring this out worth the churn? Also what do we want to call this? There's a chance we may even drop it depending on the outcome of https://issues.redhat.com/browse/MCO-193
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 I'd vote not to do the churn on this now.
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.
Dropped that commit but did move that struct to machine_config_to_ignition.go
3cda441
to
3eeb95d
Compare
c68ecfc
to
513653e
Compare
Not sure if we want to wait for #2976, but I think this should be ready to go into |
Commits from #2976 fix the unit test this is currently breaking due to Ignition version bump |
Should be good to go now that #2976 is in |
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.
Let's consider unifying this with the encapsulated machineconfig.
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const MCDContentPath = "/etc/machine-config-daemon/mcd_content.json" |
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 one definitely deserves a comment. It seems strongly related to
MachineConfigEncapsulatedPath = "/etc/ignition-machine-config-encapsulated.json"
In fact, any reason not to make them the same?
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'm not familiar with how that path is used but it appears to be used to signal completion of firstboot: https://github.com/openshift/machine-config-operator/blob/master/pkg/daemon/daemon.go#L614
Could also potentially deduplicate some code with appendEncapsulated
I was keeping everything separate so we don't break anything but can combine if that makes more sense
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.
See #868 - the commit message there tries to explain this
Anyways though...I think you're right that because this file is involved in special "firstboot" semantics, perhaps we should use a separate one to be safer.
const MCDContentPath = "/etc/machine-config-daemon/mcd_content.json" | ||
|
||
type MCDContent struct { | ||
KernelArguments []string `json:"kernelArguments"` |
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.
Worth noting that this exists in Ignition 3.3, and then if we agreed on coreos/ignition#1323 ...the need for this would entirely go away.
So...hmm, I am not sure where we are on an update to Ignition spec 3.3. It may actually block on newer bootimages 😢
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.
Is that worth creating a card or something?
} | ||
|
||
// KernelType | ||
if ctrlcommon.CanonicalizeKernelType(mcSpec.KernelType) == ctrlcommon.KernelTypeRealtime { |
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.
Feels like this one should be a switch
or so and we explicitly no-op on the default kernel type? But not a blocker.
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.
Fixed, should I return err for default?
/approve |
/hold |
/hold cancel |
@cgwalters made changes according to your suggestions, can you re-approve? |
Also left some responses to your comments above |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cgwalters, jkyros, mkenigs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@mkenigs: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
Closes https://issues.redhat.com/browse/MCO-184