-
Notifications
You must be signed in to change notification settings - Fork 601
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
Add configmap for flow controller #324
Conversation
I'm looking at the unit failure now |
4476026
to
f49faec
Compare
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.
/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
}
pkg/controller/flow/provider.go
Outdated
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.
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
?
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 |
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.
/lgtm
6a58eaf
to
1e9a1ac
Compare
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.
/approve
pkg/controller/flow/reconcile.go
Outdated
@@ -232,7 +239,7 @@ func (r *reconciler) createChannel(flow *v1alpha1.Flow) (*channelsv1alpha1.Chann | |||
}, | |||
}, | |||
Spec: channelsv1alpha1.ChannelSpec{ | |||
ClusterBus: defaultBusName, | |||
ClusterBus: clusterBusName, |
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.
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.
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". |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to update https://github.com/knative/eventing/blob/master/config/200-clusterrole.yaml ?
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.
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.
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?
[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 |
/lgtm |
/hold cancel |
pkg/controller/flow/reconcile.go
Outdated
@@ -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() |
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.
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.
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.
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.
Created #336
/hold cancel |
I wonder why the first /poke tide |
1e9a1ac
to
7ec0cbd
Compare
The following is the coverage report on pkg/.
|
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.
/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