Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Enqueue Bundle on ConfigMap/Secret event #397

Merged
merged 3 commits into from
Jan 30, 2019

Conversation

ash2k
Copy link
Contributor

@ash2k ash2k commented Jan 5, 2019

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.

@ash2k ash2k self-assigned this Jan 5, 2019
@ash2k ash2k requested review from Burr and a team January 5, 2019 11:00
if configMapRef == nil {
continue
}
indexKeys = append(indexKeys, bySecretNamespaceNameIndexKey(namespace, configMapRef.Name))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Burr
Burr previously approved these changes Jan 6, 2019
benbarclay
benbarclay previously approved these changes Jan 6, 2019
}

func byConfigMapNamespaceNameIndexKey(configMapNamespace, configMapName string) string {
return configMapNamespace + "/" + configMapName
Copy link
Contributor

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?

Copy link
Contributor Author

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).

@ash2k
Copy link
Contributor Author

ash2k commented Jan 6, 2019

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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?

ychen-atlassian
ychen-atlassian previously approved these changes Jan 8, 2019
nilebox
nilebox previously approved these changes Jan 8, 2019
Copy link
Contributor

@nilebox nilebox left a 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")]
Copy link
Contributor

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?

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. A separate PR that updates all places with constants would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ash2k
Copy link
Contributor Author

ash2k commented Jan 8, 2019

@ash2k don't we need a similar fix for Secret -> ServiceInstance -> Bundle propagation?

@nilebox yes, good catch. We need the same fix there. #402

If there is a Deployment in a Bundle that uses ConfigMap/Secret and
this object is updated, Bundle is enqueued for processing.
@ash2k ash2k force-pushed the enqueue-bundle-on-secret-configmap-change branch from 974f4e6 to 51f9a66 Compare January 27, 2019 11:43
@ash2k ash2k changed the title Enqueue Bundle on ConfigMap/Secret event WIP Enqueue Bundle on ConfigMap/Secret event Jan 27, 2019
@ash2k ash2k force-pushed the enqueue-bundle-on-secret-configmap-change branch from 51f9a66 to 8c775cb Compare January 28, 2019 09:58
@ash2k ash2k changed the title WIP Enqueue Bundle on ConfigMap/Secret event Enqueue Bundle on ConfigMap/Secret event Jan 28, 2019
@ash2k
Copy link
Contributor Author

ash2k commented Jan 28, 2019

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 testCase type that we have, but substituting workqueue with a mock one didn't work because it's copied to the lookup handler before I can replace it (without re-doing all the plumbing).

I'm going to do the same for Secret->ServiceInstance once this is merged.

@ash2k ash2k force-pushed the enqueue-bundle-on-secret-configmap-change branch from 8c775cb to 9d2ba54 Compare January 29, 2019 03:39
@@ -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)

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...

Copy link
Contributor Author

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{

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.

@ash2k ash2k merged commit f7b5065 into master Jan 30, 2019
@ash2k ash2k deleted the enqueue-bundle-on-secret-configmap-change branch January 30, 2019 05:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants