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

Remove shared nsg rule immediately when no destinations prefixes are left #3787

Conversation

MartinForReal
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Remove shared nsg rule immediately when no destinations left

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixed: Remove shared nsg rule immediately when no destinations left

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 21, 2023
@netlify
Copy link

netlify bot commented Apr 21, 2023

Deploy Preview for kubernetes-sigs-cloud-provide-azure canceled.

Name Link
🔨 Latest commit cb8383b
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cloud-provide-azure/deploys/6442639f7c60dd00083b0058

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 21, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MartinForReal

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 Apr 21, 2023
@MartinForReal MartinForReal changed the title Remove shared nsg rule immediately when no destinations left Remove shared nsg rule immediately when no destinations prefixes are left Apr 21, 2023
@@ -3785,6 +3785,52 @@ func TestReconcileSecurityGroup(t *testing.T) {
},
},
},
{
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a test case where the sg rule should be deleted completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please refer to

It("should support service annotation `service.beta.kubernetes.io/azure-shared-securityrule`", func(ctx SpecContext) {
By("Exposing two services with shared security rule")
annotation := map[string]string{
consts.ServiceAnnotationSharedSecurityRule: "true",
}
ips1 := createAndExposeDefaultServiceWithAnnotation(cs, tc.IPFamily, serviceName, ns.Name, labels, annotation, ports)
defer func() {
err := utils.DeleteService(cs, ns.Name, serviceName)
Expect(err).NotTo(HaveOccurred())
}()
serviceName2 := serviceName + "-share"
ips2 := createAndExposeDefaultServiceWithAnnotation(cs, tc.IPFamily, serviceName2, ns.Name, labels, annotation, ports)
defer func() {
By("Cleaning up")
err := utils.DeleteService(cs, ns.Name, serviceName2)
Expect(err).NotTo(HaveOccurred())
}()
By("Validate shared security rule exists")
port := fmt.Sprintf("%d", serverPort)
nsgs, err := tc.GetClusterSecurityGroups()
Expect(err).NotTo(HaveOccurred())
ipList := append(ips1, ips2...)
Expect(validateSharedSecurityRuleExists(nsgs, ipList, port)).To(BeTrue(), "Security rule for service %s not exists", serviceName)
By("Validate automatically adjust or delete the rule, when service is deleted")
Expect(utils.DeleteService(cs, ns.Name, serviceName)).NotTo(HaveOccurred())
ipList = ips2
Eventually(func() (bool, error) {
nsgs, err = tc.GetClusterSecurityGroups()
if err != nil {
return false, err
}
return validateSharedSecurityRuleExists(nsgs, ips2, port) && !validateSharedSecurityRuleExists(nsgs, ips1, port), nil
}).WithContext(ctx).Should(BeTrue(), "Security rule should be modified to only contain service %s", serviceName2)
Expect(utils.DeleteService(cs, ns.Name, serviceName2)).NotTo(HaveOccurred())
Eventually(func() (bool, error) {
nsgs, err := tc.GetClusterSecurityGroups()
if err != nil {
return false, err
}
return validateSharedSecurityRuleExists(nsgs, ipList, port), nil
}).WithContext(ctx).Should(BeFalse(), "Fail to automatically delete the shared security rule")
})

@MartinForReal MartinForReal force-pushed the fix/removensgruleimmediately branch 4 times, most recently from 72b45d4 to ce0402a Compare April 21, 2023 10:03
Signed-off-by: MartinForReal <fanshangxiang@gmail.com>
Copy link
Member

@feiskyer feiskyer 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 Apr 22, 2023
@MartinForReal
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit 702ce83 into kubernetes-sigs:master Apr 22, 2023
19 checks passed
@MartinForReal MartinForReal deleted the fix/removensgruleimmediately branch April 23, 2023 01:16
@MartinForReal
Copy link
Contributor Author

/cherrypick release-1.27

@MartinForReal
Copy link
Contributor Author

/cherrypick release-1.26

@MartinForReal
Copy link
Contributor Author

/cherrypick release-1.25

@MartinForReal
Copy link
Contributor Author

/cherrypick release-1.24

@k8s-infra-cherrypick-robot

@MartinForReal: new pull request created: #3797

In response to this:

/cherrypick release-1.27

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-infra-cherrypick-robot

@MartinForReal: new pull request created: #3798

In response to this:

/cherrypick release-1.26

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-infra-cherrypick-robot

@MartinForReal: new pull request created: #3799

In response to this:

/cherrypick release-1.25

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-infra-cherrypick-robot

@MartinForReal: new pull request created: #3800

In response to this:

/cherrypick release-1.24

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.

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. kind/bug Categorizes issue or PR as related to a bug. 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.

None yet

5 participants