[WIP] Convert Flow controller to provider/reconcile model#287
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vaikas-google The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
grantr
left a comment
There was a problem hiding this comment.
Love to see this @vaikas-google! I'm about halfway through, but have enough comments to submit early.
| // MessageResourceSynced is the message used for an Event fired when a Flow | ||
| // is synced successfully | ||
| MessageResourceSynced = "Flow synced successfully" | ||
| ) |
There was a problem hiding this comment.
These constants don't seem to be used anymore, can they be removed?
|
|
||
| // Reconcile compares the actual state with the desired, and attempts to | ||
| // converge the two. It then updates the Status block of the Flow resource | ||
| // with the current status of the resource. |
There was a problem hiding this comment.
This is a better comment than feed.Reconcile() has, I'll steal it 😄
| // converge the two. It then updates the Status block of the Flow resource | ||
| // with the current status of the resource. | ||
| func (r *reconciler) Reconcile(request reconcile.Request) (reconcile.Result, error) { | ||
| glog.Infof("Reconciling flow %v", request) |
| // If we didn't change anything then don't call updateStatus. | ||
| // This is important because the copy we loaded from the informer's | ||
| // cache may be stale and we don't want to overwrite a prior update | ||
| // to status with this stale state. |
There was a problem hiding this comment.
This update handling is different from the feed controller and I'm curious why. Did you run into issues, or is there a bug in the feed controller's update handling?
The feed controller does this:
- Get the feed from the cache (feed A)
- Reconcile feed A
- Get the feed from the cache (feed B)
- If the reconciled feed A status is equal to the just-retrieved feed B status, stop and do not update.
- Copy feed A status into feed B.
- Update feed B. This update will fail if the feed has been updated by something else since feed B was retrieved (because the apiserver will reject the feed B resourceVersion).
The flow controller does this:
- Get the flow from the cache (flow A)
- Copy flow A to original
- Reconcile flow A
- If the reconciled flow A status is equal to original status, stop and do not update.
- Get the flow from the cache (flow B)
- Copy flow A status into flow B
- Update flow B. This update will fail if the feed has been updated by something else since feed B was retrieved (because the apiserver will reject the feed B resourceVersion).
| } | ||
|
|
||
| // Requeue if the resource is not ready: | ||
| return reconcile.Result{Requeue: !flow.Status.IsReady()}, err |
There was a problem hiding this comment.
Instead of relying on requeue to progress to ready, the flow controller should watch the resources that, when changed, indicate progress toward readiness. My guess is that by watching Feeds, Channels, and Subscriptions, this Requeue will be unnecessary.
The feed controller does this by watching Jobs:
eventing/pkg/controller/feed/provider.go
Lines 58 to 62 in bc26d36
There was a problem hiding this comment.
FYI I think this is the only true blocker to LGTM. Everything else is minor and can be cleaned up later.
|
|
||
| // syncHandler compares the actual state with the desired, and attempts to | ||
| // converge the two. It then updates the Status block of the Flow resource | ||
| // with the current status of the resource. |
There was a problem hiding this comment.
This comment is about a different function 😄
| // converge the two. It then updates the Status block of the Flow resource | ||
| // with the current status of the resource. | ||
| func (r *reconciler) resolveActionTarget(namespace string, action v1alpha1.FlowAction) (string, error) { | ||
| glog.Infof("Resolving target: %+v", action) |
| return "", fmt.Errorf("No resolvable action target: %+v", action) | ||
| } | ||
|
|
||
| // resolveObjectReference fetches an object based on ObjectRefence. It assumes the |
| glog.Warningf("failed to get object: %v", err) | ||
| return "", err | ||
| } | ||
| status, ok := obj.Object["status"] |
| channel := &channelsv1alpha1.Channel{} | ||
| err := r.client.Get(context.TODO(), client.ObjectKey{Namespace: flow.Namespace, Name: channelName}, channel) | ||
| if errors.IsNotFound(err) { | ||
| channel, err = r.createChannel(flow) |
There was a problem hiding this comment.
For a future PR: might be useful to emit an event here
There was a problem hiding this comment.
As in that we create one? I'd expect that Channel would send an event?
There was a problem hiding this comment.
Oh I mean corev1.Event. Sorry for the ambiguity 😄
| glog.Infof("Resolved Target to: %q", target) | ||
|
|
||
| // Reconcile the Channel. Creates a channel that is the target that the Feed will use. | ||
| // TODO: We should reuse channels possibly. |
There was a problem hiding this comment.
Looks like the current code already reuses a channel with the same name. Is this TODO still needed?
There was a problem hiding this comment.
sorry, it could re-use a channel (not by name but type or something like that) and only create a subscription. Right now it creates 1:1 (channel:subscription). Tried to clarify the comment.
| return nil, err | ||
| } | ||
|
|
||
| // Should make sure channel is what it should be. For now, just assume it's fine |
There was a problem hiding this comment.
Might be clearer to add a TODO here.
|
|
||
| // Should make sure channel is what it should be. For now, just assume it's fine | ||
| // if it exists. | ||
| return channel, err |
There was a problem hiding this comment.
Seems like err can only be nil here, so it might be clearer to return channel, nil.
|
|
||
| // Should make sure subscription is what it should be. For now, just assume it's fine | ||
| // if it exists. | ||
| return subscription, err |
There was a problem hiding this comment.
Seems like err can only be nil here, so it might be clearer to return channel, nil.
| return nil, err | ||
| } | ||
|
|
||
| // Should make sure subscription is what it should be. For now, just assume it's fine |
There was a problem hiding this comment.
Might be clearer to add a TODO here.
| } | ||
|
|
||
| glog.Infof("Reconciled feed: %+v", feed) | ||
| // Should make sure feed is what it should be. For now, just assume it's fine |
There was a problem hiding this comment.
Might be clearer to add a TODO here.
| glog.Infof("Reconciled feed: %+v", feed) | ||
| // Should make sure feed is what it should be. For now, just assume it's fine | ||
| // if it exists. | ||
| return feed, err |
There was a problem hiding this comment.
Seems like err can only be nil here, so it might be clearer to return channel, nil.
|
Thanks for the review @grantr! Addressed all the other comments except one that I want to think about some more. PTAL. |
|
The following is the coverage report on pkg/.
|
Backporting patch from 071 t0 08x line
Fixes #
Proposed Changes