-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adds events for route #358
Conversation
/retest |
pkg/controller/route/controller.go
Outdated
@@ -367,7 +353,7 @@ func (c *Controller) syncTrafficTargets(route *v1alpha1.Route) (*v1alpha1.Route, | |||
} | |||
|
|||
// Then create the actual route rules. | |||
glog.Infof("Creating istio route rules") | |||
glog.Infof("Creating Istio route rules") |
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.
nit: no format args
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/route/controller.go
Outdated
@@ -389,26 +375,33 @@ func (c *Controller) syncTrafficTargets(route *v1alpha1.Route) (*v1alpha1.Route, | |||
updated, err := c.updateStatus(route) | |||
if err != nil { | |||
glog.Warningf("Failed to update service status: %s", err) | |||
c.recorder.Event(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to update traffic targets") |
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.
@vaikas-google should we surface err
here?
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.
Probably, makes sense, otherwise the user knows something went wrong, but not what. We should also add details here about which route failed or succeeded. Otherwise, messages of the form (from the PR description):
Normal Updated 29s (x6 over 1m) route-controller Updated traffic targets
don't provide enough information to figure out what happened.
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 the err.
pkg/controller/route/controller.go
Outdated
if err != nil { | ||
if !apierrs.IsAlreadyExists(err) { | ||
glog.Infof("Failed to create service: %s", err) | ||
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create service: %s", service.Name) |
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.
Include err
here unless @vaikas-google thinks that's inappropriate.
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/route/controller.go
Outdated
@@ -428,8 +421,13 @@ func (c *Controller) createOrUpdateIngress(route *v1alpha1.Route, ns string) err | |||
return err | |||
} | |||
_, createErr := ic.Create(ingress) | |||
if createErr != nil { | |||
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create Ingress: %s", ingress.Name) |
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.
Include 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.
Done.
pkg/controller/route/controller.go
Outdated
@@ -428,8 +421,13 @@ func (c *Controller) createOrUpdateIngress(route *v1alpha1.Route, ns string) err | |||
return err | |||
} | |||
_, createErr := ic.Create(ingress) | |||
if createErr != 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.
Prefer: if _, err := ic.Create(); 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.
There are a bunch of these if you are up for changing them :)
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.
+1 :)
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/route/controller.go
Outdated
@@ -627,15 +627,21 @@ func (c *Controller) createOrUpdateRoutes(route *v1alpha1.Route, configMap map[s | |||
return nil, err | |||
} | |||
routeRules = MakeRouteIstioRoutes(route, ns, revisionRoutes) | |||
_, createErr := routeClient.Create(routeRules) | |||
return revisionRoutes, createErr | |||
if _, createErr := routeClient.Create(routeRules); createErr != 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.
nit: use 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.
Done.
pkg/controller/route/controller.go
Outdated
_, createErr := routeClient.Create(routeRules) | ||
return revisionRoutes, createErr | ||
if _, createErr := routeClient.Create(routeRules); createErr != nil { | ||
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create Istio route rule: %s", routeRules.Name) |
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.
include 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.
Added.
pkg/controller/route/controller.go
Outdated
} | ||
|
||
routeRules.Spec = MakeRouteIstioSpec(route, ns, revisionRoutes) | ||
_, err = routeClient.Update(routeRules) | ||
if err != nil { | ||
if _, err := routeClient.Update(routeRules); err != nil { | ||
c.recorder.Eventf(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to update Istio route rule: %s", routeRules.Name) |
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.
include 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.
Added.
pkg/controller/route/controller.go
Outdated
return nil, err | ||
} | ||
c.recorder.Eventf(route, corev1.EventTypeNormal, "Updated", "Updated Istio route rule: %s", routeRules.Name) |
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'd like to better understand the wisdom of the parameter in the "Updated"
position.
Is this purely informational (terse) or expected to be more like an enumeration that clients can operate on programmatically? I'm trying to capture some of this for Status.Condition
convention here, but am not sure what the wisdom is for events?
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.
TBH, IDK neither. From the Event source code, it says Reason
is machine understandable string that gives the reason for the transition into the object's current status.
Here are some samples of events created by k8s:
7m 7m 1 p-79de88cc-3791-4370-b6c0-5197d2cd1705-autoscaler-d7c5c6554z2rn.151be65f06790b80 Pod spec.containers{autoscaler} Normal Pulled kubelet, gke-elafros-demo-default-pool-8d4847e8-xw93 Container image "gcr.io/yanweiguo-test/ela-autoscaler@sha256:ffc20211794a1ea1298a6584797db4f5317b892c0970bd8129e65d0b68542a2a" already present on machine
7m 7m 1 p-79de88cc-3791-4370-b6c0-5197d2cd1705-autoscaler-d7c5c6554z2rn.151be65f09dc92c2 Pod spec.containers{autoscaler} Normal Created kubelet, gke-elafros-demo-default-pool-8d4847e8-xw93 Created container
7m 7m 1 p-79de88cc-3791-4370-b6c0-5197d2cd1705-autoscaler-d7c5c6554z2rn.151be65f10809f19 Pod spec.containers{autoscaler} Normal Started kubelet, gke-elafros-demo-default-pool-8d4847e8-xw93
I just followed that to use Created
or Updated
.
pkg/controller/route/controller.go
Outdated
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create Ingress: %s", ingress.Name) | ||
return createErr | ||
} | ||
c.recorder.Eventf(route, corev1.EventTypeNormal, "Created", "Created Ingress: %s", ingress.Name) |
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 we make this "IngressCreated"
? IDK what's typical here.
pkg/controller/route/controller.go
Outdated
@@ -389,26 +375,33 @@ func (c *Controller) syncTrafficTargets(route *v1alpha1.Route) (*v1alpha1.Route, | |||
updated, err := c.updateStatus(route) | |||
if err != nil { | |||
glog.Warningf("Failed to update service status: %s", err) | |||
c.recorder.Event(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to update traffic targets") |
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.
Probably, makes sense, otherwise the user knows something went wrong, but not what. We should also add details here about which route failed or succeeded. Otherwise, messages of the form (from the PR description):
Normal Updated 29s (x6 over 1m) route-controller Updated traffic targets
don't provide enough information to figure out what happened.
pkg/controller/route/controller.go
Outdated
return nil, err | ||
} | ||
|
||
c.recorder.Event(route, corev1.EventTypeNormal, "Updated", "Updated traffic targets") |
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.
Could you add the route name to all these messages. The other messages are nice because you can see what happened and to which object.
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/route/controller.go
Outdated
@@ -428,8 +421,13 @@ func (c *Controller) createOrUpdateIngress(route *v1alpha1.Route, ns string) err | |||
return err | |||
} | |||
_, createErr := ic.Create(ingress) | |||
if createErr != 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.
+1 :)
pkg/controller/route/controller.go
Outdated
config.Name, ela.RouteLabelKey, routeName) | ||
c.recorder.Event(route, corev1.EventTypeWarning, "InvalidConfiguration", errMsg) | ||
return errors.New(errMsg) |
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 don't actually know what the best practices here really are. I think logs/events have different retain policies and you could maybe have different rbac rules, etc. Perhaps we should file an issue on this.
At the very least we should clean up our logs:
#361
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.
Looks great! Thanks for doing this, the one request is global replace of '%s' with %q for fmt. arguments.
@@ -294,11 +294,11 @@ func (c *Controller) syncHandler(key string) error { | |||
created, err := c.elaclientset.BuildV1alpha1().Builds(build.Namespace).Create(build) | |||
if err != nil { | |||
glog.Errorf("Failed to create Build:\n%+v\n%s", build, err) | |||
c.recorder.Eventf(config, corev1.EventTypeWarning, "CreationFailed", "Failed to create Build: %s", build.Name) | |||
c.recorder.Eventf(config, corev1.EventTypeWarning, "CreationFailed", "Failed to create Build '%s': %s", build.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.
Instead of '%s' could you change these to %q
https://golang.org/pkg/fmt/
%q a double-quoted string safely escaped with Go syntax
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. Good to know this. Thanks!
return err | ||
} | ||
glog.Infof("Created Build:\n%+v", created.Name) | ||
c.recorder.Eventf(config, corev1.EventTypeNormal, "Created", "Created Build: %s", created.Name) | ||
c.recorder.Eventf(config, corev1.EventTypeNormal, "Created", "Created Build '%s'", created.Name) |
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.
Same here and elsewhere where you use '%s' format.
@@ -209,12 +209,12 @@ func (c *Controller) processNextWorkItem() bool { | |||
// Run the syncHandler, passing it the namespace/name string of the | |||
// Foo resource to be synced. | |||
if err := c.syncHandler(key); err != nil { | |||
return fmt.Errorf("error syncing '%s': %s", key, err.Error()) | |||
return fmt.Errorf("error syncing %q: %s", key, err.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.
This shouldn't use err.Error()
, but should instead use %v
and just err
.
@@ -294,11 +294,11 @@ func (c *Controller) syncHandler(key string) error { | |||
created, err := c.elaclientset.BuildV1alpha1().Builds(build.Namespace).Create(build) | |||
if err != nil { | |||
glog.Errorf("Failed to create Build:\n%+v\n%s", build, err) | |||
c.recorder.Eventf(config, corev1.EventTypeWarning, "CreationFailed", "Failed to create Build: %s", build.Name) | |||
c.recorder.Eventf(config, corev1.EventTypeWarning, "CreationFailed", "Failed to create Build %q: %s", build.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.
use %v
for err
@@ -328,10 +328,10 @@ func (c *Controller) syncHandler(key string) error { | |||
created, err := c.elaclientset.ElafrosV1alpha1().Revisions(config.Namespace).Create(rev) | |||
if err != nil { | |||
glog.Errorf("Failed to create Revision:\n%+v\n%s", rev, err) | |||
c.recorder.Eventf(config, corev1.EventTypeWarning, "CreationFailed", "Failed to create Revision: %s", rev.Name) | |||
c.recorder.Eventf(config, corev1.EventTypeWarning, "CreationFailed", "Failed to create Revision %q: %s", rev.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.
%v
pkg/controller/route/controller.go
Outdated
@@ -375,10 +375,10 @@ func (c *Controller) syncTrafficTargets(route *v1alpha1.Route) (*v1alpha1.Route, | |||
updated, err := c.updateStatus(route) | |||
if err != nil { | |||
glog.Warningf("Failed to update service status: %s", err) | |||
c.recorder.Event(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to update traffic targets") | |||
c.recorder.Eventf(route, corev1.EventTypeWarning, "UpdateFailed", "Failed to update status for route '%s': %s", route.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.
%q
and %v
pkg/controller/route/controller.go
Outdated
return nil, err | ||
} | ||
c.recorder.Event(route, corev1.EventTypeNormal, "Updated", "Updated traffic targets") | ||
c.recorder.Eventf(route, corev1.EventTypeNormal, "Updated", "Updated status for route '%s'", route.Name) |
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
pkg/controller/route/controller.go
Outdated
return nil, err | ||
} | ||
|
||
c.recorder.Eventf(route, corev1.EventTypeNormal, "Updated", "Updated status for route '%s'", route.Name) |
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
pkg/controller/route/controller.go
Outdated
if !apierrs.IsAlreadyExists(err) { | ||
glog.Infof("Failed to create service: %s", err) | ||
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create service '%s': %s", service.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.
%q
and %v
pkg/controller/route/controller.go
Outdated
} | ||
glog.Infof("Created service: %q", service.Name) | ||
if newlyCreated { | ||
c.recorder.Eventf(route, corev1.EventTypeNormal, "Created", "Created service '%s'", service.Name) |
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
pkg/controller/route/controller.go
Outdated
if !apierrs.IsNotFound(err) { | ||
return err | ||
} | ||
_, createErr := ic.Create(ingress) | ||
if _, err := ic.Create(ingress); err != nil { | ||
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create Ingress '%s': %s", ingress.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.
%q
and %v
pkg/controller/route/controller.go
Outdated
c.recorder.Eventf(route, corev1.EventTypeWarning, "CreationFailed", "Failed to create Ingress '%s': %s", ingress.Name, err) | ||
return err | ||
} | ||
c.recorder.Eventf(route, corev1.EventTypeNormal, "Created", "Created Ingress '%s'", ingress.Name) |
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
/retest |
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.
thanks for bearing with my tidal wave of nits :)
I spotted one typo, but otherwise this LGTM.
-M
@@ -277,12 +277,12 @@ func (c *Controller) processNextWorkItem() bool { | |||
// Run the syncHandler, passing it the namespace/name string of the | |||
// Foo resource to be synced. | |||
if err := c.syncHandler(key); err != nil { | |||
return fmt.Errorf("error syncing '%s': %s", key, err.Error()), controller.PromLabelValueFailure | |||
return fmt.Errorf("error syncing %q: %vs", key, err), controller.PromLabelValueFailure |
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.
typo: %vs
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.
@@ -625,7 +625,7 @@ func TestMarkRevReadyUponEndpointBecomesReady(t *testing.T) { | |||
// Look for the revision ready event. | |||
h.OnCreate(&kubeClient.Fake, "events", func(obj runtime.Object) hooks.HookResult { | |||
event := obj.(*corev1.Event) | |||
expectedMessage := "Revision becomes ready upon endpoint 'test-endpoints' becoming ready" | |||
expectedMessage := "Revision becomes ready upon endpoint \"test-endpoints\" becoming ready" |
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 change needed, but FYI: if you use `Strings "like" this` you can avoid escaping.
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.
Good to know. Thanks.
/retest |
Co-authored-by: Kenjiro Nakayama <nakayamakenjiro@gmail.com>
Adds following events:
Sample output:
Also improves the tests for controllers:
Closes #8 #12