Skip to content

Conversation

@mdbooth
Copy link
Contributor

@mdbooth mdbooth commented Sep 22, 2021

This commit makes 2 closely related changes:

  • Add NetworkStatus.Addresses(), and return this in OpenStackMachine
  • Update IP() and FloatingIP() to return individual addresses by
    network name

There are also a couple of incidental changes:

  • Don't bother with DisassociateFloatingIP before DeleteFloatingIP for
    bastion host
  • Delete floating IPs before server during machine delete: avoids
    orphaned floating IPs if floating IP delete fails.

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 #1001, fixes #926

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 22, 2021
@netlify
Copy link

netlify bot commented Sep 22, 2021

✔️ Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!

🔨 Explore the source changes: aea62dd

🔍 Inspect the deploy log: https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/615625a6ee1bca00079ce7ee

😎 Browse the preview: https://deploy-preview-1004--kubernetes-sigs-cluster-api-openstack.netlify.app

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 22, 2021
if err = networkingService.DeleteFloatingIP(openStackCluster, floatingIP); err != nil {
handleUpdateOSCError(openStackCluster, errors.Errorf("failed to delete floating IP: %v", err))
return errors.Errorf("failed to delete floating IP: %v", err)
for _, address := range addresses {
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, what's the reason behind the removal of disasociate floating ip for bastion only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency. We've never done it for controllers:

if !openStackCluster.Spec.ManagedAPIServerLoadBalancer && util.IsControlPlaneMachine(machine) && openStackCluster.Spec.APIServerFloatingIP == "" && floatingIP != "" {
if err = networkingService.DeleteFloatingIP(openStackCluster, floatingIP); err != nil {
handleUpdateMachineError(logger, openStackMachine, errors.Errorf("error deleting Openstack floating IP: %v", err))
return ctrl.Result{}, nil
}
}

Also it's redundant, because the floating IP will be disassociated automatically on deletion.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, thanks for the confirmation
I don't know the disassociate also happen on deletion.. thanks:)

}

if instanceStatus == nil {
logger.Info("Skipped deleting machine that is already deleted")
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add instance ID here?

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 added this, but then removed it again because after looking at how we create the log object I realised it's redundant. We don't have instance ID here because the machine has been deleted. I had added machine name, but that's already included by the logger:

log = log.WithValues("openStackMachine", openStackMachine.Name)

case "fixed":
addressType = corev1.NodeInternalIP
default:
// Ignore unknown address types
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add some log as reference? though should not reach here..

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 thought about this, and I'm not sure.

The most likely reason that we would get an unknown address type here is that OpenStack introduced a new address type which we don't use, yet. This would be a new feature, and logging something here because of a new feature we don't support yet would be very noisy. I guess we could log this and IPv6 addresses at debug level just in case?

Interestingly, I was speaking to a Nova developer about addresses yesterday, and his impression is that addresses is more likely to go away entirely rather than gain new features because it's viewed as a proxy API. The replacement would be to directly query neutron for ports associated with the device id. The only reason I didn't make that change here is that as long as Nova is caching NetworkInfo, getting it from Nova requires 1 less API call.

TL;DR I might add this at debug.

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 added this.


// FloatingIP returns the first listed floating ip of an instance for the given
// network name.
func (ns *InstanceNetworkStatus) FloatingIP(networkName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I lost some background
usually ,multiple network is reasonable, so we have multiple NICs from various network
but multiple NIC from one network is not so familiar to me, anyway, seems no harm if we
return the first ip

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're actually only using this method in 1 place: APIInstance() above. And the only thing that uses APIInstance() is the bastion host. I guess we're not likely to put a second floating IP on the bastion host, so this is really just something to make the behaviour defined if we ever did.

@jichenjc
Copy link
Contributor

/lgtm

overall looks great, just very some minor questions.. thanks~

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Sep 24, 2021
@mdbooth mdbooth force-pushed the alladdresses branch 2 times, most recently from 1c090b4 to fcbf207 Compare September 24, 2021 09:53
Copy link
Contributor

@macaptain macaptain left a comment

Choose a reason for hiding this comment

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

Looks great! Unit tests and e2e tests, we are spoiled.

Comment on lines +201 to +205
networks := make([]string, 0, len(ns.addresses))
for network := range ns.addresses {
networks = append(networks, network)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be more idiomatic to do a copy here?

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 read your comment, looked at my code, and agreed with you.

I was trying to work out why I wrote it this way when I realised the code is actually correct, because the range iterates over only the keys of the map, not the elements.

I think that's a fairly clear indication this code needs another comment 😂 I'll add one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

Comment on lines 249 to 250
Expect(len(workerMachines)).To(Equal(1))
Expect(len(controlPlaneMachines)).To(Equal(3))
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that this creates a four node cluster with the machines having ports on two different networks. Did you also want to test your functions? I think you should be able to see e.g. controlPlaneMachines[0].Status.Addresses, if the controller is working, this should show multiple addresses, since they get assigned in reconciliation:

openStackMachine.Status.Addresses = addresses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a lazy late addition, tbh. I'd previously written it as a standalone create/delete test which I expected to fail. However, it turns out that it eventually comes up because although IP selection was non-deterministic and failed when it picked the wrong one, the reconciler would just retry and eventually it picked the right one 🤷‍♂️

You are right: this test would be massively improved by testing the resulting addresses.

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 expanded the e2e test to explicitly check ports and addresses.

Incidentally, @EmilienM you may want to do something like this in #1008? I'm iterating over openstack ports per machine, which I think it what we were trying to do in that test.

This commit makes 2 closely related changes:
* Add NetworkStatus.Addresses(), and return this in OpenStackMachine
* Update IP() and FloatingIP() to return individual addresses by
  network name

There are also a couple of incidental changes:
* Don't bother with DisassociateFloatingIP before DeleteFloatingIP for
  bastion host
* Delete floating IPs before server during machine delete: avoids
  orphaned floating IPs if floating IP delete fails.
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 30, 2021
@mdbooth mdbooth requested a review from jichenjc October 1, 2021 10:21
@hidekazuna
Copy link
Contributor

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hidekazuna, macaptain, mdbooth

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 Oct 4, 2021
@macaptain
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

@macaptain: changing LGTM is restricted to collaborators

Details

In response to this:

/lgtm

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.

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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 4, 2021
@k8s-ci-robot k8s-ci-robot merged commit 1358f6e into kubernetes-sigs:master Oct 4, 2021
@mdbooth mdbooth deleted the alladdresses branch November 5, 2021 14:23
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report all machine addresses Instance.IP is set randomly when a server has multiple networks

6 participants