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

v33tov32: fix 3.3 -> 3.2 Clevis pointer translation #47

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

jkyros
Copy link
Contributor

@jkyros jkyros commented Apr 5, 2023

Per openshift/machine-config-operator#3576 (comment), Clevis was a pointer in 3.2, but isn't in 3.3, so down-translation from 3.3 -> 3.2 resulted in a panic.

I also added a test here, but I can retool it or drop it.

I was going to add a test for Clevis.Custom also, but it looks like pin is simultaneously required and and an error if supplied, so I gave up? I'm probably missing...something 😄 :

https://github.com/coreos/ignition/blob/0680c483fce356c3ddd2bcec913f41e847adc51e/config/v3_2/types/custom.go#L28
https://github.com/coreos/ignition/blob/0680c483fce356c3ddd2bcec913f41e847adc51e/config/v3_3/types/clevis.go#L36

/cc @prestist

@prestist
Copy link
Contributor

prestist commented Apr 6, 2023

Thank you for doing this, and I take a look and see what all the fuss is about.

@prestist
Copy link
Contributor

prestist commented Apr 6, 2023

Added a basic ClevisCustom test that does enforce your changes and I was shocked to see no other tests that cover it in the test file.

@prestist
Copy link
Contributor

prestist commented Apr 7, 2023

I am currently pondering how to move this change to be more of an after the fact effect like the rest of the checks. TBC this change does work, and catches / fixes the issue. However, typically that section is really a copy and paste from the ignition repo and I would like to keep that true, though I am not sure what to do about that.

@bgilbert I wonder if you have any insight?

translate/v33tov32/v33tov32.go Outdated Show resolved Hide resolved
translate/v33tov32/v33tov32.go Show resolved Hide resolved
translate_test.go Outdated Show resolved Hide resolved
@bgilbert
Copy link
Contributor

Thanks for doing this!

Do we need a similar change for Link.Target?

I was going to add a test for Clevis.Custom also, but it looks like pin is simultaneously required and and an error if supplied, so I gave up?

The pin is required if the config is present. Where are you seeing that it can't be supplied? Both of the code snippets you posted require it.

I am currently pondering how to move this change to be more of an after the fact effect like the rest of the checks. TBC this change does work, and catches / fixes the issue. However, typically that section is really a copy and paste from the ignition repo and I would like to keep that true, though I am not sure what to do about that.

I don't see a straightforward way to do that, and wouldn't worry about it. The converter code doesn't need to be super-clean, and the switch from pointers to embedded structs is a one-off change that won't happen again. (Ignition now has unit tests to make sure we don't get more struct pointers in the future.) Let's just make sure we update the leading comment block to indicate what changes were made to the original translation code.

@prestist prestist force-pushed the mco-translation-pointers branch 3 times, most recently from 244641b to 81c8164 Compare April 14, 2023 21:26
@prestist
Copy link
Contributor

@bgilbert I updated the comment to include some details about the change that breaks the pattern, and we don't need to do anything with the link.target, it looks like the other direction was accounted for previously.

@prestist prestist force-pushed the mco-translation-pointers branch 3 times, most recently from 7b939cc to 557113f Compare April 17, 2023 17:31
If we populate the "Clevis" section of ignition in 3.3 and then try to
down-translate to 3.2, we panic because some of the fields were pointers
in 3.2, but they are not pointers in 3.3 (so you copy from a struct in
3.3 into a nil pointer in 3.2 and you die)

For Clevis and Custom, this just compares the struct to the empty
struct, and:
- if it's equal, we leave the pointer as a nil and skip the translate
- if it's not equal, we point the pointer at an empty struct and do the
  translation into that

co-authored-by: jkyros jkyros@redhat.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants