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

Introduce a new interface to encapsulate Ingress sync and controller implementation of the sync #428

Merged
merged 2 commits into from
Aug 23, 2018

Conversation

rramkumar1
Copy link
Contributor

@rramkumar1 rramkumar1 commented Aug 8, 2018

This PR introduces one high level sync interface and an interface for controllers to implement the sync.
The benefit of this PR is that it enforces a simple contract for controllers to follow and makes creating controller mocks much easier. For example, the existing controller in pkg/controller/controller.go would be modified to implement the Controller interface.

Note that this PR works at a layer above #424. A controller would potentially implement SyncBackends using the new interfaces defined in pkg/backends.

Also note that this abstraction will make it easier to parallelize syncs although the current implementation would need to be rewired a bit.

The second commit attempts to use the new interfaces in pkg/controller the way the code is currently structured.

/assign @bowei

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 8, 2018
@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 Aug 9, 2018
@rramkumar1 rramkumar1 force-pushed the syncer-interface branch 6 times, most recently from 9fce965 to a8be678 Compare August 14, 2018 00:12
// of garbage collecting GCLB resources during the sync of an Ingress.
type GarbageCollectionState struct {
lbNames []string
allSvcPorts []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.

just call this svcPorts?

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

glog.V(2).Infof("Ingress %q no longer exists, triggering GC", key)
// GC will find GCE resources that were used for this ingress and delete them.
return lbc.gc(lbNames, gceSvcPorts)
// Implements Controller.
Copy link
Member

Choose a reason for hiding this comment

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

fix these to be the right format (all other instances as well)

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

// Get ingress and DeepCopy for assurance that we don't pollute other goroutines with changes.
ing, ok := obj.(*extensions.Ingress)
// Implements Controller.
func (lbc *LoadBalancerController) SyncBackends(ing *extensions.Ingress, state interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this take in a utils.GCEURLMap? Do the conversion as close to the place where we get the interface{}

// free up enough quota for the next sync to pass.
if gcErr := lbc.gc(lbNames, gceSvcPorts); gcErr != nil {
retErr = fmt.Errorf("error during sync %v, error during GC %v", retErr, gcErr)
ports := []int64{}
Copy link
Member

Choose a reason for hiding this comment

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

can we make this a function by itself

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/sync/sync.go Outdated

// ShortCircuit is an error that can be returned by a Controller to
// short-circuit the remaining sync processes.
var ShortCircuit = errors.New("")
Copy link
Member

Choose a reason for hiding this comment

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

ErrSkipBackendSync = errors.New("ingress skip backend sync")

If someone accidentally uses, we should know when it gets printed out.

Copy link
Member

Choose a reason for hiding this comment

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

Errors should be named Errxxx

}

// Implements Controller.
func (lbc *LoadBalancerController) GCBackends(state interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

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

again, would like to not have to take in interface{}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that if its an interface, we aren't constrained to use one specific type to hold pre-processing data.

// We expect state to be a GarbageCollectionState
gcState, ok := state.(*GarbageCollectionState)
if !ok {
return fmt.Errorf("Expected state type to be GarbageCollectionState, type was %T", state)
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 capitalize errors

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


// Implements Controller.
func (lbc *LoadBalancerController) PostProcess(ing *extensions.Ingress) error {
Copy link
Member

Choose a reason for hiding this comment

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

call this UpdateStatus?

Copy link
Contributor Author

@rramkumar1 rramkumar1 Aug 21, 2018

Choose a reason for hiding this comment

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

I feel like PostProcess is a little more generic. We don't have to necessarily just update the status in the post process routine, we could potentially do other things like remove a finalizer

l7, err := lbc.l7Pool.Get(lb.Name)
k, err := utils.KeyFunc(ing)
if err != nil {
return fmt.Errorf("cannot get key for Ingress %v/%v: %v", ing.Namespace, ing.Name, err)
Copy link
Member

Choose a reason for hiding this comment

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

... Ingress %v/%v: %q

Copy link
Contributor Author

Choose a reason for hiding this comment

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

%q for an err?

Copy link
Member

Choose a reason for hiding this comment

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

ah misread ignore

@@ -0,0 +1,38 @@
package sync
Copy link
Member

Choose a reason for hiding this comment

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

I think it's kind of an anti-pattern to put interfaces into their own .go file. We can keep it this way for now.

@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 21, 2018
@rramkumar1 rramkumar1 force-pushed the syncer-interface branch 3 times, most recently from 502f229 to ac0c8ce Compare August 22, 2018 00:18
@rramkumar1
Copy link
Contributor Author

/retest

@bowei
Copy link
Member

bowei commented Aug 23, 2018

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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 merged commit 7adac05 into kubernetes:master Aug 23, 2018
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. 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