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

Remove builder interface, linearize pod creation and watching#464

Merged
knative-prow-robot merged 14 commits intoknative:masterfrom
imjasonh:builder
Nov 26, 2018
Merged

Remove builder interface, linearize pod creation and watching#464
knative-prow-robot merged 14 commits intoknative:masterfrom
imjasonh:builder

Conversation

@imjasonh
Copy link
Copy Markdown
Contributor

@imjasonh imjasonh commented Nov 9, 2018

Proposed Changes

  • Remove the builder.Interface which effectively only had a single implementation for on-cluster builds
  • Linearize pod creation, so it can be read and understood more clearly from top-to-bottom
  • Remove Operation, callbacks, mutexes, etc.

With this change, we'll listen for all pod events on the cluster, and when we see one for a pod owned by a Build, we'll update that build with the Pod's status.

Release Note

NONE

Copy link
Copy Markdown

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@imjasonh: 0 warnings.

Details

In response to this:

Proposed Changes

  • Remove the builder.Interface which effectively only had a single implementation for on-cluster builds
  • Linearize pod creation, so it can be read and understood more clearly from top-to-bottom
  • Remove Operation, callbacks, mutexes, etc.

With this change, we'll listen for all pod events on the cluster, and when we see one for a pod owned by a Build, we'll update that build with the Pod's status.

Release Note

NONE

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.

@imjasonh
Copy link
Copy Markdown
Contributor Author

imjasonh commented Nov 9, 2018

/test pull-knative-build-integration-tests

Comment thread pkg/reconciler/build/resources/pod.go Outdated
Namespace: build.Namespace,
// Ensure our Pod gets a unique name.
GenerateName: fmt.Sprintf("%s-", build.Name),
Name: fmt.Sprintf("pod-for-%s", build.Name),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about $(build_name)-pod?
For example if k8s deployment is used, the pod names have deployment name as prefix. It is easier to associate the parent resource with prefix rather than suffix.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not have strong opinion on what follows after build_name. Probably a better question to ask is if build can only have a pod why do we need different name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, done.

FWIW, the reason I dropped GenerateName is because the fake k8s implementation doesn't generate names, and so pods were always created as "". 😠

@imjasonh
Copy link
Copy Markdown
Contributor Author

The failing test is the YAML test for test-with-low-timeout:

I1109 22:02:23.123] test-with-low-timeout     Succeeded   Unknown   2018-11-09T21:56:46Z   <none>     <none>

It looks like the timeout isn't kicking in and the build continues executing ~forever. Oddly this doesn't seem to happen when I run e2e-tests.sh locally. I'll investigate more and unhold this.

/hold

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@knative knative deleted a comment from googlebot Nov 10, 2018
@imjasonh
Copy link
Copy Markdown
Contributor Author

/test pull-knative-build-integration-tests

Comment thread cmd/controller/main.go Outdated
controllers := []controller.Interface{
build.NewController(logger, kubeClient, buildClient, buildInformer, buildTemplateInformer, clusterBuildTemplateInformer, bldr),
controllers := []*controller.Impl{
build.NewController(logger, kubeClient, kubeInformerFactory, buildClient, buildInformer, buildTemplateInformer, clusterBuildTemplateInformer),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The pattern we're using constructs the Pod informer here and passes it in, so that it can be included in the synchronization below.

Comment thread pkg/reconciler/build/build.go Outdated
kubeinformers.Core().V1().Pods().Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: r.addPodEvent,
UpdateFunc: r.updatePodEvent,
DeleteFunc: r.deletePodEvent,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For this to be properly level-based, these should use impl.EnqueueControllerOf (possibly wrapped with controller.PassNew). For a Pod informer, you also certainly want to use a Filter on the OwnerReference Kind being Build.

In level-based reconciliation, all of the logic is oriented in terms of reconciling Build keys (Reconcile()), and these triggers are very thin, they just figure out what Build to queue and enqueue it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that tip. I tried switching to this and had some trouble in tests getting a signal that the enqueued update happened. Do you happen to have a link to how you handle this in Serving?

Also, good idea filtering for build-owned pods. How do I express that filter to podsLister? NewSharedInformerFactoryWithOptions with a TweakListOptions to specify a FieldSelector?

Comment thread cmd/controller/main.go Outdated
"k8s.io/client-go/tools/clientcmd"

// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
"k8s.io/client-go/tools/clientcmd" // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is not at the right place 😅

@imjasonh
Copy link
Copy Markdown
Contributor Author

/hold

I have quite a few unpushed changes, I'm thinking this might be better as more smaller PRs. Unfortunately life stuff is taking up a lot of time lately, I probably can't promise much progress until after the Thanksgiving holiday.

@imjasonh
Copy link
Copy Markdown
Contributor Author

/hold cancel

This change is ready now, passing unit and integration tests. Unfortunately it's pretty big, sorry about that, my intention had been to split it up but it looked like it was all pretty tightly intertwined. The good news is I think this is a lot easier to read and understand (and test!) after this change. It should now be pretty straightforward to forklift this into the TaskRun controller and make it responsible for creating Pods directly.

Copy link
Copy Markdown
Contributor

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

SGTM 🐯
/approve

Copy link
Copy Markdown
Contributor

@shashwathi shashwathi left a comment

Choose a reason for hiding this comment

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

/lgtm

if err != nil {
return err
}
newb.Status = u.Status
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could consider checking if there is any change in status object before updating it.
This could be changed in further PR too.

Comment thread test/e2e/e2e.go
}
}
return nil, errors.New("watch ended before build completion")
return latest, errWatchTimeout
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this classification of errors.

@vdemeester
Copy link
Copy Markdown
Contributor

oh @imjasonh needs a rebase 🙏

Copy link
Copy Markdown
Contributor

@vdemeester vdemeester 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
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ImJasonH, shashwathi, vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [ImJasonH,shashwathi]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-metrics-robot
Copy link
Copy Markdown

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

File Old Coverage New Coverage Delta
pkg/reconciler/build/build.go 76.4% 76.7% 0.3
pkg/reconciler/build/resources/pod.go 84.5% 88.0% 3.6
pkg/reconciler/build/validate_build.go 93.0% 91.4% -1.6

@knative-prow-robot knative-prow-robot merged commit 6343297 into knative:master Nov 26, 2018
@imjasonh imjasonh mentioned this pull request Nov 26, 2018
vdemeester pushed a commit to vdemeester/knative-build that referenced this pull request Apr 3, 2019
…e#464)

* Remove builder interface, linearize pod creation and watching

* Remove pkg/buildtest/wait.go

* Create pods like <build-name>-pod

* Remove pkg/controller

* Improve TestLowTimeout, still needs work

* Move BuildStatusFromPod to resources pkg

* Skip statuses for multiple sources; add tests for BuildStatusFromPod

* Lower timeout, log more

* pass build to isTimeout

* Generate unique names for each pod, otherwise conflict; move tests to pod_test.go

* Sync pod lister before starting controller

* update deps

* Reconcile in response to pod events

* Remove commented import
vdemeester pushed a commit to vdemeester/knative-build that referenced this pull request Apr 3, 2019
…e#464)

* Remove builder interface, linearize pod creation and watching

* Remove pkg/buildtest/wait.go

* Create pods like <build-name>-pod

* Remove pkg/controller

* Improve TestLowTimeout, still needs work

* Move BuildStatusFromPod to resources pkg

* Skip statuses for multiple sources; add tests for BuildStatusFromPod

* Lower timeout, log more

* pass build to isTimeout

* Generate unique names for each pod, otherwise conflict; move tests to pod_test.go

* Sync pod lister before starting controller

* update deps

* Reconcile in response to pod events

* Remove commented import
vdemeester pushed a commit to vdemeester/knative-build that referenced this pull request Apr 3, 2019
…e#464)

* Remove builder interface, linearize pod creation and watching

* Remove pkg/buildtest/wait.go

* Create pods like <build-name>-pod

* Remove pkg/controller

* Improve TestLowTimeout, still needs work

* Move BuildStatusFromPod to resources pkg

* Skip statuses for multiple sources; add tests for BuildStatusFromPod

* Lower timeout, log more

* pass build to isTimeout

* Generate unique names for each pod, otherwise conflict; move tests to pod_test.go

* Sync pod lister before starting controller

* update deps

* Reconcile in response to pod events

* Remove commented import
vdemeester pushed a commit to vdemeester/knative-build that referenced this pull request Apr 3, 2019
…e#464)

* Remove builder interface, linearize pod creation and watching

* Remove pkg/buildtest/wait.go

* Create pods like <build-name>-pod

* Remove pkg/controller

* Improve TestLowTimeout, still needs work

* Move BuildStatusFromPod to resources pkg

* Skip statuses for multiple sources; add tests for BuildStatusFromPod

* Lower timeout, log more

* pass build to isTimeout

* Generate unique names for each pod, otherwise conflict; move tests to pod_test.go

* Sync pod lister before starting controller

* update deps

* Reconcile in response to pod events

* Remove commented import
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.

7 participants