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

🐛 Fix sub-ports not deleted with trunks #2081

Merged

Conversation

mquhuy
Copy link
Contributor

@mquhuy mquhuy commented May 15, 2024

What this PR does / why we need it:
Sometimes, when a trunk is associated with sub ports, deletion of the trunk will not lead to deletion of the subports, which is not expected. This PR adds the check to ensure the deletion of the subports in such cases.

Special notes for your reviewer:

  1. Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

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

/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 15, 2024
@k8s-ci-robot k8s-ci-robot requested review from dulek and lentzi90 May 15, 2024 06:53
@k8s-ci-robot
Copy link
Contributor

Hi @mquhuy. 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-sigs/prow 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 May 15, 2024
Copy link

netlify bot commented May 15, 2024

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

Name Link
🔨 Latest commit dabce29
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cluster-api-openstack/deploys/664ef05dec2d4d0009e3c25e
😎 Deploy Preview https://deploy-preview-2081--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.

@lentzi90
Copy link
Contributor

/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 May 15, 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.

Thanks for this, it looks pretty good!
Please make lint-update to fix the linting error.

pkg/clients/networking.go Outdated Show resolved Hide resolved
@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch 3 times, most recently from 86c9d6e to 796af8e Compare May 15, 2024 08:44
@mquhuy
Copy link
Contributor Author

mquhuy commented May 15, 2024

/retest

@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch from 796af8e to 2d230c5 Compare May 15, 2024 10:10
@mquhuy mquhuy requested a review from lentzi90 May 15, 2024 11:40
@mquhuy
Copy link
Contributor Author

mquhuy commented May 15, 2024

/cc @mdbooth

@k8s-ci-robot k8s-ci-robot requested a review from mdbooth May 15, 2024 11:47
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.

Thanks, looks good. Just a request to move some code for consistency.

pkg/clients/networking.go Outdated Show resolved Hide resolved
pkg/cloud/services/networking/trunk.go Outdated Show resolved Hide resolved
@mquhuy
Copy link
Contributor Author

mquhuy commented May 15, 2024

Thank you @mdbooth! I have to go now, but I'll make the change asap tomorrow.

@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch from 2d230c5 to 4e979cc Compare May 16, 2024 05:01
@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 May 16, 2024
@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch from 4e979cc to c23bf37 Compare May 16, 2024 05:24
@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 May 16, 2024
@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch from c23bf37 to c64a89d Compare May 16, 2024 05:55
@k8s-ci-robot k8s-ci-robot removed the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 16, 2024
@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch 6 times, most recently from 5f01e18 to 34406b5 Compare May 20, 2024 14:23
@mquhuy mquhuy requested a review from mdbooth May 20, 2024 14:41
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.

I'm happy to merge this, but I recommend considering how best to test it. Some unit tests covering error cases might be one way. I think (but I haven't checked) we create a port with a trunk in one of the e2e tests. Perhaps we could also add a subport to it, which would cause the test to fail if it isn't cleaned up properly. Just some ideas.

@@ -77,6 +79,44 @@ func (s *Service) getOrCreateTrunkForPort(eventObject runtime.Object, port *port
return trunk, nil
}

func (s *Service) RemoveTrunkSubports(trunkID string) error {
mc := metrics.NewMetricPrometheusContext("trunk", "deletesubports")
Copy link
Contributor

Choose a reason for hiding this comment

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

We really need a metrics strategy. I'd probably leave this out, tbh, but in absence of any related policy I'm not going to object.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks to me like this is a duplicate. We are already getting the metrics in networking.go above.
Can you remove this @mquhuy ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure. Coming up

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 May 21, 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.

This looks good, except the duplicate metrics

@@ -77,6 +79,44 @@ func (s *Service) getOrCreateTrunkForPort(eventObject runtime.Object, port *port
return trunk, nil
}

func (s *Service) RemoveTrunkSubports(trunkID string) error {
mc := metrics.NewMetricPrometheusContext("trunk", "deletesubports")
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks to me like this is a duplicate. We are already getting the metrics in networking.go above.
Can you remove this @mquhuy ?

@mquhuy
Copy link
Contributor Author

mquhuy commented May 23, 2024

I'm happy to merge this, but I recommend considering how best to test it. Some unit tests covering error cases might be one way. I think (but I haven't checked) we create a port with a trunk in one of the e2e tests. Perhaps we could also add a subport to it, which would cause the test to fail if it isn't cleaned up properly. Just some ideas.

Thank you. I'm wondering if this is the one you were thinking of? https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/main/pkg/cloud/services/networking/port_test.go#L309

I'm not sure if I understand it correctly, but it seems to me the test is only checking if the port could be created. Do you think we should also test if it can be cleaned? If it turned out to be in a bigger scope, I'd be happy to do it in another PR.

@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch from 34406b5 to 4a91e03 Compare May 23, 2024 07:19
@mquhuy mquhuy force-pushed the mquhuy/ensure-trunkport-deletion branch from 4a91e03 to dabce29 Compare May 23, 2024 07:29
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.

/lgtm

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

mquhuy commented May 23, 2024

/unhold

@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 May 23, 2024
@k8s-ci-robot k8s-ci-robot merged commit 7a19fb6 into kubernetes-sigs:main May 23, 2024
9 checks passed
@mdbooth
Copy link
Contributor

mdbooth commented May 23, 2024

I'm happy to merge this, but I recommend considering how best to test it. Some unit tests covering error cases might be one way. I think (but I haven't checked) we create a port with a trunk in one of the e2e tests. Perhaps we could also add a subport to it, which would cause the test to fail if it isn't cleaned up properly. Just some ideas.

Thank you. I'm wondering if this is the one you were thinking of? https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/main/pkg/cloud/services/networking/port_test.go#L309

I'm not sure if I understand it correctly, but it seems to me the test is only checking if the port could be created. Do you think we should also test if it can be cleaned? If it turned out to be in a bigger scope, I'd be happy to do it in another PR.

Looks like that's only testing port creation. You might want a new unit test for the delete flow. But something similar to that.

For the e2e test I was thinking of this:

// assert trunked port is created.
Eventually(func() int {
plist, err = shared.DumpOpenStackPorts(e2eCtx, ports.ListOpts{Description: "trunked", Tags: testTag})
Expect(err).To(BeNil())
return len(plist)
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(1))
port = plist[0]
Expect(port.Description).To(Equal("trunked"))
Expect(port.Tags).To(ContainElement(testTag))

If we updated the test to add a subport to that trunk we'd presumably get an error if the test didn't clean it up properly.

@mquhuy
Copy link
Contributor Author

mquhuy commented Aug 21, 2024

/cherrypick release-0.9
/cherrypick release-0.10

@k8s-infra-cherrypick-robot

@mquhuy: only kubernetes-sigs org members may request cherry picks. If you are already part of the org, make sure to change your membership to public. Otherwise you can still do the cherry-pick manually.

In response to this:

/cherrypick release-0.9
/cherrypick release-0.10

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-sigs/prow repository.

k8s-ci-robot added a commit that referenced this pull request Aug 27, 2024
k8s-ci-robot added a commit that referenced this pull request Aug 27, 2024
@lentzi90 lentzi90 deleted the mquhuy/ensure-trunkport-deletion branch November 26, 2024 06:39
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants