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

Add String only Params for Triggers #532

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/eventlistenersink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ func main() {
DiscoveryClient: sinkClients.DiscoveryClient,
DynamicClient: dynamicCS,
TriggersClient: sinkClients.TriggersClient,
PipelineClient: sinkClients.PipelineClient,
ResourceClient: sinkClients.ResourceClient,
HTTPClient: http.DefaultClient,
EventListenerName: sinkArgs.ElName,
EventListenerNamespace: sinkArgs.ElNamespace,
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/triggers/v1alpha1/event_listener_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package v1alpha1
import (
"fmt"

pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"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 Expand Up @@ -95,7 +96,7 @@ type WebhookInterceptor struct {
// Header is a group of key-value pairs that can be appended to the
// interceptor request headers. This allows the interceptor to make
// decisions specific to an EventListenerTrigger.
Header []pipelinev1.Param `json:"header,omitempty"`
Header []v1beta1.Param `json:"header,omitempty"`
}

// GitHubInterceptor provides a webhook to intercept and pre-process events
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/triggers/v1alpha1/param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v1alpha1

// ParamSpec defines an arbitrary named input whose value can be supplied by a
// `Param`.
type ParamSpec struct {
// Name declares the name by which a parameter is referenced.
Name string `json:"name"`
// Description is a user-facing description of the parameter that may be
// used to populate a UI.
// +optional
Description string `json:"description,omitempty"`
// Default is the value a parameter takes if no input value via a Param is supplied.
// +optional
Default *string `json:"default,omitempty"`
ncskier marked this conversation as resolved.
Show resolved Hide resolved
}

// Param defines a string value to be used for a ParamSpec with the same name.
type Param struct {
Name string `json:"name"`
Value string `json:"value"`
}
3 changes: 1 addition & 2 deletions pkg/apis/triggers/v1alpha1/trigger_binding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

import (
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/apis"
)
Expand All @@ -41,7 +40,7 @@ func (tb *TriggerBinding) Copy() TriggerBindingInterface {
// TriggerBindingSpec defines the desired state of the TriggerBinding.
type TriggerBindingSpec struct {
// Params defines the parameter mapping from the given input event.
Params []pipelinev1.Param `json:"params,omitempty"`
Params []Param `json:"params,omitempty"`
}

// TriggerBindingStatus defines the observed state of TriggerBinding.
Expand Down
3 changes: 1 addition & 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,6 @@ package v1alpha1
import (
"context"

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

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

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

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

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

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 Expand Up @@ -86,7 +85,7 @@ func validateResourceTemplates(templates []TriggerResourceTemplate) *apis.FieldE
}

// Verify every param in the ResourceTemplates is declared with a ParamSpec
func verifyParamDeclarations(params []pipelinev1.ParamSpec, templates []TriggerResourceTemplate) *apis.FieldError {
func verifyParamDeclarations(params []ParamSpec, templates []TriggerResourceTemplate) *apis.FieldError {
declaredParamNames := map[string]struct{}{}
for _, param := range params {
declaredParamNames[param.Name] = struct{}{}
Expand Down
45 changes: 40 additions & 5 deletions pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"flag"
"log"

"github.com/tektoncd/pipeline/pkg/system"
"github.com/tektoncd/triggers/pkg/system"
dibyom marked this conversation as resolved.
Show resolved Hide resolved
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"
"knative.dev/pkg/configmap"
Expand Down
12 changes: 0 additions & 12 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package reconciler
import (
"time"

pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned"
triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned"
triggersScheme "github.com/tektoncd/triggers/pkg/client/clientset/versioned/scheme"
"go.uber.org/zap"
Expand All @@ -39,8 +37,6 @@ import (
// creating our controllers.
type Options struct {
KubeClientSet kubernetes.Interface
PipelineClientSet pipelineclientset.Interface
ResourceClientSet resourceclientset.Interface
TriggersClientSet triggersclientset.Interface
CachingClientSet cachingclientset.Interface

Expand All @@ -64,12 +60,6 @@ type Base struct {
// KubeClientSet allows us to talk to the k8s for core APIs
KubeClientSet kubernetes.Interface

// PipelineClientSet allows us to configure pipeline objects
PipelineClientSet pipelineclientset.Interface

// ResourceClientSet allows us to configure pipeline resource objects
ResourceClientSet resourceclientset.Interface

// TriggersClientSet allows us to configure triggers objects
TriggersClientSet triggersclientset.Interface

Expand Down Expand Up @@ -114,8 +104,6 @@ func NewBase(opt Options, controllerAgentName string) *Base {

base := &Base{
KubeClientSet: opt.KubeClientSet,
PipelineClientSet: opt.PipelineClientSet,
ResourceClientSet: opt.ResourceClientSet,
TriggersClientSet: opt.TriggersClientSet,
CachingClientSet: opt.CachingClientSet,
ConfigMapWatcher: opt.ConfigMapWatcher,
Expand Down
6 changes: 0 additions & 6 deletions pkg/reconciler/v1alpha1/eventlistener/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"os"
"time"

pipelineclient "github.com/tektoncd/pipeline/pkg/client/injection/client"
resourceclient "github.com/tektoncd/pipeline/pkg/client/resource/injection/client"
"github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
triggersclient "github.com/tektoncd/triggers/pkg/client/injection/client"
eventlistenerinformer "github.com/tektoncd/triggers/pkg/client/injection/informers/triggers/v1alpha1/eventlistener"
Expand All @@ -44,17 +42,13 @@ const (
func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
logger := logging.FromContext(ctx)
kubeclientset := kubeclient.Get(ctx)
pipelineclientset := pipelineclient.Get(ctx)
resourceclientset := resourceclient.Get(ctx)
triggersclientset := triggersclient.Get(ctx)
eventListenerInformer := eventlistenerinformer.Get(ctx)
deploymentInformer := deployinformer.Get(ctx)
serviceInformer := serviceinformer.Get(ctx)

opt := reconciler.Options{
KubeClientSet: kubeclientset,
PipelineClientSet: pipelineclientset,
ResourceClientSet: resourceclientset,
TriggersClientSet: triggersclientset,
ConfigMapWatcher: cmw,
Logger: logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/tektoncd/pipeline/pkg/system"
"github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
"github.com/tektoncd/triggers/pkg/system"
"github.com/tektoncd/triggers/test"
bldr "github.com/tektoncd/triggers/test/builder"
appsv1 "k8s.io/api/apps/v1"
Expand Down
14 changes: 0 additions & 14 deletions pkg/sink/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package sink
import (
"flag"

pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned"
triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned"
"golang.org/x/xerrors"
discoveryclient "k8s.io/client-go/discovery"
Expand Down Expand Up @@ -60,8 +58,6 @@ type Clients struct {
DiscoveryClient discoveryclient.DiscoveryInterface
RESTClient restclient.Interface
TriggersClient triggersclientset.Interface
PipelineClient pipelineclientset.Interface
ResourceClient resourceclientset.Interface
}

// GetArgs returns the flagged Args
Expand Down Expand Up @@ -97,20 +93,10 @@ func ConfigureClients() (Clients, error) {
if err != nil {
return Clients{}, xerrors.Errorf("Failed to create TriggersClient: %s", err)
}
pipelineclient, err := pipelineclientset.NewForConfig(clusterConfig)
if err != nil {
return Clients{}, xerrors.Errorf("Failed to create PipelineClient: %s", err)
}
resourceclient, err := resourceclientset.NewForConfig(clusterConfig)
if err != nil {
return Clients{}, xerrors.Errorf("Failed to create ResourceClient: %s", err)
}

return Clients{
DiscoveryClient: kubeClient.Discovery(),
RESTClient: kubeClient.RESTClient(),
TriggersClient: triggersClient,
PipelineClient: pipelineclient,
ResourceClient: resourceclient,
}, nil
}
7 changes: 2 additions & 5 deletions pkg/sink/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"io/ioutil"
"net/http"

pipelineclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
resourceclientset "github.com/tektoncd/pipeline/pkg/client/resource/clientset/versioned"
triggersv1 "github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1"
triggersclientset "github.com/tektoncd/triggers/pkg/client/clientset/versioned"
"github.com/tektoncd/triggers/pkg/interceptors"
Expand All @@ -50,8 +48,6 @@ type Sink struct {
TriggersClient triggersclientset.Interface
DiscoveryClient discoveryclient.ServerResourcesInterface
DynamicClient dynamic.Interface
PipelineClient pipelineclientset.Interface
ResourceClient resourceclientset.Interface
HTTPClient *http.Client
EventListenerName string
EventListenerNamespace string
Expand Down Expand Up @@ -164,7 +160,8 @@ func (r Sink) processTrigger(t *triggersv1.EventListenerTrigger, request *http.R
log.Error(err)
return err
}
log.Info("params: %+v", params)

log.Infof("ResolvedParams : %+v", params)
resources := template.ResolveResources(rt.TriggerTemplate, params)
token, err := r.retrieveAuthToken(t.ServiceAccount, eventLog)
if err != nil {
Expand Down
Loading