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

🌱 Add option for non-mandatory IP/DHCP for network device #2727

Conversation

p-strusiewiczsurmacki-mobica
Copy link
Contributor

What this PR does / why we need it:
This PR introduces ipConfigurationNotMandatory for for network device configuration (deviceSpec). If set true controller should not wait for IP address allocation for this network device.

Which issue(s) this PR fixes:
Fixes #2721

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 8, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @p-strusiewiczsurmacki-mobica!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-vsphere 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-vsphere has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @p-strusiewiczsurmacki-mobica. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 8, 2024
@p-strusiewiczsurmacki-mobica p-strusiewiczsurmacki-mobica changed the title :seedling Add option for non-mandatory IP/DHCP for network device 🌱 Add option for non-mandatory IP/DHCP for network device Feb 8, 2024

// IPConfigurationNotMandatory allows for the device to not have IP address or DHCP configured.
// +optional
IPConfigurationNotMandatory bool `json:"ipConfigurationNotMandatory,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could use something a little more explicit here, e.g. skipWaitForAddress?

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 go into more detail at the godoc.

If this new variable gets set to true, this device gets ignored when checking for an existing ip address. And propably that at least one device should get an IP address (dunno if this is true but I can think of provisioning to fail at different places if there is no IP here)?

SkipWaitForAddress sounds better to me but not yet perfect. No strong opinion on the name or a better recommendation from my side though...

What about: SkipIPAllocation or IgnoreIPAllocation

Copy link
Contributor

@zhanggbj zhanggbj Feb 19, 2024

Choose a reason for hiding this comment

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

SkipIPAllocation or IgnoreIPAllocation sounds more straightforward to me. And I'm thinking perhaps adding static is more precise, like SkipStaticIPAllocation or IgnoreStaticIPAllocation as we're only skipping the static IP allocation but not the DHCP allocation. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the name to SkipIPAllocation.

we're only skipping the static IP allocation but not the DHCP allocation

I think this is something I've got wrong. I've added SkipIPAllocation check in few more places now.
I think that if user sets SkipIPAllocation to true, no check should be performed at all.

@MaxRink
Copy link
Contributor

MaxRink commented Feb 12, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot 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 Feb 12, 2024
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: Patch coverage is 76.47059% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 64.05%. Comparing base (2768cc0) to head (b020650).
Report is 41 commits behind head on main.

Files Patch % Lines
pkg/services/govmomi/util.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2727      +/-   ##
==========================================
+ Coverage   63.88%   64.05%   +0.17%     
==========================================
  Files         160      160              
  Lines        9345     9360      +15     
==========================================
+ Hits         5970     5996      +26     
+ Misses       2914     2908       -6     
+ Partials      461      456       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -473,7 +473,7 @@ func (r vmReconciler) reconcileNormal(ctx context.Context, vmCtx *capvcontext.VM
func (r vmReconciler) isWaitingForStaticIPAllocation(vmCtx *capvcontext.VMContext) bool {
devices := vmCtx.VSphereVM.Spec.Network.Devices
for _, dev := range devices {
if !dev.DHCP4 && !dev.DHCP6 && len(dev.IPAddrs) == 0 && len(dev.AddressesFromPools) == 0 {
if !dev.DHCP4 && !dev.DHCP6 && len(dev.IPAddrs) == 0 && len(dev.AddressesFromPools) == 0 && !dev.IPConfigurationNotMandatory {
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a comment here explaining this long if? Its hard to read and remember again.

We should also adjust the godoc of the function.

Maybe there's a way to write this function in a way so its more readable: (please check if the logic is correct)

// TODO explain
if dev.IgnoreIPAllocation {
  continue
}

// TODO explain
if len(dev.IPAddrs) > 0 || len(dev.AddressesFromPools) > 0 {
  continue
}

// TODO explain
if dev.DHCP4 || dev.DHCP6 {
  continue
}

// TODO explain
return true

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've split this if statement into 3 separate statements as by tour suggestion.


// IPConfigurationNotMandatory allows for the device to not have IP address or DHCP configured.
// +optional
IPConfigurationNotMandatory bool `json:"ipConfigurationNotMandatory,omitempty"`
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 go into more detail at the godoc.

If this new variable gets set to true, this device gets ignored when checking for an existing ip address. And propably that at least one device should get an IP address (dunno if this is true but I can think of provisioning to fail at different places if there is no IP here)?

SkipWaitForAddress sounds better to me but not yet perfect. No strong opinion on the name or a better recommendation from my side though...

What about: SkipIPAllocation or IgnoreIPAllocation

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 19, 2024
@p-strusiewiczsurmacki-mobica
Copy link
Contributor Author

p-strusiewiczsurmacki-mobica commented Feb 19, 2024

@chrischdi I've tried to add some more details into this godoc comment. Hope it will be OK now.
I can add a check to ensure that at least 1 device has IP configured/DHCP enabled, but I am not sure if that's necessary. If user has to explicitly set this flag to true I would assume they have at least a minimal knowledge of what and why they are doing anyway.
But maybe I am too optimistic about this, so I'll just let you decide on that. :)

@chrischdi
Copy link
Member

Looks like some generated code needs to get regenerated.

Thanks for tackling this. I'll try to come back to this tomorrow.

@p-strusiewiczsurmacki-mobica
Copy link
Contributor Author

p-strusiewiczsurmacki-mobica commented Feb 19, 2024

Looks like some generated code needs to get regenerated.

That's weird, because I've run make verify-gen several times already and there are no changes I could commit.

EDIT: I've force-pushed those once again and it seems to be ok. Maybe CI did not get the last commit.

Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
apis/v1beta1/types.go Outdated Show resolved Hide resolved
controllers/vspherevm_controller.go Outdated Show resolved Hide resolved
@@ -457,6 +457,11 @@ func waitForIPAddresses(
// Look at each IP and determine whether a reconcile has
// been triggered for the IP.
for _, discoveredIPInfo := range nic.IpConfig.IpAddress {
// Ignore device if SkipIPAllocation is set.
if deviceSpec.SkipIPAllocation {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we want to run continue in this first case. Wouldn't this also skip discovering if IP Addresses get set on this interface?

If so, we should add it to the description that IPs for this device don't get bubbled up.

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 think you're right. Even if there is IP address discovered but the device has no static IP or DHCP configured, the discovered address will be skipped anyway.
Deleted this if statement.

@@ -109,10 +109,21 @@ func GetMachineMetadata(hostname string, vsphereVM infrav1.VSphereVM, ipamState
devices[i].Gateway6 = state.Gateway6
}

// Ignore device if SkipIPAllocation is set
Copy link
Member

Choose a reason for hiding this comment

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

Can we add why we want to skip this device here? What impact has that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some consideration I think it's not really necessary. If the device has no static IP address or DHCP configured, then waitForIPv4 and waitForIPv6 should be false anyway.

if waitForIPv4 && waitForIPv6 {
// break early as we already wait for ipv4 and ipv6
continue
}

if vsphereVM.Spec.Network.Devices[i].SkipIPAllocation {
Copy link
Member

Choose a reason for hiding this comment

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

duplicate to above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted that.

Co-authored-by: Christian Schlotter <chrischdi@users.noreply.github.com>
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
Comment on lines 376 to 377
// If true, both static IP address allocation and DHCP allocation will be skipped,
// and provider will not verify IP address allocation.
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for nitpicking here, but this may not be entirely true?

CAPV will only not verify IP address allocation. The vm itself may still doe static IP configuration or DHCP allocation (depending on the other configuration)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed that to

// If true, CAPV will not verify IP address allocation.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 27, 2024
Signed-off-by: Patryk Strusiewicz-Surmacki <patryk-pawel.strusiewicz-surmacki@external.telekom.de>
@chrischdi
Copy link
Member

/test help

@k8s-ci-robot
Copy link
Contributor

@chrischdi: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-cluster-api-provider-vsphere-e2e-blocking-main
  • /test pull-cluster-api-provider-vsphere-e2e-conformance-ci-latest-main
  • /test pull-cluster-api-provider-vsphere-e2e-conformance-main
  • /test pull-cluster-api-provider-vsphere-e2e-main
  • /test pull-cluster-api-provider-vsphere-e2e-upgrade-1-29-1-30-main
  • /test pull-cluster-api-provider-vsphere-test-integration-main
  • /test pull-cluster-api-provider-vsphere-test-main
  • /test pull-cluster-api-provider-vsphere-verify-main

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-provider-vsphere-apidiff-main

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-provider-vsphere-apidiff-main
  • pull-cluster-api-provider-vsphere-e2e-blocking-main
  • pull-cluster-api-provider-vsphere-test-integration-main
  • pull-cluster-api-provider-vsphere-test-main
  • pull-cluster-api-provider-vsphere-verify-main

In response to this:

/test help

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.

@chrischdi
Copy link
Member

/test pull-cluster-api-provider-vsphere-e2e-conformance-ci-latest-main

@chrischdi
Copy link
Member

/test pull-cluster-api-provider-vsphere-e2e-conformance-main

@chrischdi
Copy link
Member

/test pull-cluster-api-provider-vsphere-e2e-main

@chrischdi
Copy link
Member

/test pull-cluster-api-provider-vsphere-e2e-upgrade-1-29-1-30-main

Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

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

/lgtm

@schrej could you maybe give this another look in its final state :-)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 27, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 1fcc6b6fed9e860a93895d30b9198608f06e1e40

@schrej
Copy link
Member

schrej commented Mar 4, 2024

lgtm!

Thanks @p-strusiewiczsurmacki-mobica 🎉

@chrischdi
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chrischdi

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 4, 2024
@k8s-ci-robot k8s-ci-robot merged commit 185d036 into kubernetes-sigs:main Mar 4, 2024
22 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.10 milestone Mar 4, 2024
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: make ip addresses on secondary interfaces optional
6 participants