Skip to content

Commit

Permalink
add tolerations to eventlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwonsoo Lee committed Jun 5, 2020
1 parent dd1aff6 commit bf2c48c
Show file tree
Hide file tree
Showing 18 changed files with 299 additions and 30 deletions.
5 changes: 5 additions & 0 deletions examples/eventlisteners/eventlistener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ metadata:
name: listener
spec:
serviceAccountName: tekton-triggers-example-sa
# tolerations:
# - key: key
# value: value
# operator: Equal
# effect: NoSchedule
triggers:
- name: foo-trig
bindings:
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ require (
github.com/google/go-github/v31 v31.0.0
github.com/gorilla/mux v1.7.3
github.com/grpc-ecosystem/grpc-gateway v1.13.0 // indirect
github.com/onsi/ginkgo v1.10.2 // indirect
github.com/openzipkin/zipkin-go v0.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/tektoncd/pipeline v0.11.3
github.com/tektoncd/plumbing v0.0.0-20200430135134-e53521e1d887
Expand All @@ -27,7 +29,7 @@ require (
k8s.io/api v0.18.2
k8s.io/apimachinery v0.18.2
k8s.io/client-go v0.18.2
k8s.io/code-generator v0.17.1
k8s.io/code-generator v0.17.2
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 // indirect
Expand Down
37 changes: 37 additions & 0 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/apis/triggers/v1alpha1/event_listener_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type EventListenerSpec struct {
ServiceAccountName string `json:"serviceAccountName"`
Triggers []EventListenerTrigger `json:"triggers"`
ServiceType corev1.ServiceType `json:"serviceType,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
}

// EventListenerTrigger represents a connection between TriggerBinding, Params,
Expand Down
7 changes: 7 additions & 0 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.

5 changes: 5 additions & 0 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func (c *Reconciler) reconcileDeployment(el *v1alpha1.EventListener) error {
Labels: labels,
},
Spec: corev1.PodSpec{
Tolerations: el.Spec.Tolerations,
ServiceAccountName: el.Spec.ServiceAccountName,
Containers: []corev1.Container{container},

Expand Down Expand Up @@ -358,6 +359,10 @@ func (c *Reconciler) reconcileDeployment(el *v1alpha1.EventListener) error {
existingDeployment.Spec.Template.Spec.ServiceAccountName = deployment.Spec.Template.Spec.ServiceAccountName
updated = true
}
if !reflect.DeepEqual(existingDeployment.Spec.Template.Spec.Tolerations, deployment.Spec.Template.Spec.Tolerations) {
existingDeployment.Spec.Template.Spec.Tolerations = deployment.Spec.Template.Spec.Tolerations
updated = true
}
if len(existingDeployment.Spec.Template.Spec.Containers) == 0 ||
len(existingDeployment.Spec.Template.Spec.Containers) > 1 {
existingDeployment.Spec.Template.Spec.Containers = []corev1.Container{container}
Expand Down
63 changes: 62 additions & 1 deletion pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func init() {
eventListener0 = bldr.EventListener(eventListenerName, namespace,
bldr.EventListenerSpec(
bldr.EventListenerServiceAccount("sa"),
bldr.EventListenerTolerations(nil),
),
bldr.EventListenerStatus(
bldr.EventListenerConfig(generatedResourceName),
Expand Down Expand Up @@ -79,6 +80,14 @@ var (
reconcileKey = fmt.Sprintf("%s/%s", namespace, eventListenerName)
updateLabel = map[string]string{"update": "true"}
updatedSa = "updatedSa"
updateTolerations = []corev1.Toleration{
{
Key: "key",
Operator: "Equal",
Value: "value",
Effect: "NoSchedule",
},
}
deploymentAvailableCondition = appsv1.DeploymentCondition{
Type: appsv1.DeploymentAvailable,
Status: corev1.ConditionTrue,
Expand Down Expand Up @@ -266,6 +275,9 @@ func Test_reconcileDeployment(t *testing.T) {
eventListener4 := eventListener1.DeepCopy()
eventListener4.Spec.ServiceAccountName = updatedSa

eventListener5 := eventListener1.DeepCopy()
eventListener5.Spec.Tolerations = updateTolerations

var replicas int32 = 1
// deployment1 == initial deployment
deployment1 := &appsv1.Deployment{
Expand All @@ -280,6 +292,7 @@ func Test_reconcileDeployment(t *testing.T) {
Labels: generatedLabels,
},
Spec: corev1.PodSpec{
Tolerations: eventListener0.Spec.Tolerations,
ServiceAccountName: eventListener0.Spec.ServiceAccountName,
Containers: []corev1.Container{
{
Expand Down Expand Up @@ -373,6 +386,9 @@ func Test_reconcileDeployment(t *testing.T) {
deployment4 := deployment1.DeepCopy()
deployment4.Spec.Template.Spec.ServiceAccountName = updatedSa

deployment5 := deployment1.DeepCopy()
deployment5.Spec.Template.Spec.Tolerations = updateTolerations

deploymentMissingVolumes := deployment1.DeepCopy()
deploymentMissingVolumes.Spec.Template.Spec.Volumes = nil
deploymentMissingVolumes.Spec.Template.Spec.Containers[0].VolumeMounts = nil
Expand Down Expand Up @@ -458,7 +474,21 @@ func Test_reconcileDeployment(t *testing.T) {
EventListeners: []*v1alpha1.EventListener{eventListener4},
Deployments: []*appsv1.Deployment{deployment4},
},
}, {
},
{
name: "eventlistener-tolerations-update",
startResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{eventListener5},
Deployments: []*appsv1.Deployment{deployment1},
},
endResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{eventListener5},
Deployments: []*appsv1.Deployment{deployment5},
},
},
{
name: "eventlistener-config-volume-mount-update",
startResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
Expand Down Expand Up @@ -512,6 +542,14 @@ func TestReconcile(t *testing.T) {
eventListener1 := bldr.EventListener(eventListenerName, namespace,
bldr.EventListenerSpec(
bldr.EventListenerServiceAccount("sa"),
bldr.EventListenerTolerations([]corev1.Toleration{
{
Key: "key",
Operator: "Equal",
Value: "value",
Effect: "NoSchedule",
},
}),
),
bldr.EventListenerStatus(
bldr.EventListenerConfig(generatedResourceName),
Expand Down Expand Up @@ -550,6 +588,9 @@ func TestReconcile(t *testing.T) {
eventListener4 := eventListener3.DeepCopy()
eventListener4.Spec.ServiceType = corev1.ServiceTypeNodePort

eventListener5 := eventListener2.DeepCopy()
eventListener5.Spec.Tolerations = updateTolerations

var replicas int32 = 1
deployment1 := &appsv1.Deployment{
ObjectMeta: generateObjectMeta(eventListener0),
Expand All @@ -563,6 +604,7 @@ func TestReconcile(t *testing.T) {
Labels: generatedLabels,
},
Spec: corev1.PodSpec{
Tolerations: eventListener0.Spec.Tolerations,
ServiceAccountName: eventListener0.Spec.ServiceAccountName,
Containers: []corev1.Container{{
Name: "event-listener",
Expand Down Expand Up @@ -640,6 +682,9 @@ func TestReconcile(t *testing.T) {
deployment3 := deployment2.DeepCopy()
deployment3.Spec.Template.Spec.ServiceAccountName = updatedSa

deployment4 := deployment2.DeepCopy()
deployment4.Spec.Template.Spec.Tolerations = updateTolerations

service1 := &corev1.Service{
ObjectMeta: generateObjectMeta(eventListener0),
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -725,6 +770,22 @@ func TestReconcile(t *testing.T) {
Services: []*corev1.Service{service2},
ConfigMaps: []*corev1.ConfigMap{loggingConfigMap},
},
}, {
name: "update-eventlistener-tolerations",
key: reconcileKey,
startResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{eventListener5},
Deployments: []*appsv1.Deployment{deployment2},
Services: []*corev1.Service{service2},
},
endResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{eventListener5},
Deployments: []*appsv1.Deployment{deployment4},
Services: []*corev1.Service{service2},
ConfigMaps: []*corev1.ConfigMap{loggingConfigMap},
},
}, {
name: "update-eventlistener-servicetype",
key: reconcileKey,
Expand Down
7 changes: 7 additions & 0 deletions test/builder/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func EventListenerServiceAccount(saName string) EventListenerSpecOp {
}
}

// EventListenerTolerations sets the specified Tolerations of the EventListener.
func EventListenerTolerations(tolerations []corev1.Toleration) EventListenerSpecOp {
return func(spec *v1alpha1.EventListenerSpec) {
spec.Tolerations = tolerations
}
}

// EventListenerTrigger adds an EventListenerTrigger to the EventListenerSpec Triggers.
// Any number of EventListenerTriggerOp modifiers can be passed to create/modify it.
func EventListenerTrigger(ttName, apiVersion string, ops ...EventListenerTriggerOp) EventListenerSpecOp {
Expand Down
13 changes: 12 additions & 1 deletion test/eventlistener_scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,18 @@ func TestEventListenerScale(t *testing.T) {
// Create an EventListener with 1000 Triggers
var err error
el := bldr.EventListener("my-eventlistener", namespace, bldr.EventListenerSpec(
bldr.EventListenerServiceAccount(saName)),
bldr.EventListenerServiceAccount(saName),
bldr.EventListenerTolerations(nil)),
// If you want to test toleration feature, please use this commented part.
//bldr.EventListenerTolerations([]corev1.Toleration{
// {
// Key: "key",
// Operator: "Equal",
// Value: "value",
// Effect: "NoSchedule",
// },
// }),
//),
)

for i := 0; i < 1000; i++ {
Expand Down
10 changes: 10 additions & 0 deletions test/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ func TestEventListenerCreate(t *testing.T) {
),
bldr.EventListenerSpec(
bldr.EventListenerServiceAccount(sa.Name),
bldr.EventListenerTolerations(nil),
// If you want to test toleration feature, please use this commented part.
//bldr.EventListenerTolerations([]corev1.Toleration{
// {
// Key: "key",
// Operator: "Equal",
// Value: "value",
// Effect: "NoSchedule",
// },
//}),
bldr.EventListenerTrigger(tt.Name, "",
bldr.EventListenerTriggerBinding(tb.Name, "", tb.Name, "v1alpha1"),
bldr.EventListenerTriggerBinding(ctb.Name, "ClusterTriggerBinding", ctb.Name, "v1alpha1"),
Expand Down
11 changes: 3 additions & 8 deletions vendor/github.com/pkg/errors/.travis.yml

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

44 changes: 44 additions & 0 deletions vendor/github.com/pkg/errors/Makefile

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

11 changes: 9 additions & 2 deletions vendor/github.com/pkg/errors/README.md

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

8 changes: 7 additions & 1 deletion vendor/github.com/pkg/errors/errors.go

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

Loading

0 comments on commit bf2c48c

Please sign in to comment.