Skip to content
This repository was archived by the owner on Jun 19, 2022. It is now read-only.

[WIP] Add Targets Config Map Reconciler #914

Closed
wants to merge 1 commit into from

Conversation

ian-mi
Copy link
Contributor

@ian-mi ian-mi commented Apr 21, 2020

Closes #830

Proposed Changes

  • Add a targets configmap reconciler which is responsible for writing broker config changes to the targets configmap.
  • Create a simple BrokerConfigUpdater through which the broker reconciler can communicate with the targets reconciler.

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ian-mi

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

@googlebot googlebot added the cla: yes (override cla status due to multiple authors bug) label Apr 21, 2020
@ian-mi ian-mi force-pushed the targets-reconciler branch from 7f81d18 to 29e3d34 Compare April 22, 2020 02:36
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-google-knative-gcp-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/broker/broker.go 58.4% 70.4% 12.0
pkg/reconciler/broker/controller.go 81.8% 89.5% 7.7
pkg/reconciler/broker/targets.go Do not exist 76.2%
pkg/reconciler/broker/trigger.go 58.4% 55.9% -2.6

targetsName: targetsName,
targetsNS: targetsNS,
updateCh: make(chan updateReq),
configMaps: client.CoreV1().ConfigMaps(targetsNS),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use a real client rather than a configmap lister here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reconciler needs to be able to update the configmap as well.

return nil
}

func (r *targetsReconciler) reconcile(ctx context.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm finding this method difficult to read and understand without comments. Can you add some comments explaining the flow?

It's not clear to me how this approach differs from using a mutex (but probably it does):

// pseudocode
func UpdateBrokerConfig(b) error {
  mtxx.Lock()
  defer mtx.Unlock()
 
  // TODO update targets 

  return writeTargets()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This approach uses a single goroutine to guard access to state. This achieves more or less the same thing as a mutex but has the advantage that code executed within this goroutine does not need to worry about locking. Since all communication happens over channels it easy for the main goroutine to select on a resync channel for example without worrying about locking. Channels also allow for cancellation where mutexes do not.

The end result is that this reconciler combines the communication of state changes and serialization of config updates that was provided by the old targets updater goroutine with the protection of mutable state provided by in memory targets data structure.

Copy link
Member

Choose a reason for hiding this comment

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

I'm likely biased. But I really don't see a point of forcing channel adoption in this case. This approach here seems to leak a lot of internals of targets config while IMO the reconciler should only worry about reading/writing the configmap data. It would be much easier for me to agree with such a change if update logic can be better wrapper within the targets config lib.

return r
}

func (r *targetsReconciler) UpdateBrokerConfig(ctx context.Context, b *config.Broker) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the complexity here is aimed at allowing multiple threads to call this method concurrently and get an error back (which the previous implementation didn't allow).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this allows the serialization and batching of writes across multiple reconcile goroutines while providing a blocking interface to the caller.

@ian-mi
Copy link
Contributor Author

ian-mi commented Apr 23, 2020

I intend to add some polish before marking this PR as ready to merge but first wanted to make sure we agree on the high-level design.

@knative-prow-robot
Copy link
Contributor

@ian-mi: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ian-mi
Copy link
Contributor Author

ian-mi commented Apr 23, 2020

Closing as the BrokerCell reconciler should make this unnecessary barring possible scaling issues.

@ian-mi ian-mi closed this Apr 23, 2020
@ian-mi ian-mi mentioned this pull request May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation of Targets that knows it's backed by a configmap
6 participants