Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Have the ClusterBuildTemplate controller instantiate Image resources. #354

Merged
merged 1 commit into from
Sep 17, 2018

Conversation

mattmoor
Copy link
Member

Unlike the BuildTemplate controller, which colocates the Image references, this places the Image resources (which are namespaced) in the knative-build namespace.

WIP until #353 lands.

@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mattmoor

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

}

// Delete any Image caches relevant to older versions of this resource.
propPolicy := metav1.DeletePropagationForeground
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that cached images are deleted upon template update?

if missing := allCached(ics, eics); len(missing) > 0 {
grp, _ := errgroup.WithContext(ctx)

for _, m := range missing {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test that new images are cached upon template update?

return nil
}

func (c *Reconciler) reconcileImageCaches(ctx context.Context, cbt *v1alpha1.ClusterBuildTemplate) error {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be moved to a common location shared by both types of template reconcilers?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've made the parts that are common usable from the buildtemplate reconciler.

caching "github.com/knative/caching/pkg/apis/caching/v1alpha1"
)

func TestMakeImageCache(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Duplicating this test also feels Wrong, if the code was in a single common location then you'd only need to have one test for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

This checks that we properly create things in the system namespace. I can reduce the testing, but the vast majority of the logic is shared :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think what I'm asking for is a test that does all of these cases, for either BuildTemplate or ClusterBuildTemplate, and checks that the resources are created either in the template's namespace or in the case of ClusterBuildTemplate, the system namespace. Sort of like a two-level nested table-driven test, does that make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, let me spend some time on this. Will ping this when RFAL.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok this should be RFAL.

@mattmoor mattmoor changed the title [WIP] Have the ClusterBuildTemplate controller instantiate Image resources. Have the ClusterBuildTemplate controller instantiate Image resources. Sep 14, 2018
@@ -193,3 +182,18 @@ func allCached(desired []caching.Image, observed []*caching.Image) (missing []ca
}
return missing
}

func CreateMissingImageCaches(ctx context.Context, client cachingclientset.Interface, missing []caching.Image) error {
Copy link
Member

Choose a reason for hiding this comment

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

Could this just transparently calculate missingImageCaches and create them? Users shouldn't need to call both methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this so that CreateMissingImageCaches calls missingImageCaches.

}

// Make sure we have all of the desired caching resources.
if missing := buildtemplate.MissingImageCaches(ics, eics); len(missing) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Taking this even further, buildtemplate.ReconcileImageCaches could:

  1. Calculate missing images
  2. Cache missing images
  3. Uncache old images

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I like the split we reach above since the creates can be done in a generic way without the namespace coming into play. There's already a large number of arguments, and I generally prefer largely single-purpose functions.

caching "github.com/knative/caching/pkg/apis/caching/v1alpha1"
)

func TestMakeImageCache(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think what I'm asking for is a test that does all of these cases, for either BuildTemplate or ClusterBuildTemplate, and checks that the resources are created either in the template's namespace or in the case of ClusterBuildTemplate, the system namespace. Sort of like a two-level nested table-driven test, does that make sense?

Unlike the BuildTemplate controller, which colocates the Image references,
this places the Image resources (which are namespaced) in the knative-build
namespace.
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-build-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/reconciler/clusterbuildtemplate/resources/imagecache.go Do not exist 100.0%

Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot merged commit 001e690 into knative:master Sep 17, 2018
@mattmoor mattmoor deleted the cbt-images branch September 17, 2018 19:14
vdemeester pushed a commit to vdemeester/knative-build that referenced this pull request Apr 3, 2019
…knative#354)

Unlike the BuildTemplate controller, which colocates the Image references,
this places the Image resources (which are namespaced) in the knative-build
namespace.
vdemeester pushed a commit to vdemeester/knative-build that referenced this pull request Apr 3, 2019
…knative#354)

Unlike the BuildTemplate controller, which colocates the Image references,
this places the Image resources (which are namespaced) in the knative-build
namespace.
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.

4 participants