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

✨ Re-work ports management #1788

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Conversation

EmilienM
Copy link
Contributor

@EmilienM EmilienM commented Dec 11, 2023

What this PR does / why we need it:

This moves the ports management for both the OpenStackMachines and Bastion to be done outside of instances. This will make CAPO more resilient.

List of changes:

  • API: Add OpenStackMachineStatus.DependentResources and OpenStackCluster.Status.Bastion.DependentResources which will contain resolved dependent resources that were created by the machine.
  • API: Add PortsStatus to DependentResources which for now only contains Neutron Ports IDs that have been adopted (meaning they actually exist) in a cluster.
  • OpenStackCluster: reconcileDelete: we remove the security groups later since we need to remove the ports first.
  • deleteBastion: remove bastion ports after the bastion instance was removed.
  • When reconciling a Machine or a Bastion, resolve the dependent resources (only ports for now), which will 1) find out what are the expected ports for a cluster and 2) adopt the ports that currently exist and put them in Status. This will help later to know which ones to create or delete.

Note: we didn't add Conditions yet, but this might be something we do in the future.

  • squashed commits
  • if necessary:
    • includes documentation
    • adds unit tests

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Dec 11, 2023
Copy link

netlify bot commented Dec 11, 2023

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

Name Link
🔨 Latest commit 7ec4c14
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/65dccc94f20c880008624f2d
😎 Deploy Preview https://deploy-preview-1788--kubernetes-sigs-cluster-api-openstack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 11, 2023
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Dec 11, 2023
@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 Dec 11, 2023
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 13, 2023
@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 Dec 13, 2023
@EmilienM EmilienM changed the title WIP - move ports out of instance ✨ Re-work ports management Dec 14, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 14, 2023
@EmilienM
Copy link
Contributor Author

/cc jichenjc

@EmilienM
Copy link
Contributor Author

/cc lentzi90

@EmilienM
Copy link
Contributor Author

/test pull-cluster-api-provider-openstack-e2e-full-test

@EmilienM
Copy link
Contributor Author

/test pull-cluster-api-provider-openstack-e2e-full-test

@EmilienM
Copy link
Contributor Author

/test pull-cluster-api-provider-openstack-test pull-cluster-api-provider-openstack-build

@EmilienM
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 22, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 22, 2024
@EmilienM
Copy link
Contributor Author

/test pull-cluster-api-provider-openstack-e2e-full-test

Copy link
Contributor

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

Looking really great!

pkg/cloud/services/compute/referenced_resources_test.go Outdated Show resolved Hide resolved
pkg/cloud/services/networking/port_test.go Show resolved Hide resolved
@@ -446,7 +489,38 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
return ctrl.Result{}, nil
}

func (r *OpenStackMachineReconciler) getOrCreate(logger logr.Logger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine, computeService *compute.Service, userData string) (*compute.InstanceStatus, error) {
func getOrCreateMachinePorts(scope scope.Scope, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine, networkingService *networking.Service, clusterName string) error {
scope.Logger().Info("Reconciling ports for machine", "machine", machine.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this important enough to be info level? I don't have a strong opinion, just a thought

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be enough with changes, meaning if a port is created/deleted or updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Info is already used elsewhere in the controller, for example when handling machines or also load balancers, etc. I think this is fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I know it is used for "Reconciling machine" for example. It just feels to me like "ports for machine" would be already implied by "Reconciling machine", as in this is a lower level. Load balancers on the other hand is not part of that machine so it makes sense that they get a separate log message.

If we end up creating or changing a port during this reconciliation I would definitely expect an Info level message for that, but this is just information that we made it this far in the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I'll fix that right on a next iteration.

@EmilienM
Copy link
Contributor Author

/test pull-cluster-api-provider-openstack-e2e-full-test

Copy link
Contributor

@mdbooth mdbooth left a comment

Choose a reason for hiding this comment

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

This is fantastic, great work.

Returning changed from ResolveReferencedMachineResources is a bit jarring, but I understand where you're coming from.

Of course this struct should not change after creation, which is its whole purpose. This commit from my API cleanup series turns it into a pointer. I think that change would allow us to more easily set this struct atomically. i.e. It's either entirely set, or not present.

I think this is good, though, and I've approved it. If you wanted to incorporate this change, go for it. If not I'll likely do it as part of my API cleanup series instead.

I'm also going to wait for other eyes to sign off on this change too as it's pretty big.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: EmilienM, mdbooth

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 Feb 27, 2024
Copy link
Contributor

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

My comments have been addressed, so
/lgtm
Hold is still there if you want to do something about that log level or @mdbooth 's comment

@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
@EmilienM
Copy link
Contributor Author

I'm taking a look at Matt & Lennart's comments today.

@EmilienM
Copy link
Contributor Author

Thanks you all for the reviews. I'll address the logging and the API cleanup right after this one merges (if possible today), if you're fine with it.

@EmilienM
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 27, 2024
@k8s-ci-robot k8s-ci-robot merged commit fd37971 into kubernetes-sigs:main Feb 27, 2024
10 checks passed
@EmilienM EmilienM deleted the ports branch February 27, 2024 14:36
@EmilienM
Copy link
Contributor Author

WOW WOW WOW

@EmilienM EmilienM mentioned this pull request Feb 27, 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants