-
Notifications
You must be signed in to change notification settings - Fork 301
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
Conversation
6cbb7cb
to
a75d694
Compare
9fce965
to
a8be678
Compare
pkg/controller/controller.go
Outdated
// of garbage collecting GCLB resources during the sync of an Ingress. | ||
type GarbageCollectionState struct { | ||
lbNames []string | ||
allSvcPorts []utils.ServicePort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just call this svcPorts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/controller/controller.go
Outdated
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. |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/controller/controller.go
Outdated
// 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 { |
There was a problem hiding this comment.
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{}
pkg/controller/controller.go
Outdated
// 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{} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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("") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
pkg/controller/controller.go
Outdated
} | ||
|
||
// Implements Controller. | ||
func (lbc *LoadBalancerController) GCBackends(state interface{}) error { |
There was a problem hiding this comment.
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{}
There was a problem hiding this comment.
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.
pkg/controller/controller.go
Outdated
// 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't capitalize errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/controller/controller.go
Outdated
|
||
// Implements Controller. | ||
func (lbc *LoadBalancerController) PostProcess(ing *extensions.Ingress) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call this UpdateStatus?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... Ingress %v/%v: %q
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%q for an err?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
a8be678
to
db69511
Compare
502f229
to
ac0c8ce
Compare
ac0c8ce
to
6f8e6d6
Compare
/retest |
/lgtm |
[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 |
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