Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Simple Pipeline Controller with tests #75

Merged
merged 5 commits into from Oct 3, 2018

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented Sep 28, 2018

Addresses 1 pat of #61

This PR, implements simple pipeline controller which records events when a pipelinerun points to right pipeline reference.
This implementation, for now does nothing and logs errors if there the pipeline run refers to invalid ref.

@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tejal29

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

@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 28, 2018
@tejal29
Copy link
Contributor Author

tejal29 commented Sep 28, 2018

Just noticed, Bulk of changes are in vendor directory.
I think previous PR did not clean up all the vendor directories.
I will create a PR to dep prune on master and then submit that first.

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Niiiiiice! Very cool!

I think you've done a lot of work here that is going to be super valuable for everyone implementing controllers going forward! My biggest piece of feedback is that if I was to have to do the same thing (e.g. for a different controller/type), looking at the tests that you've added for guidance, I'd be a bit confused about what I needed to do, so it would be great to have some kind of docs or guidance for future unit test authors.

cmd/controller/main.go Show resolved Hide resolved
cmd/controller/main.go Show resolved Hide resolved
cmd/controller/main.go Outdated Show resolved Hide resolved
cmd/controller/main.go Outdated Show resolved Hide resolved

const (
//PipelineRunAgent is the logging agent for pipeline run controller
PipelineRunAgent = "pipelinerun-controller"
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is an agent in this context? is that a kubernetes term?

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 is the logging agent. The Log line will dump logs with this agent name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm just wondering what "agent" means specifically, is it a kubernetes thing or golang thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. this more of logging thing. Its used when logging.
I can rename this to loggerName if that helps.

pkg/controller/pipelinerun/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller_test.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
@bobcatfish
Copy link
Collaborator

image

Note: this syntax will actually CLOSE #61, which I think is not quite what we want b/c I think we still need a few more follow-up PRs to finish #61, so maybe you just want something in the commit and PR description like part of #61 or first step in #61 instead?

cmd/controller/main.go Show resolved Hide resolved
var (
runsListerFunc = runsLister
pipelinesListerFunc = pipelinesLister
getRecordFunc = getRecorder
Copy link
Member

Choose a reason for hiding this comment

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

This could also done with one NewController that takes functional arguments (à-la-builder in a way). That would allow to setup sane defaults, easily overridable (and future-proof).

type ControllerConfig {
    lister func // …
    // …
}

func Lister(f func …) func(*ControllerConfig) {
    return func(c *ControllerConfig) {
        c.lister = f
    }
}

// Any non-required function can have a sane default and thus be written as a "function operator"
func NewController(
	k kubernetes.Interface,
	c clientset.Interface,
	l *zap.SugaredLogger,
        ops ...func(*ControllerConfig)
) controller.Interface { 
    c := &ControllerConfig{
        // … with sane defaults
    }

    for _, op := range ops {
        op(c)
    }
// […]

pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
pkg/controller/pipelinerun/controller.go Outdated Show resolved Hide resolved
This pipeline controller records events when a pipelinerun points to right pipeline reference.
This implementation, for now only records events if the pipelinerun object points to valid pipeline.
Add unit tests for new reconcilers.
Unit tests, uses fake kuberneters go client and REST client.
They run Reconciler and obsevers errors logged.
The tests, then verifies the logged errors.
Added documentation on adding tests for controller.
@tejal29
Copy link
Contributor Author

tejal29 commented Oct 3, 2018

@bobcatfish , @pivotal-nader-ziada and @vdemeester This is ready for review with reconciler and documentations on how to test controller.

Copy link
Member

@nader-ziada nader-ziada left a comment

Choose a reason for hiding this comment

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

A good reconciler start, I think it would be good to merge this in and then add the functionality of creating pipelineRun and taskRun along with more tests

@tejal29
small changes we can hopefully change before merging this in:

  • Fix the Gopkg.lock diff so it doesn't cause conflicts later
  • Add the newController in cmd/controller/main.go

t.Errorf("expected list to be called, found %s", action.GetVerb())
}
```

Copy link
Member

Choose a reason for hiding this comment

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

neat!

cmd/controller/main.go Show resolved Hide resolved
@nader-ziada
Copy link
Member

Thanks @tejal29

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 3, 2018
@knative-prow-robot knative-prow-robot merged commit c74ad1f into tektoncd:master Oct 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants