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

Use NEG CRs for NEG Garbage Collection #1197

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

swetharepakula
Copy link
Member

  • Add finalizer to NEG CRs to ensure CR exists until NEG is deleted
    during GC
  • When neg crd is enabled, GC will use neg crs, otherwise will fallback
    to regular GC using the naming to determine which NEGs are to be
    deleted

@k8s-ci-robot
Copy link
Contributor

Hi @swetharepakula. Thanks for your PR.

I'm waiting for a kubernetes 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/test-infra 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 29, 2020
@k8s-ci-robot k8s-ci-robot requested review from bowei and thockin July 29, 2020 18:26
@freehan
Copy link
Contributor

freehan commented Jul 29, 2020

/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 Jul 29, 2020
@@ -370,6 +377,62 @@ func (manager *syncerManager) garbageCollectNEG() error {
return nil
}

// garbageCollectNEGWithCRD uses the NEG CRs and the svcPortMap to determine which NEGs
// need to be garbage collected. NEGs that have a corresponding CR with a deletion
// timestamp, don't exist in the svcPortMap or don't have a corresponding NEG in the
Copy link
Contributor

Choose a reason for hiding this comment

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

Complete the sentence ?

}
for _, cr := range deletionCandidates {
cr.Finalizers = []string{}
if cr.GetDeletionTimestamp().IsZero() {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably need to send a delete call

}
if _, ok := deletionCandidates[neg.Name]; ok {
if err := manager.ensureDeleteNetworkEndpointGroup(neg.Name, key.Zone); err != nil {
return fmt.Errorf("failed to delete NEG %s in %s: %s", neg.Name, key.Zone, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

cannot return here.
Instead it should record an event to the NEG CR if it is there

// need to be garbage collected. NEGs that have a corresponding CR with a deletion
// timestamp, don't exist in the svcPortMap or don't have a corresponding NEG in the
// will all be garbage collected
func (manager *syncerManager) garbageCollectNEGWithCRD() error {
Copy link
Contributor

@freehan freehan Jul 29, 2020

Choose a reason for hiding this comment

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

Assumption is that NEG CR exists then NEG must not be fully GCed.
Try to report event to NEG CR if NEG cannot be GCed.

Case 1: NEG CR with deletion timestamp + Manager PortInfo Map does not have key

  • Delete NEG
  • Remove Finalizer

Case 2: NEG CR has deletion timestamp + Manager PortInfo Map has the key

  • Don't Remove Finalizer until it becomes to Case 1

Case 3: NEG CR does not have deletion timestamp + Manager PortInfoMap does not have key (controller is down when the service or annotation is removed)

  • Delete NEG
  • Delete NEG CR
  • Remove Finalzier

Copy link
Contributor

Choose a reason for hiding this comment

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

func A: Delete NEG
func B: Delete NEG CR (Delete and remove Finalzier)

Copy link
Contributor

Choose a reason for hiding this comment

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

For each deletion candidate (bool shouldDeleteNEG):

  • if shouldDeleteNEG, then try delete NEG
  • Delete NEG CR

Copy link
Contributor

Choose a reason for hiding this comment

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

Deletion candidate:

case 1: shouldDeleteNEG = true
case 2: shouldDeleteNEG= false
case 3: shouldDeleteNEG = true

}

var errList []error
for key, neg := range negList {
Copy link
Contributor

Choose a reason for hiding this comment

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

one corner to watch out:

cluster A -> try to create NEG foo. (NEG foo belongs cluster B)

when service or annotation got updated, and cluster A wants to GC NEG foo. Will it GC NEG foo?

Copy link
Contributor

Choose a reason for hiding this comment

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

check description or initialized condition

@swetharepakula swetharepakula force-pushed the neg-crd-gc branch 4 times, most recently from 65add2b to 49c862c Compare July 31, 2020 17:50
Copy link
Contributor

@freehan freehan left a comment

Choose a reason for hiding this comment

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

LGTM overall
just nits.

pkg/neg/manager.go Show resolved Hide resolved
defer manager.mu.Unlock()
for _, portInfoMap := range manager.svcPortMap {
for _, portInfo := range portInfoMap {
// only keep in deletionCandidates if neg does not exist in svcPortMap
Copy link
Contributor

Choose a reason for hiding this comment

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

add a comment regarding the 2 corner cases:

  1. NEG CR has deletionTimestamp but svcPortMap has the svc
  2. NEG CR does not have deletionTImeStamp but svcPortMap does not has the svc.

 - Add finalizer to NEG CRs to ensure CR exists until NEG is deleted
 during GC
 - When neg crd is enabled, GC will use neg crs, otherwise will fallback
 to regular GC using the naming to determine which NEGs are to be
 deleted
@freehan
Copy link
Contributor

freehan commented Aug 3, 2020

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: freehan, swetharepakula

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 Aug 3, 2020
@k8s-ci-robot k8s-ci-robot merged commit c96b1d8 into kubernetes:master Aug 3, 2020
@swetharepakula swetharepakula deleted the neg-crd-gc branch August 3, 2020 17:37
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
None yet
Development

Successfully merging this pull request may close these issues.

3 participants