Skip to content

Commit

Permalink
Add inital taskrun controller implementation
Browse files Browse the repository at this point in the history
This pr implements a simple TaskRun controller that creates a knative/build Build and updates the TaskRun status to reflect the Build status. We delegate to the knative/build controller to do the work of actually fulfillign the Build itself - meaning we have a hard dependency on knative/build.

The integration test doesn't actually assert on the logs output by the
bulid step because the pods disappear immediately after completion, so
we need a better solution here (e.g. writing to a PVC in the test) - in
the long run we need to implement better log support (#107).

Remaining work for #59 is to improve unit test coverage, and add some
docs on running + debugging.
  • Loading branch information
aaron-prindle authored and knative-prow-robot committed Oct 8, 2018
1 parent d97057a commit c6fe81c
Show file tree
Hide file tree
Showing 18 changed files with 934 additions and 290 deletions.
194 changes: 25 additions & 169 deletions Gopkg.lock

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (

clientset "github.com/knative/build-pipeline/pkg/client/clientset/versioned"
pipelineinformers "github.com/knative/build-pipeline/pkg/client/informers/externalversions"
knativebuildclientset "github.com/knative/build/pkg/client/clientset/versioned"
knativeinformers "github.com/knative/build/pkg/client/informers/externalversions"
buildclientset "github.com/knative/build/pkg/client/clientset/versioned"
buildinformers "github.com/knative/build/pkg/client/informers/externalversions"
"github.com/knative/pkg/configmap"
"github.com/knative/pkg/signals"
)
Expand Down Expand Up @@ -90,29 +90,28 @@ func main() {
logger.Fatalf("Error building pipeline clientset: %v", err)
}

knativebuildClient, err := knativebuildclientset.NewForConfig(cfg)
buildClient, err := buildclientset.NewForConfig(cfg)
if err != nil {
logger.Fatalf("Error building Build clientset: %v", err)
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30)
pipelineInformerFactory := pipelineinformers.NewSharedInformerFactory(pipelineClient, time.Second*30)
knativebuildInformerFactory := knativeinformers.NewSharedInformerFactory(knativebuildClient, time.Second*30)
buildInformerFactory := buildinformers.NewSharedInformerFactory(buildClient, time.Second*30)

configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace)

opt := reconciler.Options{
KubeClientSet: kubeClient,
BuildClientSet: buildClient,
SharedClientSet: sharedClient,
PipelineClientSet: pipelineClient,
Logger: logger,
}

taskInformer := pipelineInformerFactory.Pipeline().V1alpha1().Tasks()
taskRunInformer := pipelineInformerFactory.Pipeline().V1alpha1().TaskRuns()
buildInformer := knativebuildInformerFactory.Build().V1alpha1().Builds()
buildTemplateInformer := knativebuildInformerFactory.Build().V1alpha1().BuildTemplates()
clusterBuildTemplateInformer := knativebuildInformerFactory.Build().V1alpha1().ClusterBuildTemplates()
buildInformer := buildInformerFactory.Build().V1alpha1().Builds()

pipelineInformer := pipelineInformerFactory.Pipeline().V1alpha1().Pipelines()
pipelineRunInformer := pipelineInformerFactory.Pipeline().V1alpha1().PipelineRuns()
Expand All @@ -123,8 +122,6 @@ func main() {
taskRunInformer,
taskInformer,
buildInformer,
buildTemplateInformer,
clusterBuildTemplateInformer,
),
pipelinerun.NewController(opt,
pipelineRunInformer,
Expand All @@ -139,7 +136,7 @@ func main() {

kubeInformerFactory.Start(stopCh)
pipelineInformerFactory.Start(stopCh)
knativebuildInformerFactory.Start(stopCh)
buildInformerFactory.Start(stopCh)
if err := configMapWatcher.Start(stopCh); err != nil {
logger.Fatalf("failed to start configuration manager: %v", err)
}
Expand All @@ -150,8 +147,6 @@ func main() {
taskInformer.Informer().HasSynced,
taskRunInformer.Informer().HasSynced,
buildInformer.Informer().HasSynced,
buildTemplateInformer.Informer().HasSynced,
clusterBuildTemplateInformer.Informer().HasSynced,
} {
if ok := cache.WaitForCacheSync(stopCh, synced); !ok {
logger.Fatalf("failed to wait for cache at index %v to sync", i)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1alpha1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type TaskSpec struct {
// +optional
Inputs *Inputs `json:"inputs,omitempty"`
// +optional
Outputs *Outputs `json:"outputs,omitempty"`
BuildSpec buildv1alpha1.BuildSpec `json:"buildSpec"`
Outputs *Outputs `json:"outputs,omitempty"`
BuildSpec *buildv1alpha1.BuildSpec `json:"buildSpec"`
}

// TaskStatus defines the observed state of Task
Expand Down
38 changes: 4 additions & 34 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -68,10 +68,10 @@ type TaskTriggerRef struct {
}

// TaskRunStatus defines the observed state of TaskRun
// TODO(aaron-prindle) change back to being used in Task
type TaskRunStatus struct {
Steps []StepRun `json:"steps"`
Conditions []TaskRunCondition `json:"conditions"`
Steps []StepRun `json:"steps"`
// Conditions describes the set of conditions of this build.
Conditions duckv1alpha1.Conditions `json:"conditions,omitempty"`
}

// StepRun reports the results of running a step in the Task. Each
Expand All @@ -83,36 +83,6 @@ type StepRun struct {
ExitCode int `json:"exitCode"`
}

// TaskRunConditionType indicates the status of the execution of the TaskRun.
type TaskRunConditionType string

const (
// TaskRunConditionTypeStarted indicates whether or not the TaskRun
// has started actually executing.
TaskRunConditionTypeStarted TaskRunConditionType = "Started"

//TaskRunConditionTypeCompleted indicates whether or not the TaskRun
// has finished executing.
TaskRunConditionTypeCompleted TaskRunConditionType = "Completed"

// TaskRunConditionTypeSucceeded indicates whether or not the TaskRun
// was successful.
TaskRunConditionTypeSucceeded TaskRunConditionType = "Successful"
)

// TaskRunCondition holds a Condition that the TaskRun has entered into while being executed.
type TaskRunCondition struct {
Type TaskRunConditionType `json:"type"`

Status corev1.ConditionStatus `json:"status"`

LastTransitionTime metav1.Time `json:"lastTransitionTime"`
// +optional
Reason string `json:"reason,omitempty"`
// +optional
Message string `json:"message,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
31 changes: 12 additions & 19 deletions pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
clientset "github.com/knative/build-pipeline/pkg/client/clientset/versioned"
pipelineScheme "github.com/knative/build-pipeline/pkg/client/clientset/versioned/scheme"

buildclientset "github.com/knative/build/pkg/client/clientset/versioned"
cachingclientset "github.com/knative/caching/pkg/client/clientset/versioned"
sharedclientset "github.com/knative/pkg/client/clientset/versioned"
"github.com/knative/pkg/configmap"
Expand All @@ -40,6 +41,7 @@ type Options struct {
KubeClientSet kubernetes.Interface
SharedClientSet sharedclientset.Interface
PipelineClientSet clientset.Interface
BuildClientSet buildclientset.Interface
CachingClientSet cachingclientset.Interface

ConfigMapWatcher configmap.Watcher
Expand All @@ -57,6 +59,9 @@ type Base struct {
// PipelineClientSet allows us to configure pipeline objects
PipelineClientSet clientset.Interface

// PipelineClientSet allows us to configure pipeline objects
BuildClientSet buildclientset.Interface

// CachingClientSet allows us to instantiate Image objects
CachingClientSet cachingclientset.Interface

Expand Down Expand Up @@ -93,6 +98,7 @@ func NewBase(opt Options, controllerAgentName string) *Base {
KubeClientSet: opt.KubeClientSet,
SharedClientSet: opt.SharedClientSet,
PipelineClientSet: opt.PipelineClientSet,
BuildClientSet: opt.BuildClientSet,
CachingClientSet: opt.CachingClientSet,
ConfigMapWatcher: opt.ConfigMapWatcher,
Recorder: recorder,
Expand Down
Loading

0 comments on commit c6fe81c

Please sign in to comment.