Skip to content

[WIP] Convert Flow controller to provider/reconcile model#287

Merged
google-prow-robot merged 11 commits into
knative:masterfrom
vaikas:flow-tests
Jul 27, 2018
Merged

[WIP] Convert Flow controller to provider/reconcile model#287
google-prow-robot merged 11 commits into
knative:masterfrom
vaikas:flow-tests

Conversation

@vaikas
Copy link
Copy Markdown
Contributor

@vaikas vaikas commented Jul 25, 2018

Fixes #

Proposed Changes

  • change Flow controller to be like Feed controller.

@vaikas vaikas added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 25, 2018
@google-prow-robot
Copy link
Copy Markdown

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-prow-robot google-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 25, 2018
@google-prow-robot google-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 25, 2018
Copy link
Copy Markdown
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see this @vaikas-google! I'm about halfway through, but have enough comments to submit early.

Comment thread pkg/controller/flow/reconcile.go Outdated
// MessageResourceSynced is the message used for an Event fired when a Flow
// is synced successfully
MessageResourceSynced = "Flow synced successfully"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants don't seem to be used anymore, can they be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for debugging?

// 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Get the feed from the cache (feed A)
  2. Reconcile feed A
  3. Get the feed from the cache (feed B)
  4. If the reconciled feed A status is equal to the just-retrieved feed B status, stop and do not update.
  5. Copy feed A status into feed B.
  6. 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:

  1. Get the flow from the cache (flow A)
  2. Copy flow A to original
  3. Reconcile flow A
  4. If the reconciled flow A status is equal to original status, stop and do not update.
  5. Get the flow from the cache (flow B)
  6. Copy flow A status into flow B
  7. 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).

Comment thread pkg/controller/flow/reconcile.go Outdated
}

// Requeue if the resource is not ready:
return reconcile.Result{Requeue: !flow.Status.IsReady()}, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

// Watch Jobs and enqueue owning Feed key.
if err := c.Watch(&source.Kind{Type: &batchv1.Job{}},
&handler.EnqueueRequestForOwner{OwnerType: &feedsv1alpha1.Feed{}, IsController: true}); err != nil {
return nil, err
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I think this is the only true blocker to LGTM. Everything else is minor and can be cleaned up later.

Comment thread pkg/controller/flow/reconcile.go Outdated

// 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is about a different function 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug line?

Comment thread pkg/controller/flow/reconcile.go Outdated
return "", fmt.Errorf("No resolvable action target: %+v", action)
}

// resolveObjectReference fetches an object based on ObjectRefence. It assumes the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo nit: ObjectReference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

glog.Warningf("failed to get object: %v", err)
return "", err
}
status, ok := obj.Object["status"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a future PR: might be useful to emit an event here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in that we create one? I'd expect that Channel would send an event?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I mean corev1.Event. Sorry for the ambiguity 😄

Copy link
Copy Markdown
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the rest

Comment thread pkg/controller/flow/reconcile.go Outdated
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the current code already reuses a channel with the same name. Is this TODO still needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/controller/flow/reconcile.go Outdated
return nil, err
}

// Should make sure channel is what it should be. For now, just assume it's fine
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer to add a TODO here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/controller/flow/reconcile.go Outdated

// Should make sure channel is what it should be. For now, just assume it's fine
// if it exists.
return channel, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like err can only be nil here, so it might be clearer to return channel, nil.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/controller/flow/reconcile.go Outdated

// Should make sure subscription is what it should be. For now, just assume it's fine
// if it exists.
return subscription, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like err can only be nil here, so it might be clearer to return channel, nil.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/controller/flow/reconcile.go Outdated
return nil, err
}

// Should make sure subscription is what it should be. For now, just assume it's fine
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer to add a TODO here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/controller/flow/reconcile.go Outdated
}

glog.Infof("Reconciled feed: %+v", feed)
// Should make sure feed is what it should be. For now, just assume it's fine
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer to add a TODO here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread pkg/controller/flow/reconcile.go Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like err can only be nil here, so it might be clearer to return channel, nil.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@vaikas
Copy link
Copy Markdown
Contributor Author

vaikas commented Jul 27, 2018

Thanks for the review @grantr! Addressed all the other comments except one that I want to think about some more. PTAL.

@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/controller/flow/reconcile.go Do not exist 45.2%

@vaikas vaikas removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 27, 2018
Copy link
Copy Markdown
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 27, 2018
@google-prow-robot google-prow-robot merged commit 904f403 into knative:master Jul 27, 2018
@vaikas vaikas deleted the flow-tests branch July 27, 2018 16:33
matzew pushed a commit to matzew/eventing that referenced this pull request Oct 11, 2019
Backporting patch from 071 t0 08x line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants