Skip to content
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 configmap for flow controller #324

Merged
merged 1 commit into from
Aug 13, 2018

Conversation

pmorie
Copy link
Member

@pmorie pmorie commented Aug 6, 2018

Replaces #240, closes #209

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 6, 2018
@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 6, 2018
@pmorie
Copy link
Member Author

pmorie commented Aug 6, 2018

I'm looking at the unit failure now

@pmorie pmorie force-pushed the flow-controller-config branch 5 times, most recently from 4476026 to f49faec Compare August 6, 2018 19:50
Copy link
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

This seems reasonable, but given the goals of this PR, I'm curious why the watch is needed.

Here's what I understand of the goal:

  • During Flow reconcile, if a channel should be created, set the created channel's bus name to a default value.
  • If a channel already exists, never set its bus value again, even if the default changes.

IIUC the original solution for this in knative/serving was to create an informer and use its cache to get the configmap values when needed. But serving has a lot of configmaps and controllers, so it quickly became a big pain to manage all those informer declarations. The configmap package was written to wrap up the configmap informer initialization so the controller constructor can just write an event handler function to persist the change. This was a nice improvement in code size and readability.

The controller-runtime client takes a different approach, handling creation of all informers automatically and serving all Get calls out of informer caches. IMO this makes the configmap package unnecessary, since it serves the same purpose of eliminating informer declarations and allowing the configmap values to be retrieved when they're needed.

So I'm curious whether something like this would be easier to write, read, test, or maintain:

// pseudocode

const configMapKey = client.ObjectKey{
  Namespace: system.Namespace,
  Name: "flow-controller-config",
}

func (r *reconciler) getDefaultClusterBus() (string, error) {
  configMap := &corev1.ConfigMap{}
  if err := r.client.Get(context.TODO(), configMapKey, configMap); err != nil {
    return nil, err
  }

  if value, ok := configMap.Data[defaultClusterBusConfigMapKey]; ok {
    return value, nil
  }
  return "stub", nil // or return an error
}

controllerConfigMapWatcher configmap.Watcher
// defaultBusName is the default bus name to use to create channels; it is
// updated if the knative-system/flow-controller-config ConfigMap exists and
// contains the 'default-cluster-bus-name' key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the key default-cluster-bus or default-cluster-bus-name?

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 6, 2018
@pmorie pmorie force-pushed the flow-controller-config branch from f49faec to 441962e Compare August 6, 2018 22:08
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 6, 2018
@pmorie pmorie force-pushed the flow-controller-config branch from 441962e to 434a716 Compare August 6, 2018 22:18
@pmorie
Copy link
Member Author

pmorie commented Aug 6, 2018

/retest

@pmorie
Copy link
Member Author

pmorie commented Aug 6, 2018

/retest

🎲 🎲

@pmorie pmorie force-pushed the flow-controller-config branch from 434a716 to fd4fb04 Compare August 7, 2018 04:16
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 7, 2018
@pmorie
Copy link
Member Author

pmorie commented Aug 7, 2018

@grantr reading from an informer is acceptable here, I think. I know people have wanted this feature - how about I do a refactor in a follow-up?

@pmorie
Copy link
Member Author

pmorie commented Aug 7, 2018

/retest

@pmorie
Copy link
Member Author

pmorie commented Aug 7, 2018

Hrm, reading this, what you proposed now looks obviously better and more idiomatic, so I'll do it in this PR.

@pmorie pmorie force-pushed the flow-controller-config branch from fd4fb04 to 2b48572 Compare August 7, 2018 15:11
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 7, 2018
@pmorie pmorie force-pushed the flow-controller-config branch 2 times, most recently from acd6b98 to c89e25e Compare August 7, 2018 15:30
@pmorie pmorie changed the title WIP: add configmap for flow controller Add configmap for flow controller Aug 7, 2018
@pmorie
Copy link
Member Author

pmorie commented Aug 8, 2018

@grantr feedbacks addressed, should be ready now

@pmorie pmorie closed this Aug 8, 2018
@pmorie pmorie reopened this Aug 8, 2018
@pmorie
Copy link
Member Author

pmorie commented Aug 8, 2018

/retest

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2018
Copy link
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

@pmorie pmorie force-pushed the flow-controller-config branch from 6a58eaf to 1e9a1ac Compare August 8, 2018 22:01
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2018
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/approve

@@ -232,7 +239,7 @@ func (r *reconciler) createChannel(flow *v1alpha1.Flow) (*channelsv1alpha1.Chann
},
},
Spec: channelsv1alpha1.ChannelSpec{
ClusterBus: defaultBusName,
ClusterBus: clusterBusName,
Copy link
Member

Choose a reason for hiding this comment

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

Remove defaultBusName on line 40?

const (
// controllerConfigMapName is the name of the configmap in the eventing
// namespace that holds the configuration for this controller.
controllerConfigMapName = "flow-controller-config"
Copy link
Member

Choose a reason for hiding this comment

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

controllerAgentName + "-config" ?


// getDefaultClusterBusName returns the value of the 'default-cluster-bus' key in
// the knative-system/flow-controller-config configmap or an error. If the
// 'default-cluster-bus' key is not set, it returns the default value "stub".
Copy link
Member

Choose a reason for hiding this comment

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

Is this something which should be handled through an Informer in the future (it's fine to leave this as a TODO)?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

No, it turns out that we don't care about roles: https://github.com/knative/eventing/blob/master/config/201-clusterrolebinding.yaml (cluster-admin)

Copy link
Member Author

Choose a reason for hiding this comment

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

The controller-runtime client handles maintaining informers automatically - pretty neat huh?

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, grantr, pmorie

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 8, 2018
@evankanderson
Copy link
Member

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2018
@pmorie
Copy link
Member Author

pmorie commented Aug 9, 2018

/hold cancel

@@ -222,6 +224,11 @@ func (r *reconciler) reconcileChannel(flow *v1alpha1.Flow) (*channelsv1alpha1.Ch
}

func (r *reconciler) createChannel(flow *v1alpha1.Flow) (*channelsv1alpha1.Channel, error) {
clusterBusName, err := r.getDefaultClusterBusName()
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add an issue that we should make it possible for a flow to use a Bus or a ClusterBus

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I'll create that issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #336

@pmorie
Copy link
Member Author

pmorie commented Aug 9, 2018

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 9, 2018
@grantr
Copy link
Contributor

grantr commented Aug 9, 2018

I wonder why the first /hold cancel didn't work. Maybe a failed delivery?

/poke tide

@pmorie pmorie force-pushed the flow-controller-config branch from 1e9a1ac to 7ec0cbd Compare August 13, 2018 15:36
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
@knative-metrics-robot
Copy link

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 44.3% 44.9% 0.6

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2018
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/lgtm

Someone should remove the TODO on 39 and the definition on line 40 of defaultBusName, but let's get this PR in.

@knative-prow-robot knative-prow-robot merged commit 3d956ce into knative:master Aug 13, 2018
n3wscott pushed a commit to n3wscott/eventing that referenced this pull request Aug 14, 2018
pierDipi added a commit to pierDipi/eventing that referenced this pull request Aug 31, 2023
Co-authored-by: pierDipi <pierDipi@users.noreply.github.com>
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a ConfigMap for configuring which bus to use by default
6 participants