Skip to content

Commit

Permalink
Add support for v1 pipeline types and customruns
Browse files Browse the repository at this point in the history
Allow triggers to create v1 pipeline types
Also allow triggers to create v1beta1 customruns
Finally, move the allowlisted types to a single file (fixes tektoncd#494)

Signed-off-by: Dibyo Mukherjee <dibyo@google.com>
  • Loading branch information
dibyom authored and khrm committed Feb 23, 2023
1 parent 80c4998 commit 1f130ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 15 additions & 0 deletions pkg/apis/config/allowed_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
customrunsv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
pipelineresourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
Expand All @@ -17,10 +18,12 @@ func init() {
utilruntime.Must(customrunsv1alpha1.AddToScheme(scheme))
utilruntime.Must(pipelineresourcev1alpha1.AddToScheme(scheme))
utilruntime.Must(pipelinev1beta1.AddToScheme(scheme))
utilruntime.Must(pipelinev1.AddToScheme(scheme))
codec := serializer.NewCodecFactory(scheme)
Decoder = codec.UniversalDecoder(
pipelineresourcev1alpha1.SchemeGroupVersion, // customrunsv1alpha1 share the same SchemeGroupVersion
pipelinev1beta1.SchemeGroupVersion,
pipelinev1.SchemeGroupVersion,
)
}

Expand All @@ -30,3 +33,15 @@ func EnsureAllowedType(rt runtime.RawExtension) error {
_, err := runtime.Decode(Decoder, rt.Raw)
return err
}

var (
AllowedPipelineTypes = map[string][]string{
"v1alpha1": {"pipelineresources", "pipelineruns", "taskruns", "pipelines", "clustertasks", "tasks", "conditions", "runs"},
"v1beta1": {"pipelineruns", "taskruns", "pipelines", "clustertasks", "tasks", "customruns"},
"v1": {"pipelineruns", "taskruns", "pipelines", "tasks"},
}
AllowedTriggersTypes = map[string][]string{
"v1alpha1": {"clusterinterceptors", "interceptors"},
"v1beta1": {"clustertriggerbindings", "eventlisteners", "triggerbindings", "triggers", "triggertemplates"},
}
)
16 changes: 3 additions & 13 deletions pkg/client/dynamic/clientset/tekton/tekton.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,17 @@ package tekton

import (
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/triggers/pkg/apis/config"
"github.com/tektoncd/triggers/pkg/apis/triggers"
"github.com/tektoncd/triggers/pkg/client/dynamic/clientset"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
)

var (
allowedPipelineTypes = map[string][]string{
"v1alpha1": {"pipelineresources", "pipelineruns", "taskruns", "pipelines", "clustertasks", "tasks", "conditions", "runs"},
"v1beta1": {"pipelineruns", "taskruns", "pipelines", "clustertasks", "tasks"},
}
allowedTriggersTypes = map[string][]string{
"v1alpha1": {"clusterinterceptors", "interceptors"},
"v1beta1": {"clustertriggerbindings", "eventlisteners", "triggerbindings", "triggers", "triggertemplates"},
}
)

// WithClient adds Tekton related clients to the Dynamic client.
func WithClient(client dynamic.Interface) clientset.Option {
return func(cs *clientset.Clientset) {
for version, resources := range allowedPipelineTypes {
for version, resources := range config.AllowedPipelineTypes {
for _, resource := range resources {
r := schema.GroupVersionResource{
Group: pipeline.GroupName,
Expand All @@ -48,7 +38,7 @@ func WithClient(client dynamic.Interface) clientset.Option {
cs.Add(r, client)
}
}
for version, resources := range allowedTriggersTypes {
for version, resources := range config.AllowedTriggersTypes {
for _, resource := range resources {
r := schema.GroupVersionResource{
Group: triggers.GroupName,
Expand Down

0 comments on commit 1f130ed

Please sign in to comment.