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

✨ Enable mac address retrieved from annotations #1262

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

fhaftmann
Copy link

What this PR does / why we need it:
This PR in principle enables users to assign mac addresses via networkData based on annotations to objects representing machines, in a fashion similiar what is already possible for metaData.

Questions I was unable to resolve on my own:

These issues should be resolved before merging:

  • The data schema is extended conservatively, it is not clear to me whether this also requires an API version bump (e.g. to v1beta2).
  • The fuzzy round trip conversion test complains about FromAnnotation on v1beta1.NetworkLinkEthernetMac going lost; I have found no clue how to instruct it that this is a genuinely new field with no representation in v1alpha5, although other schema extensions surely handled this in a similar way.

The follwing issues are also present on branch main (commit 3068f09), it is unclear what to do about these:

  • make lint fails with
baremetal/remote/remote_test.go:36:4: validKubeConfig declared and not used (typecheck)
                        validKubeConfig              string
                        ^
controllers/metal3remediation_controller.go:105:10: r.Get undefined (type *Metal3RemediationReconciler has no field or method Get) (typecheck)
        err = r.Get(ctx, key, &metal3Machine)
  • make verify complains about a bunch of wrong boilerplate headers and aborts.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #1208

@metal3-io-bot metal3-io-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 10, 2023
@metal3-io-bot
Copy link
Contributor

Hi @fhaftmann. Thanks for your PR.

I'm waiting for a metal3-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@fhaftmann
Copy link
Author

/hold

@metal3-io-bot metal3-io-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Oct 10, 2023
@fhaftmann fhaftmann changed the title :sparkles Enable mac address retrieved from annotations ✨ Enable mac address retrieved from annotations Oct 10, 2023
@tuminoid
Copy link
Member

/ok-to-test

@metal3-io-bot metal3-io-bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 10, 2023
@tuminoid
Copy link
Member

Hi @fhaftmann, thanks for the PR!

I don't get the failures with make lint or make verify as you do, but I recall I hit that linting issue earlier, and it was some sort of unrelated flake. While this PR is on top of fresh main, I think you might have something cached that'll cause it. My local make lint produces same errors as the golangci-lint test in this PR: https://github.com/metal3-io/cluster-api-provider-metal3/actions/runs/6469401835/job/17564710755?pr=1262 and not the ones you have in the description.

Please try cleaning the repo (git clean -dfx for example) and linter cache rm -rf ~/.cache/golangci-lint and see if it helps.

@fhaftmann fhaftmann force-pushed the mac-address-from-annotation branch 2 times, most recently from baa3eb4 to 35801fe Compare October 10, 2023 14:12
@fhaftmann
Copy link
Author

Please try cleaning the repo (git clean -dfx for example) and linter cache rm -rf ~/.cache/golangci-lint and see if it helps.

That did not help, but the feedback from the CI was enough to address the reported issues.

The failing unit test in https://prow.apps.test.metal3.io/view/s3/prow-logs/pr-logs/pull/metal3-io_cluster-api-provider-metal3/1262/unit/1711731905075875840 presumably is the failing round-trip conversion test mentioned in the PR where I am at a loss how to address it.

@tuminoid
Copy link
Member

Please try cleaning the repo (git clean -dfx for example) and linter cache rm -rf ~/.cache/golangci-lint and see if it helps.

That did not help, but the feedback from the CI was enough to address the reported issues.

The failing unit test in https://prow.apps.test.metal3.io/view/s3/prow-logs/pr-logs/pull/metal3-io_cluster-api-provider-metal3/1262/unit/1711731905075875840 presumably is the failing round-trip conversion test mentioned in the PR where I am at a loss how to address it.

/cc @mboukhalfa @lentzi90

@lentzi90
Copy link
Member

lentzi90 commented Oct 11, 2023

make verify complains about a bunch of wrong boilerplate headers and aborts.

Please ignore this for now. We have not been running this in the CI for a long time. At some point we may want to, but until then you can safely ignore it.

Regarding make lint, could this be due to the go version? I saw #1261 so I'm guessing you are used to running with many different versions. Alternatively the golangci-lint version. It is downloaded to hack/tools/bin. Deleting it from there should make sure it downloads the correct version the next time you run make lint.

@lentzi90
Copy link
Member

For the conversion, I think you are missing what we do here. The down conversion (v1beta1 -> v1alpha5) is good, but on upconversion to v1beta1 we need to restore the field from a "backup" annotation to get the roundtrip clean.
There is a recent good example in #708 that will hopefully help. 🙂

@fhaftmann fhaftmann force-pushed the mac-address-from-annotation branch from 35801fe to 7e4334b Compare October 11, 2023 07:12
@fhaftmann
Copy link
Author

For the conversion, I think you are missing what we do here. The down conversion (v1beta1 -> v1alpha5) is good, but on upconversion to v1beta1 we need to restore the field from a "backup" annotation to get the roundtrip clean. There is a recent good example in #708 that will hopefully help. 🙂

Thanks, that was the missing hint.

@fhaftmann
Copy link
Author

/hold cancel

@metal3-io-bot metal3-io-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 11, 2023
@fhaftmann
Copy link
Author

Regarding make lint, could this be due to the go version? I saw #1261 so I'm guessing you are used to running with many different versions. Alternatively the golangci-lint version. It is downloaded to hack/tools/bin. Deleting it from there should make sure it downloads the correct version the next time you run make lint.

Tried it, still same behaviour. Same behaviour without my changes. I am unsure whether this should be pursued further.

Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

Really great work on this! I especially appreciate the unit tests and docs!
Just two notes below

@@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: quay.io/metal3-io/cluster-api-provider-metal3:main
- image: quay.io/metal3-io/cluster-api-provider-metal3-amd64:v1beta1
Copy link
Member

@lentzi90 lentzi90 Oct 16, 2023

Choose a reason for hiding this comment

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

Remember to remove before merge!

Copy link
Author

Choose a reason for hiding this comment

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

Oops, I have often seen that side-effect of building but did not recognize it after issuing code generation. Corrected.

Copy link
Author

Choose a reason for hiding this comment

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

But maybe this was not the purpose of your comment.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it is unfortunate that the current way of deploying and testing relies on making changes to these manifests 😬
I just wanted to make sure we remember to remove any changes to this line. Looks like you now accidentally removed the :main at the end.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected now, sorry for the noice (again).

}
}

func getValueFromAnnotationStrict(object string, annotation string,
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 we should just conclude that this is how we should handle annotations and get rid of getValueFromAnnotation (used when rendering metadata). Different behaviors for metadata and network data will just be confusing.

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
Author

Choose a reason for hiding this comment

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

During developing I found out that getValueFromAnnotation yields empty strings for non-existing annotations. (It is not clear to me whether Kubernetes itself distinguishes between empty or non-existing annotations.)

An empty MAC address is surely an error condition, and hence I decided to make that strict. (You could even argue to check the annotation further e.g. via a regular expression to allow early detection of errors.)

But for meta data it is perfectly valid to have empty values – we do just not know how the data is applied.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation, that makes sense!
Could you add doc strings to these functions with some description that makes it clear what the difference is?

Copy link
Author

@fhaftmann fhaftmann Oct 16, 2023

Choose a reason for hiding this comment

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

This discussion made me think about that matter again and I have now added an explicit regexp check for the resulting MAC address – regardless of its source. That appears far more conclusive then the rather erratic and not self-explanatory distinction between potentially empty and non-empty annotations.

That means a subtle change of the overall behaviour: non-well-formed MAC addresses will not raise issues later after provisioning, but already before.

@fhaftmann fhaftmann force-pushed the mac-address-from-annotation branch 2 times, most recently from b574c1e to 7e090ed Compare October 16, 2023 11:38
@fhaftmann
Copy link
Author

I am still confused by the golangci-lint / lint CI – in https://github.com/metal3-io/cluster-api-provider-metal3/actions/runs/6533034950/job/17737383459?pr=1262#step:5:12777 it plainly states

Running [/home/runner/golangci-lint-1.54.2-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
  Error: unused-parameter: parameter 'm3d' seems to be unused, consider removing or renaming it as _ (revive)

Unfortunately without any file / line indication.
I am also still unable to reproduce the lint run locally.
Is there any chance to make the CI explicit about location of issues?

@lentzi90
Copy link
Member

Here is something you can try. Create a codespace from your branch:
image
Then run make lint in there.

This is what I got when doing it:

baremetal/metal3data_manager.go:925:24: unused-parameter: parameter 'm3d' seems to be unused, consider removing or renaming it as _ (revive)
func renderNetworkData(m3d *infrav1.Metal3Data, m3dt *infrav1.Metal3DataTemplate,
                       ^

@fhaftmann fhaftmann force-pushed the mac-address-from-annotation branch 2 times, most recently from 5d3a85f to c7c7791 Compare October 16, 2023 12:10
@fhaftmann
Copy link
Author

Thanks, that gave me the necessary information.

@fhaftmann fhaftmann force-pushed the mac-address-from-annotation branch from c7c7791 to fd60117 Compare October 16, 2023 14:20
This addresses issue metal3-io#1208.

Signed-off-by: Florian Haftmann <flha@uhurutec.com>
@fhaftmann fhaftmann force-pushed the mac-address-from-annotation branch from fd60117 to 6f0c29e Compare October 16, 2023 14:23
Copy link
Member

@lentzi90 lentzi90 left a comment

Choose a reason for hiding this comment

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

I'm happy with this
/approve

Would love to see some reviews by others though

baremetal/metal3data_manager.go Show resolved Hide resolved
@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 17, 2023
@lentzi90
Copy link
Member

/cc @Rozzii @Sunnatillo

Copy link
Member

@Rozzii Rozzii left a comment

Choose a reason for hiding this comment

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

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 17, 2023
@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lentzi90, Rozzii

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

@lentzi90
Copy link
Member

/test-centos-e2e-integration-main
/test-ubuntu-integration-main

@metal3-io-bot metal3-io-bot merged commit 9e5cf69 into metal3-io:main Oct 17, 2023
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. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
5 participants