-
Notifications
You must be signed in to change notification settings - Fork 24
Enqueue Bundle on ConfigMap/Secret event #397
Conversation
pkg/controller/bundlec/controller.go
Outdated
if configMapRef == nil { | ||
continue | ||
} | ||
indexKeys = append(indexKeys, bySecretNamespaceNameIndexKey(namespace, configMapRef.Name)) |
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.
this should be byConfigMapNamespaceNameIndexKey
, right?
same with the statement below.
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.
Doh, I checked it like 3 times and still got it wrong =) Thanks! Copy-pasting is bad.
} | ||
|
||
func byConfigMapNamespaceNameIndexKey(configMapNamespace, configMapName string) string { | ||
return configMapNamespace + "/" + configMapName |
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.
Any specific reason you use this style over fmt.Sprintf
?
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.
It is not important in this case of course, but I think concatenation is faster - don't need to parse the formatting string. Also this code does not depend on the fmt
package that way (also not important).
I want to have some tests here, so I'm not merging it straight away. |
@@ -110,6 +148,37 @@ func (c *Controller) Run(ctx context.Context) { | |||
<-ctx.Done() | |||
} | |||
|
|||
// lookupBundleByDeploymentByIndex returns a function that can be used to perform lookups of Bundles that contain | |||
// Deployment objects that reference ConfigMap/Secret objects. | |||
func (c *Controller) lookupBundleByDeploymentByIndex(byIndex byIndexFunc, indexName string, indexKey indexKeyFunc) func(runtime.Object) ([]runtime.Object, error) { |
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.
This could probably be a nice util function in ctrl because we do something very similar in basically everywhere we have a LookupHandler
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.
I have checked the places where LookupHandler
is used, but all of them are not like this one. They are simpler. We have duplication there and we should DRY it, but the logic is not the same as here. Or I'm missing something?
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.
@ash2k don't we need a similar fix for Secret -> ServiceInstance -> Bundle
propagation?
c.crdContext, c.crdContextCancel = context.WithCancel(context.Background()) | ||
crdInf.AddEventHandler(&crdEventHandler{ | ||
controller: c, | ||
watchers: make(map[string]watchState), | ||
}) | ||
|
||
deploymentInf := resourceInfs[apps_v1.SchemeGroupVersion.WithKind("Deployment")] |
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.
nit: I know that k/k monorepo doesn't have constants for resource kinds, but we could define our own constants and use them?
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.
Yes. A separate PR that updates all places with constants would be nice.
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.
If there is a Deployment in a Bundle that uses ConfigMap/Secret and this object is updated, Bundle is enqueued for processing.
51f9a66
974f4e6
to
51f9a66
Compare
51f9a66
to
8c775cb
Compare
I've added a test, ready for re-review. No code modifications were required. I could write a unit test but that would require a massive amount of setup code. I tried to re-use the I'm going to do the same for |
8c775cb
to
9d2ba54
Compare
@@ -226,7 +227,10 @@ func (c *BundleControllerConstructor) New(config *ctrl.Config, cctx *ctrl.Contex | |||
Broadcaster: broadcaster, | |||
Recorder: recorder, | |||
} | |||
cntrlr.Prepare(crdInf, resourceInfs) | |||
err = cntrlr.Prepare(crdInf, resourceInfs) |
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.
🤔 this should have been a warning before...
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.
It wasn't returning an error before this PR.
Resources: []smith_v1.Resource{ | ||
{ | ||
Name: deploymentResourceName, | ||
Spec: smith_v1.ResourceSpec{ |
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're going to have to make builders for this stuff or put it in files. I'm realizing there's.... a lot of boilerplate.
If there is a Deployment in a Bundle that uses ConfigMap/Secret and this object is updated, Bundle is enqueued for processing.
Fixes #394.
Not sure how to test this. Will think more.