-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Always call updateStatus after Reconcile. #1321
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,18 @@ func (c *Controller) updateRouteEvent(key string) error { | |
| } | ||
| // Don't modify the informers copy | ||
| route = route.DeepCopy() | ||
|
|
||
| // Reconcile this copy of the route and then write back any status | ||
| // updates regardless of whether the reconciliation errored out. | ||
| err = c.reconcile(ctx, route) | ||
| if _, err := c.updateStatus(ctx, route); err != nil { | ||
| return err | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (c *Controller) reconcile(ctx context.Context, route *v1alpha1.Route) error { | ||
| logger := logging.FromContext(ctx) | ||
| route.Status.InitializeConditions() | ||
|
|
||
| logger.Infof("Reconciling route :%v", route) | ||
|
|
@@ -204,10 +216,10 @@ func (c *Controller) updateRouteEvent(key string) error { | |
| return err | ||
| } | ||
|
|
||
| // Call syncTrafficTargetsAndUpdateRouteStatus, which also updates the Route.Status | ||
| // Call syncTrafficTargets, which also updates the Route.Status | ||
| // to contain the domain we will use for Ingress creation. | ||
|
|
||
| if _, err := c.syncTrafficTargetsAndUpdateRouteStatus(ctx, route); err != nil { | ||
| if _, err := c.syncTrafficTargets(ctx, route); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -217,10 +229,7 @@ func (c *Controller) updateRouteEvent(key string) error { | |
| logger.Error("Failed to create or update ingress rule", zap.Error(err)) | ||
| return err | ||
| } | ||
|
|
||
| logger.Info("Route successfully synced") | ||
| _, err = c.updateStatus(ctx, route) | ||
| return err | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Controller) getDomainConfig() *DomainConfig { | ||
|
|
@@ -240,10 +249,10 @@ func (c *Controller) routeDomain(route *v1alpha1.Route) string { | |
| return fmt.Sprintf("%s.%s.%s", route.Name, route.Namespace, domain) | ||
| } | ||
|
|
||
| // syncTrafficTargetsAndUpdateRouteStatus attempts to converge the actual state and desired state | ||
| // syncTrafficTargets attempts to converge the actual state and desired state | ||
| // according to the traffic targets in Spec field for Route resource. It then updates the Status | ||
| // block of the Route and returns the updated one. | ||
| func (c *Controller) syncTrafficTargetsAndUpdateRouteStatus(ctx context.Context, route *v1alpha1.Route) (*v1alpha1.Route, error) { | ||
| func (c *Controller) syncTrafficTargets(ctx context.Context, route *v1alpha1.Route) (*v1alpha1.Route, error) { | ||
| logger := logging.FromContext(ctx) | ||
| c.consolidateTrafficTargets(ctx, route) | ||
| configMap, revMap, err := c.getDirectTrafficTargets(ctx, route) | ||
|
|
@@ -292,7 +301,7 @@ func (c *Controller) syncTrafficTargetsAndUpdateRouteStatus(ctx context.Context, | |
| route.Status.Traffic = traffic | ||
| } | ||
| route.Status.Domain = c.routeDomain(route) | ||
| return c.updateStatus(ctx, route) | ||
| return route, nil | ||
| } | ||
|
|
||
| func (c *Controller) reconcilePlaceholderService(ctx context.Context, route *v1alpha1.Route) error { | ||
|
|
@@ -358,10 +367,6 @@ func (c *Controller) getDirectTrafficTargets(ctx context.Context, route *v1alpha | |
| logger.Infof("Failed to fetch Configuration %q: %v", configName, err) | ||
| if apierrs.IsNotFound(err) { | ||
| route.Status.MarkTrafficNotAssigned("Configuration", configName) | ||
| if _, err := c.updateStatus(ctx, route); err != nil { | ||
| // If we failed to update the status, return that error instead of the "config not found" error. | ||
| return nil, nil, err | ||
| } | ||
| } | ||
| return nil, nil, err | ||
| } | ||
|
|
@@ -373,10 +378,6 @@ func (c *Controller) getDirectTrafficTargets(ctx context.Context, route *v1alpha | |
| logger.Infof("Failed to fetch Revision %q: %v", revName, err) | ||
| if apierrs.IsNotFound(err) { | ||
| route.Status.MarkTrafficNotAssigned("Revision", revName) | ||
| if _, err := c.updateStatus(ctx, route); err != nil { | ||
| // If we failed to update the status, return that error instead of the "revision not found" error. | ||
| return nil, nil, err | ||
| } | ||
| } | ||
| return nil, nil, err | ||
| } | ||
|
|
@@ -446,10 +447,6 @@ func (c *Controller) extendRevisionsWithIndirectTrafficTargets( | |
| logger.Errorf("Failed to fetch Revision %s: %s", revName, err) | ||
| if apierrs.IsNotFound(err) { | ||
| route.Status.MarkTrafficNotAssigned("Revision", revName) | ||
| if _, err := c.updateStatus(ctx, route); err != nil { | ||
| // If we failed to update the status, return that error instead of the "revision not found" error. | ||
| return err | ||
| } | ||
| } | ||
| return err | ||
| } | ||
|
|
@@ -969,9 +966,10 @@ func (c *Controller) SyncConfiguration(config *v1alpha1.Configuration) { | |
|
|
||
| // Don't modify the informers copy | ||
| route = route.DeepCopy() | ||
| if _, err := c.syncTrafficTargetsAndUpdateRouteStatus(ctx, route); err != nil { | ||
| if _, err := c.syncTrafficTargets(ctx, route); err != nil { | ||
| logger.Error("Error updating route upon configuration becoming ready", zap.Error(err)) | ||
| } | ||
| c.updateStatus(ctx, route) | ||
| } | ||
|
|
||
| func (c *Controller) SyncIngress(ingress *v1beta1.Ingress) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Curious what you think about not splitting these methods but having this as a top level
defercallThere 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 thought about this, but this felt clearer (less magical) to me. One thing that makes hard is returning an error on
updateStatus(you need to use named return values).LMK if you feel strongly (the naming could also be more original, but nothing else felt appreciably better).
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 feel strongly - was just wondering if you considered it