Skip to content

Commit

Permalink
Implement working kaniko build Task tektoncd#62
Browse files Browse the repository at this point in the history
 - Change the CRD of PipelineResource to make the kind with the same
 name, the word resource makes the cluster roles rbac not work
 - add resource Lister in taskrun controller
 - move tracking of build after its created,
 - update build obejct with input git resources
 - add PipelineResource to webhook validation
 - add integration test
  • Loading branch information
nader-ziada committed Oct 10, 2018
1 parent 4c7cf1f commit 19e4a35
Show file tree
Hide file tree
Showing 18 changed files with 441 additions and 81 deletions.
3 changes: 3 additions & 0 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func main() {

taskInformer := pipelineInformerFactory.Pipeline().V1alpha1().Tasks()
taskRunInformer := pipelineInformerFactory.Pipeline().V1alpha1().TaskRuns()
resourceInformer := pipelineInformerFactory.Pipeline().V1alpha1().PipelineResources()
buildInformer := buildInformerFactory.Build().V1alpha1().Builds()

pipelineInformer := pipelineInformerFactory.Pipeline().V1alpha1().Pipelines()
Expand All @@ -122,6 +123,7 @@ func main() {
taskRunInformer,
taskInformer,
buildInformer,
resourceInformer,
),
pipelinerun.NewController(opt,
pipelineRunInformer,
Expand All @@ -147,6 +149,7 @@ func main() {
taskInformer.Informer().HasSynced,
taskRunInformer.Informer().HasSynced,
buildInformer.Informer().HasSynced,
resourceInformer.Informer().HasSynced,
} {
if ok := cache.WaitForCacheSync(stopCh, synced); !ok {
logger.Fatalf("failed to wait for cache at index %v to sync", i)
Expand Down
5 changes: 3 additions & 2 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ func main() {
Client: kubeClient,
Options: options,
Handlers: map[schema.GroupVersionKind]webhook.GenericCRD{
v1alpha1.SchemeGroupVersion.WithKind("Pipeline"): &v1alpha1.Pipeline{},
v1alpha1.SchemeGroupVersion.WithKind("Task"): &v1alpha1.Task{},
v1alpha1.SchemeGroupVersion.WithKind("Pipeline"): &v1alpha1.Pipeline{},
v1alpha1.SchemeGroupVersion.WithKind("Task"): &v1alpha1.Task{},
v1alpha1.SchemeGroupVersion.WithKind("PipelineResource"): &v1alpha1.PipelineResource{},
},
Logger: logger,
}
Expand Down
4 changes: 2 additions & 2 deletions config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ rules:
resources: ["customresourcedefinitions"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["pipeline.knative.dev"]
resources: ["tasks", "taskruns", "pipelines", "pipelineruns", "pipelineparams", "resources"]
resources: ["tasks", "taskruns", "pipelines", "pipelineruns", "pipelineparams", "pipelineresources"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
- apiGroups: ["build.knative.dev"]
resources: ["builds", "buildtemplates", "clusterbuildtemplates"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
6 changes: 3 additions & 3 deletions config/300-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
name: resources.pipeline.knative.dev
name: pipelineresources.pipeline.knative.dev
spec:
group: pipeline.knative.dev
names:
kind: Resource
plural: resources
kind: PipelineResource
plural: pipelineresources
scope: Namespaced
version: v1alpha1
status:
Expand Down
2 changes: 1 addition & 1 deletion docs/pipeline-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Use the following example to understand the syntax and strucutre of a Git Resour

```
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: wizzbang-git
namespace: default
Expand Down
8 changes: 4 additions & 4 deletions examples/pipelines/guestbook-resources.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: guestbook-resources-git
namespace: default
Expand All @@ -14,7 +14,7 @@ spec:
value: githubServiceAccount
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: guestbook-resources-redis-docker
namespace: default
Expand All @@ -29,7 +29,7 @@ spec:
value: HEAD
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: guestbookstagingimage
namespace: default
Expand All @@ -40,7 +40,7 @@ spec:
value: gcr.io/demo-staging
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: redisstagingimage
namespace: default
Expand Down
6 changes: 3 additions & 3 deletions examples/pipelines/kritis-resources.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: kritis-resources-git
namespace: default
Expand All @@ -12,7 +12,7 @@ spec:
value: master
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: kritis-resources-test-git
namespace: default
Expand All @@ -25,7 +25,7 @@ spec:
value: https://github.com/grafeas/kritis-test
---
apiVersion: pipeline.knative.dev/v1alpha1
kind: Resource
kind: PipelineResource
metadata:
name: kritis-resources-image
namespace: default
Expand Down
37 changes: 37 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelineresource_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2018 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/knative/pkg/apis"
"k8s.io/apimachinery/pkg/api/equality"
)

func (r *PipelineResource) Validate() *apis.FieldError {
if err := validateObjectMetadata(r.GetObjectMeta()); err != nil {
return err.ViaField("metadata")
}
return nil
}

func (rs *PipelineResourceSpec) Validate() *apis.FieldError {
if equality.Semantic.DeepEqual(rs, &PipelineResourceSpec{}) {
return apis.ErrMissingField(apis.CurrentField)
}

return nil
}
25 changes: 25 additions & 0 deletions pkg/apis/pipeline/v1alpha1/resource_defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2018 The Knative Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

func (t *PipelineResource) SetDefaults() {
t.Spec.SetDefaults()
}

func (ts *PipelineResourceSpec) SetDefaults() {
return
}
21 changes: 16 additions & 5 deletions pkg/apis/pipeline/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package v1alpha1

import (
"github.com/knative/pkg/apis"
"github.com/knative/pkg/webhook"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -47,17 +49,26 @@ type PipelineResourceInterface interface {
GetServiceAccountName() string
}

// PipelineResourceSpec defines an individual resources used in the pipeline.
type PipelineResourceSpec struct {
Type PipelineResourceType `json:"type"`
Params []Param `json:"params"`
// +optional
Generation int64 `json:"generation,omitempty"`
}

// PipelineResourceStatus should implment status for PipelineResource
type PipelineResourceStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

// PipelineResourceSpec defines an individual resources used in the pipeline.
type PipelineResourceSpec struct {
Type PipelineResourceType `json:"type"`
Params []Param `json:"params"`
}
// Check that PipelineResource may be validated and defaulted.
var _ apis.Validatable = (*PipelineResource)(nil)
var _ apis.Defaultable = (*PipelineResource)(nil)

// Assert that PipelineResource implements the GenericCRD interface.
var _ webhook.GenericCRD = (*PipelineResource)(nil)

// TaskResource defines an input or output Resource declared as a requirement
// by a Task. The Name field will be used to refer to these Resources within
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/v1alpha1/taskrun/resources/input_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ func AddInputResource(
logger *zap.SugaredLogger,
) (*buildv1alpha1.Build, error) {

var gitResource *v1alpha1.GitResource
if task.Spec.Inputs == nil {
return build, nil
}

var gitResource *v1alpha1.GitResource
for _, input := range task.Spec.Inputs.Resources {
resource, err := pipelineResourceLister.PipelineResources(task.Namespace).Get(input.Name)
if err != nil {
Expand Down
Loading

0 comments on commit 19e4a35

Please sign in to comment.