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

Refactor Backend GC #810

Merged
merged 1 commit into from
Aug 13, 2019
Merged

Conversation

spencerhance
Copy link
Contributor

@spencerhance spencerhance commented Aug 1, 2019

Refactor backends GC so that we don't need ListAllBackendServices() anymore. That way, if one of the api calls fails, it won't block the others.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 1, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @spencerhance. 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 1, 2019
@rramkumar1
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 Aug 2, 2019
@spencerhance
Copy link
Contributor Author

/assign @bowei

}
ilbBackends, err := s.backendPool.List(key, lbfeatures.L7ILBVersion(lbfeatures.BackendService))
if err != nil {
return fmt.Errorf("error listing L7-ILB backends: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

More accurate to say "Error listing regional backends: %v"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

pkg/backends/syncer_test.go Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 5, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 6, 2019
@spencerhance spencerhance force-pushed the l7-ilb-backends-gc branch 3 times, most recently from 05a57f1 to 6ff08ff Compare August 6, 2019 22:34
if _, err := composite.GetBackendService(fakeGCE, key, features.VersionFromServicePort(&sp)); err != nil {
return fmt.Errorf("Expected to find backend for port %v, err: %v", sp.NodePort, err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to check things in p.all not in p.existing don't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
// Make sure it was deleted
if len(p.all) == beginLen {
return fmt.Errorf("Error: %v does not exist in p.all", dp)
Copy link
Member

Choose a reason for hiding this comment

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

Error: is redundant -- fmt.Errof("%v does not exist in p.all", dp)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// portset helps keep track of service ports during GC tests
type portset struct {
all []utils.ServicePort
existing []utils.ServicePort
Copy link
Member

Choose a reason for hiding this comment

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

might want to make this a map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// Delete ports from existing that are not in 'all'
func (p *portset) gc() {
p.existing = p.all
Copy link
Member

Choose a reason for hiding this comment

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

p.existing = []utils.ServicePort{}? It's kind of strange for gc() to /add/ stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ended up removing gc() since I think it's less confusing to just use add() and delete()

for i, sp := range p.all {
if dp == sp {
// Delete it
p.all = append(p.all[:i], p.all[i:]...)
Copy link
Member

Choose a reason for hiding this comment

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

Why does all change? doesn't it never change?

if err := syncer.Sync(svcNodePorts); err != nil {
t.Fatalf("Expected syncer to add backends with error, err: %v", err)
if err := syncer.Sync(ps.all); err != nil {
t.Fatalf("error syncing backends: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

t.Fatalf("syncer.Sync(%+v) = %v; want nil", ps.all, err)

Copy link
Member

Choose a reason for hiding this comment

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

You will want to follow this format for most of the unit test checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return fmt.Errorf("error GCing regional Backends: %v", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

this is a TODO, but we may want to consider continuing on error so a single error does not block all GC operations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tracking here: #797

// portset helps keep track of service ports during GC tests
type portset struct {
// all represents the set all of service ports in the test
all map[utils.ServicePort]struct{}
Copy link
Member

Choose a reason for hiding this comment

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

usually sets are represented by map[T]bool

then map[X] == false is natural

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. Also i'm a fan, I didn't realize how go handled keys that aren't present.

return fmt.Errorf("Error creating key for backend service %s: %v", beName, err)
}

// Make sure it exists
Copy link
Member

Choose a reason for hiding this comment

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

comment is probably redundant, but if you are going to put this, put it inside the brace so that the comment for the different cases are at the same indent level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// Make sure it exists
if found {
if _, err := composite.GetBackendService(fakeGCE, key, features.VersionFromServicePort(&sp)); err != nil {
return fmt.Errorf("Expected to find backend for port %+v, err: %v", sp.NodePort, err)
Copy link
Member

Choose a reason for hiding this comment

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

"backend for port %+v should exist, but got %v"
"backend for port %+v should not exist, but get %v"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return &ps
}

func (p *portset) existingSlice() []utils.ServicePort {
Copy link
Member

Choose a reason for hiding this comment

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

existingPorts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if err != nil {
return fmt.Errorf("Error converting newHC to composite: %v", err)
}
key, err := composite.CreateKey(cloud, newHC.Name, features.L7ILBScope())
key, err := composite.CreateKey(cloud, mergedHC.Name, meta.Regional)
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason why we went back to meta.Regional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it seemed redundant but I reverted it back

@@ -314,7 +313,17 @@ func (h *HealthChecks) getILB(name string) (*HealthCheck, error) {
if err != nil {
return nil, err
}
return NewHealthCheck(alphaHC)

newHC, err := NewHealthCheck(alphaHC)
Copy link
Member

Choose a reason for hiding this comment

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

call alphaHC gceHC and you won't have to change the name again when the version changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2019
- Refactor backends GC so that we don't need ListAllBackendServices() anymore.
That way, if one of the api calls fails, it won't block the others.
- Refactor backends GC unit tests
- Fix a ILB health check update() bug
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2019
@bowei
Copy link
Member

bowei commented Aug 12, 2019

/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 12, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bowei, spencerhance

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 12, 2019
@bowei
Copy link
Member

bowei commented Aug 13, 2019

looks like the CI had issues.

@spencerhance
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit 69c12a6 into kubernetes:master Aug 13, 2019
@spencerhance spencerhance deleted the l7-ilb-backends-gc branch August 13, 2019 21:21
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.

None yet

4 participants