Skip to content

Commit

Permalink
Allow creating v1beta1 resources
Browse files Browse the repository at this point in the history
- Update examples to use v1beta1 by default.
- Add an explicit v1alpha1 example.
- Use v1beta1 Pipeline types for Params and tests.

Fixes #481

Signed-off-by: Dibyo Mukherjee <[email protected]>
  • Loading branch information
dibyom committed Mar 24, 2020
1 parent a9704de commit 2bdfd18
Show file tree
Hide file tree
Showing 33 changed files with 260 additions and 173 deletions.
3 changes: 1 addition & 2 deletions docs/getting-started/ingress-run.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: create-ingress-run
namespace: getting-started
spec:
taskRef:
name: create-ingress
inputs:
params:
- name: CreateCertificate
value: "true"
Expand Down
38 changes: 18 additions & 20 deletions docs/getting-started/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# - source is built into an image by img
# - image output is pushed to ECR
# - cloudevent emitted
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: getting-started-pipeline
Expand Down Expand Up @@ -50,18 +50,17 @@ spec:
- name: event-to-sink
resource: event-to-sink
---
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: deploy-locally
namespace: getting-started
spec:
inputs:
resources:
resources:
inputs:
- name: image-source
type: image
outputs:
resources:
outputs:
- name: event-to-sink
type: cloudEvent
steps:
Expand All @@ -72,26 +71,25 @@ spec:
- "run"
- "tekton-triggers-built-me"
- "--image"
- "${inputs.resources.image-source.url}"
- "${resources.inputs.image-source.url}"
- "--env=PORT=8080"
---
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-docker-image
namespace: getting-started
spec:
inputs:
resources:
params:
- name: pathToContext
description:
The build directory used by img
default: /workspace/source-repo
resources:
inputs:
- name: source-repo
type: git
params:
- name: pathToContext
description:
The build directory used by img
default: /workspace/source-repo
outputs:
resources:
outputs:
- name: builtImage
type: image
steps:
Expand All @@ -102,9 +100,9 @@ spec:
args:
- build
- -t
- "${outputs.resources.builtImage.url}"
- "$(resources.outputs.builtImage.url)"
- --no-cache
- "${inputs.params.pathToContext}"
- "$(params.pathToContext)"
---
apiVersion: tekton.dev/v1alpha1
kind: Condition
Expand All @@ -118,7 +116,7 @@ spec:
check:
image: golang
command: ["go"]
args: ['test', "$(inputs.resources.source-repo.path)/..."]
args: ['test', "$(resources.source-repo.path)/..."]
---
# Finally, we need something to receive our cloudevent announcing success!
# That is this services only purpose
Expand Down
3 changes: 1 addition & 2 deletions docs/getting-started/webhook-run.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: create-webhook-run
namespace: getting-started
spec:
taskRef:
name: create-webhook
inputs:
params:
- name: GitHubOrg
value: "iancoffey"
Expand Down
2 changes: 1 addition & 1 deletion docs/triggertemplates.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- name: contenttype
description: The Content-Type of the event
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: simple-pipeline-run-
Expand Down
44 changes: 22 additions & 22 deletions examples/example-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: say-hello
spec:
inputs:
params:
- name: contenttype
description: The Content-Type of the event
type: string
resources:
params:
- name: contenttype
description: The Content-Type of the event
type: string
resources:
inputs:
- name: git-source
type: git
steps:
- name: say-hi
image: bash
command: ["bash", "-c"]
args:
- echo -e 'Hello Triggers!\nContent-Type is $(inputs.params.contenttype)'
- echo -e 'Hello Triggers!\nContent-Type is $(params.contenttype)'
---
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: say-message
spec:
inputs:
params:
- name: message
description: The message to print
default: This is the default message
type: string
resources:
params:
- name: message
description: The message to print
default: This is the default message
type: string
resources:
inputs:
- name: git-source
type: git
steps:
- name: say-message
image: bash
command: ["bash", "-c"]
args:
- echo '$(inputs.params.message)'
- echo '$(params.message)'
---
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: say-bye
spec:
inputs:
resources:
resources:
inputs:
- name: git-source
type: git
steps:
Expand All @@ -55,7 +55,7 @@ spec:
args:
- echo 'Goodbye Triggers!'
---
apiVersion: tekton.dev/v1alpha1
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: simple-pipeline
Expand Down Expand Up @@ -100,4 +100,4 @@ spec:
resources:
inputs:
- name: git-source
resource: git-source
resource: git-source
2 changes: 1 addition & 1 deletion examples/triggertemplates/triggertemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
- name: contenttype
description: The Content-Type of the event
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: simple-pipeline-run-
Expand Down
47 changes: 47 additions & 0 deletions examples/v1alpha1-task/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## v1alpha1 Task EventListener

Creates an EventListener that creates a v1alpha1 TaskRun.

### Try it out locally:

1. Create the service account:

```shell script
kubectl apply -f examples/role-resources/triggerbinding-roles
kubectl apply -f examples/role-resources/
```

1. Create the v1alpha1 EventListener:

```shell script
kubectl apply -f examples/v1alpha1-task/v1alpha1-task-listener.yaml
```

1. Port forward:

```shell script
kubectl port-forward \
"$(kubectl get pod --selector=eventlistener=v1alpha1-task-listener -oname)" \
8080
```

**Note**: Instead of port forwarding, you can set the
[`serviceType`](https://github.com/tektoncd/triggers/blob/master/docs/eventlisteners.md#serviceType)
to `LoadBalancer` to expose the EventListener with a public IP.

1. Test by sending the sample payload.

```shell script
curl -v \
-H 'Content-Type: application/json' \
--data "{}" \
http://localhost:8080
```

The response status code should be `201 Created`

1. You should see a new TaskRun that got created:

```shell script
kubectl get taskruns | grep v1alpha1-task-run-
```
29 changes: 29 additions & 0 deletions examples/v1alpha1-task/v1alpha1-task-listener.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
apiVersion: tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: v1alpha1-task-template
spec:
resourcetemplates:
- apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
generateName: v1alpha1-task-run-
spec:
taskSpec:
steps:
- name: "hellothere"
image: ubuntu
script: echo "hello there"
---
apiVersion: tekton.dev/v1alpha1
kind: EventListener
metadata:
name: v1alpha1-task-listener
spec:
# from examples/role-resources/servicaccount.yaml
serviceAccountName: tekton-triggers-example-sa
triggers:
- name: v1alpha1-task-trigger
template:
name: v1alpha1-task-template
2 changes: 1 addition & 1 deletion pkg/apis/triggers/v1alpha1/event_listener_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha1
import (
"fmt"

pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/triggers/v1alpha1/event_listener_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"net/http"

pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"k8s.io/apimachinery/pkg/util/validation"
"knative.dev/pkg/apis"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/triggers/v1alpha1/trigger_binding_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 (
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/triggers/v1alpha1/trigger_binding_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha1
import (
"context"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"knative.dev/pkg/apis"
)

Expand All @@ -36,7 +36,7 @@ func (s *TriggerBindingSpec) Validate(ctx context.Context) *apis.FieldError {
return nil
}

func validateParams(params []v1alpha1.Param) *apis.FieldError {
func validateParams(params []v1beta1.Param) *apis.FieldError {
// Ensure there aren't multiple params with the same name.
seen := map[string]struct{}{}
for _, param := range params {
Expand Down
15 changes: 10 additions & 5 deletions pkg/apis/triggers/v1alpha1/trigger_template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ limitations under the License.
package v1alpha1

import (
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand All @@ -33,15 +34,19 @@ var Decoder runtime.Decoder

func init() {
scheme := runtime.NewScheme()
utilruntime.Must(pipelinev1.AddToScheme(scheme))
utilruntime.Must(pipelinev1alpha1.AddToScheme(scheme))
utilruntime.Must(pipelinev1beta1.AddToScheme(scheme))
codec := serializer.NewCodecFactory(scheme)
Decoder = codec.UniversalDecoder(pipelinev1.SchemeGroupVersion)
Decoder = codec.UniversalDecoder(
pipelinev1alpha1.SchemeGroupVersion,
pipelinev1beta1.SchemeGroupVersion,
)
}

// TriggerTemplateSpec holds the desired state of TriggerTemplate
type TriggerTemplateSpec struct {
Params []pipelinev1.ParamSpec `json:"params,omitempty"`
ResourceTemplates []TriggerResourceTemplate `json:"resourcetemplates,omitempty"`
Params []pipelinev1beta1.ParamSpec `json:"params,omitempty"`
ResourceTemplates []TriggerResourceTemplate `json:"resourcetemplates,omitempty"`
}

// TriggerResourceTemplate describes a resource to create
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/triggers/v1alpha1/trigger_template_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"regexp"
"strings"

pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/apis/validate"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
Loading

0 comments on commit 2bdfd18

Please sign in to comment.