Skip to content

[occm] Lookup ports by SG and not tags#2355

Merged
k8s-ci-robot merged 2 commits intokubernetes:masterfrom
dulek:ports-by-sg
Sep 1, 2023
Merged

[occm] Lookup ports by SG and not tags#2355
k8s-ci-robot merged 2 commits intokubernetes:masterfrom
dulek:ports-by-sg

Conversation

@dulek
Copy link
Copy Markdown
Contributor

@dulek dulek commented Aug 30, 2023

What this PR does / why we need it:
When creating an SG for an LB we tag the ports we attach the SG to in order to be able to find them easily later on when the SG will be getting deleted. We do that to simulate an API allowing us to filter ports by attached SGs, but turns out - such an API already exists in Neutron and Gophercloud v1.6.0 allows to use it.

This commit makes sure that when deleting an SG we're discovering ports to remove it from by querying the Neutron filtering by SG. Moreover tagging the ports with the SGs is removed to as not being necessary anymore.

I've left the code removing the SG tags from ports for backward compatibility.

Which issue this PR fixes(if applicable):
fixes #

Special notes for reviewers:

Release note:

[openstack-cloud-controller-manager] Ports of the nodes will not anymore be tagged with the IDs of SGs OCCM creates for the load balancers.

dulek added 2 commits August 30, 2023 15:39
When creating an SG for an LB we tag the ports we attach the SG to in
order to be able to find them easily later on when the SG will be
getting deleted. We do that to simulate an API allowing us to filter
ports by attached SGs, but turns out - such an API already exists in
Neutron and Gophercloud v1.6.0 allows to use it.

This commit makes sure that when deleting an SG we're discovering ports
to remove it from by querying the Neutron filtering by SG. Moreover
tagging the ports with the SGs is removed to as not being necessary
anymore.

I've left the code removing the SG tags from ports for backward
compatibility.
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 30, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 30, 2023
Copy link
Copy Markdown
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.

/lgtm

return fmt.Errorf("failed to remove tag %s to port %s: %v", sg, port.ID, res.Err)

// Remove the security group ID tag from the port. Please note we don't tag ports with SG IDs anymore,
// so this stays for backward compatibility. It's reasonable to delete it in the future. 404s are ignored.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the backward compatibility? In case the user rolls back an upgrade, perhaps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Uhm, well, it will be a problem. The old code won't tag the ports again and deletion of SGs created with new version of the code will fail with the old code.

What's your advice here? Leave the tagging intact? I was really tempted to remove it as it saves us a Neutron call per port, but I guess we can leave it there for one more release?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking just leave the legacy tags there and ignore them, but this is cleaner.

func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg string) error {
// Find all the ports that have the security group associated.
listOpts := neutronports.ListOpts{TagsAny: sg}
listOpts := neutronports.ListOpts{SecurityGroups: []string{sg}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shiny.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 30, 2023
@jichenjc
Copy link
Copy Markdown
Contributor

jichenjc commented Sep 1, 2023

/approve
/hold

in case @mdbooth you still want to take another look or feel free to unhold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 1, 2023
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jichenjc

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 Sep 1, 2023
Copy link
Copy Markdown
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.

/lgtm

return fmt.Errorf("failed to remove tag %s to port %s: %v", sg, port.ID, res.Err)

// Remove the security group ID tag from the port. Please note we don't tag ports with SG IDs anymore,
// so this stays for backward compatibility. It's reasonable to delete it in the future. 404s are ignored.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking just leave the legacy tags there and ignore them, but this is cleaner.

@dulek
Copy link
Copy Markdown
Contributor Author

dulek commented Sep 1, 2023

Alright, I'm assuming I can unhold this.

/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 Sep 1, 2023
@k8s-ci-robot k8s-ci-robot merged commit 92f387c into kubernetes:master Sep 1, 2023
mandre pushed a commit to shiftstack/cloud-provider-openstack that referenced this pull request Feb 6, 2024
* Update gophercloud to v1.6.0

* Lookup ports by SG and not tags

When creating an SG for an LB we tag the ports we attach the SG to in
order to be able to find them easily later on when the SG will be
getting deleted. We do that to simulate an API allowing us to filter
ports by attached SGs, but turns out - such an API already exists in
Neutron and Gophercloud v1.6.0 allows to use it.

This commit makes sure that when deleting an SG we're discovering ports
to remove it from by querying the Neutron filtering by SG. Moreover
tagging the ports with the SGs is removed to as not being necessary
anymore.

I've left the code removing the SG tags from ports for backward
compatibility.
@dulek
Copy link
Copy Markdown
Contributor Author

dulek commented Feb 7, 2024

/cherry-pick release-1.28

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@dulek: #2355 failed to apply on top of branch "release-1.28":

Applying: Update gophercloud to v1.6.0
Applying: Lookup ports by SG and not tags
Using index info to reconstruct a base tree...
M	pkg/openstack/loadbalancer.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/openstack/loadbalancer.go
CONFLICT (content): Merge conflict in pkg/openstack/loadbalancer.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Lookup ports by SG and not tags
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

Details

In response to this:

/cherry-pick release-1.28

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.

dulek added a commit to shiftstack/cloud-provider-openstack that referenced this pull request Feb 7, 2024
* Update gophercloud to v1.6.0

* Lookup ports by SG and not tags

When creating an SG for an LB we tag the ports we attach the SG to in
order to be able to find them easily later on when the SG will be
getting deleted. We do that to simulate an API allowing us to filter
ports by attached SGs, but turns out - such an API already exists in
Neutron and Gophercloud v1.6.0 allows to use it.

This commit makes sure that when deleting an SG we're discovering ports
to remove it from by querying the Neutron filtering by SG. Moreover
tagging the ports with the SGs is removed to as not being necessary
anymore.

I've left the code removing the SG tags from ports for backward
compatibility.
k8s-ci-robot pushed a commit that referenced this pull request Feb 7, 2024
* Update gophercloud to v1.6.0

* Lookup ports by SG and not tags

When creating an SG for an LB we tag the ports we attach the SG to in
order to be able to find them easily later on when the SG will be
getting deleted. We do that to simulate an API allowing us to filter
ports by attached SGs, but turns out - such an API already exists in
Neutron and Gophercloud v1.6.0 allows to use it.

This commit makes sure that when deleting an SG we're discovering ports
to remove it from by querying the Neutron filtering by SG. Moreover
tagging the ports with the SGs is removed to as not being necessary
anymore.

I've left the code removing the SG tags from ports for backward
compatibility.
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

5 participants