Add configmap for flow controller#324
Conversation
|
I'm looking at the unit failure now |
4476026 to
f49faec
Compare
grantr
left a comment
There was a problem hiding this comment.
/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. |
There was a problem hiding this comment.
Is the key default-cluster-bus or default-cluster-bus-name?
f49faec to
441962e
Compare
441962e to
434a716
Compare
|
/retest |
|
/retest 🎲 🎲 |
434a716 to
fd4fb04
Compare
|
@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? |
|
/retest |
|
Hrm, reading this, what you proposed now looks obviously better and more idiomatic, so I'll do it in this PR. |
fd4fb04 to
2b48572
Compare
acd6b98 to
c89e25e
Compare
|
@grantr feedbacks addressed, should be ready now |
|
/retest |
6a58eaf to
1e9a1ac
Compare
| }, | ||
| Spec: channelsv1alpha1.ChannelSpec{ | ||
| ClusterBus: defaultBusName, | ||
| ClusterBus: clusterBusName, |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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". |
There was a problem hiding this comment.
Is this something which should be handled through an Informer in the future (it's fine to leave this as a TODO)?
There was a problem hiding this comment.
Do you need to update https://github.com/knative/eventing/blob/master/config/200-clusterrole.yaml ?
There was a problem hiding this comment.
No, it turns out that we don't care about roles: https://github.com/knative/eventing/blob/master/config/201-clusterrolebinding.yaml (cluster-admin)
There was a problem hiding this comment.
The controller-runtime client handles maintaining informers automatically - pretty neat huh?
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
|
/hold cancel |
| } | ||
|
|
||
| func (r *reconciler) createChannel(flow *v1alpha1.Flow) (*channelsv1alpha1.Channel, error) { | ||
| clusterBusName, err := r.getDefaultClusterBusName() |
There was a problem hiding this comment.
We should add an issue that we should make it possible for a flow to use a Bus or a ClusterBus
There was a problem hiding this comment.
Yep, I'll create that issue.
|
/hold cancel |
|
I wonder why the first /poke tide |
1e9a1ac to
7ec0cbd
Compare
|
The following is the coverage report on pkg/.
|
evankanderson
left a comment
There was a problem hiding this comment.
/lgtm
Someone should remove the TODO on 39 and the definition on line 40 of defaultBusName, but let's get this PR in.
Co-authored-by: pierDipi <pierDipi@users.noreply.github.com>
Replaces #240, closes #209