Skip to content
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

Merged
merged 3 commits into from
Apr 1, 2022

Conversation

mkenigs
Copy link
Contributor

@mkenigs mkenigs commented Feb 22, 2022

@mkenigs mkenigs marked this pull request as draft February 22, 2022 15:01
@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Feb 22, 2022
Comment on lines 61 to 112
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
}
Copy link
Contributor Author

@mkenigs mkenigs Feb 22, 2022

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.

  1. 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 😂
  2. Is this correct syntax for override-remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a chat with @mkenigs about this, one idea here is to update the MCO's vendor of fcct ➡️ butane, and then generate butane for this fragment. @mkenigs is suggesting alternatively that butane exposes a Go API to generate the origin file directly.

Copy link
Member

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.

Copy link
Member

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.

@mkenigs
Copy link
Contributor Author

mkenigs commented Feb 22, 2022

/assign @jkyros @yuqi-zhang


// MCDContent
type MCDContent struct {
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

@mkenigs mkenigs force-pushed the translate-184 branch 2 times, most recently from c68ecfc to 513653e Compare March 4, 2022 00:44
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 4, 2022
@mkenigs mkenigs changed the base branch from mcbs to layering March 4, 2022 00:45
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 4, 2022
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 4, 2022
@mkenigs mkenigs marked this pull request as ready for review March 4, 2022 00:50
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 4, 2022
@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 4, 2022

Not sure if we want to wait for #2976, but I think this should be ready to go into layering

@mkenigs mkenigs marked this pull request as draft March 7, 2022 22:20
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 7, 2022
@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 7, 2022

Commits from #2976 fix the unit test this is currently breaking due to Ignition version bump

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 8, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 16, 2022
@openshift-ci openshift-ci bot requested a review from jkyros March 16, 2022 21:35
@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 17, 2022

Should be good to go now that #2976 is in

Copy link
Member

@cgwalters cgwalters left a 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"
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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"`
Copy link
Member

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 😢

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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?

pkg/controller/render/machine_config_to_ignition_test.go Outdated Show resolved Hide resolved
@cgwalters
Copy link
Member

/approve
/lgtm

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 29, 2022
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2022
@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 29, 2022

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 29, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2022
@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 29, 2022

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 29, 2022
@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 31, 2022

@cgwalters made changes according to your suggestions, can you re-approve?

@mkenigs
Copy link
Contributor Author

mkenigs commented Mar 31, 2022

Also left some responses to your comments above

Copy link
Contributor

@jkyros jkyros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 31, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 31, 2022

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Apr 1, 2022

@mkenigs: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-op-single-node 006d3a9 link false /test e2e-gcp-op-single-node
ci/prow/e2e-aws-upgrade 006d3a9 link false /test e2e-aws-upgrade
ci/prow/e2e-gcp-single-node 006d3a9 link false /test e2e-gcp-single-node

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.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 10957fc into openshift:layering Apr 1, 2022
@mkenigs mkenigs deleted the translate-184 branch April 1, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. layering lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants