-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add a simple informer implementation. #28
Conversation
kubernetes/config/azure.go
Outdated
ExpiresIn: json.Number(l.user.AuthProvider.Config["expires-in"]), | ||
ExpiresOn: json.Number(l.user.AuthProvider.Config["expires-in"]), | ||
ExpiresIn: l.user.AuthProvider.Config["expires-in"], | ||
ExpiresOn: l.user.AuthProvider.Config["expires-in"], |
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.
should it be "expires-on"?
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.
yep. fixed.
|
||
func (c *Cache) Run() { | ||
for { | ||
if err := c.ListWatch(); err != nil { |
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.
exponential backoff? otherwise there could be hot looping.
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.
added.
kubernetes/client/cache.go
Outdated
if res.Type == "ADDED" || res.Type == "MODIFIED" { | ||
c.AddOrUpdate(metadata, res.Object) | ||
return | ||
} else if res.Type == "DELETED" { |
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.
no need for 'else' as there is 'return' in the 'if' clause above
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.
kubernetes/client/cache.go
Outdated
// Lister is an interface for things that can list objects for all namespaces or by namespace | ||
type Lister interface { | ||
List() []interface{} | ||
ByNamespace() []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.
does it need a namespace param?
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.
yep (and added 'implements' to catch these kind of errors in the future.
kubernetes/client/cache.go
Outdated
ix := FindObject(list, metadata) | ||
if ix == -1 { | ||
return append(list, objEntry{metadata: metadata, obj: obj}), nil | ||
} else { |
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.
no need for 'else' as there is 'return' above
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.
} | ||
} | ||
|
||
func Delete(list []objEntry, metadata *V1ObjectMeta) ([]objEntry, bool) { |
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.
do you mean to expose the function?
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.
going to add tests, so yes.
return append(list[:ix], list[ix+1:]...), true | ||
} | ||
|
||
func FindObject(list []objEntry, metadata *V1ObjectMeta) int { |
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.
do you mean to expose the function?
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.
as above.
kubernetes/client/cache.go
Outdated
|
||
func (c *Cache) ProcessResult(res *Result) { | ||
metadata := c.Extractor(res.Object) | ||
if res.Type == "ADDED" || res.Type == "MODIFIED" { |
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.
better to define these event type constants somewhere (maybe in watch.go?), then reference it
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.
kubernetes/client/cache.go
Outdated
c.eventHandlers = append(c.eventHandlers, handler) | ||
} | ||
|
||
func (c *Cache) Run() { |
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.
make it 'stoppable'?
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.
Comments addressed, please re-check. Thanks! |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, yliaog 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 |
Thanks for the review! |
No description provided.