Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 4b664b9

Browse files
author
odacremolbap
committed
not compiling ... temporary
1 parent 6b6a939 commit 4b664b9

File tree

8 files changed

+246
-23
lines changed

8 files changed

+246
-23
lines changed

config/500-core-controller.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ spec:
6969
- name: REDISBROKER_REDIS_IMAGE
7070
value: redis/redis-stack-server:latest
7171
- name: REDISBROKER_BROKER_IMAGE
72-
value: pmercado/redis-broker:v0.1.0
72+
value: gcr.io/triggermesh/redis-broker:dev
7373

7474
securityContext:
7575
runAsNonRoot: true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/stretchr/testify v1.8.0
7-
github.com/triggermesh/brokers v0.0.0-20220926134808-88d6a8629e30
7+
github.com/triggermesh/brokers v0.0.0-20221018093436-f87a18b58712
88
go.uber.org/zap v1.22.0
99
k8s.io/api v0.24.4
1010
k8s.io/apimachinery v0.24.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1
506506
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
507507
github.com/triggermesh/brokers v0.0.0-20220926134808-88d6a8629e30 h1:EjHSGHBT/7hp01nmYd0vNGpIo7vOl1Lm2NRxmc8XQ4k=
508508
github.com/triggermesh/brokers v0.0.0-20220926134808-88d6a8629e30/go.mod h1:64gU9A1hlgsU6/51B3h7eDsg7KI4BvuzAE9uJ8h6V9U=
509+
github.com/triggermesh/brokers v0.0.0-20221018093436-f87a18b58712 h1:ARMQw1DtiJwfXI8Dx9pxgzSZti+iOw2znopgmmqOunI=
510+
github.com/triggermesh/brokers v0.0.0-20221018093436-f87a18b58712/go.mod h1:qcsxTLxVIa1R0XLm1g/0eMf8RpMI7EYlHiEU3gP+llg=
509511
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
510512
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
511513
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=

pkg/apis/eventing/v1alpha1/deepcopy_generated.go

Lines changed: 59 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/eventing/v1alpha1/trigger_types.go

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"k8s.io/apimachinery/pkg/runtime"
99

1010
eventingduckv1 "knative.dev/eventing/pkg/apis/duck/v1"
11-
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
1211
"knative.dev/pkg/apis"
1312
duckv1 "knative.dev/pkg/apis/duck/v1"
1413
"knative.dev/pkg/kmeta"
@@ -43,6 +42,55 @@ var (
4342
_ duckv1.KRShaped = (*Trigger)(nil)
4443
)
4544

45+
type Filter struct {
46+
// All evaluates to true if all the nested expressions evaluate to true.
47+
// It must contain at least one filter expression.
48+
//
49+
// +optional
50+
All []Filter `json:"all,omitempty"`
51+
52+
// Any evaluates to true if at least one of the nested expressions evaluates
53+
// to true. It must contain at least one filter expression.
54+
//
55+
// +optional
56+
Any []Filter `json:"any,omitempty"`
57+
58+
// Not evaluates to true if the nested expression evaluates to false.
59+
//
60+
// +optional
61+
Not *Filter `json:"not,omitempty"`
62+
63+
// Exact evaluates to true if the value of the matching CloudEvents
64+
// attribute matches exactly the String value specified (case-sensitive).
65+
// Exact must contain exactly one property, where the key is the name of the
66+
// CloudEvents attribute to be matched, and its value is the String value to
67+
// use in the comparison. The attribute name and value specified in the filter
68+
// expression cannot be empty strings.
69+
//
70+
// +optional
71+
Exact map[string]string `json:"exact,omitempty"`
72+
73+
// Prefix evaluates to true if the value of the matching CloudEvents
74+
// attribute starts with the String value specified (case-sensitive). Prefix
75+
// must contain exactly one property, where the key is the name of the
76+
// CloudEvents attribute to be matched, and its value is the String value to
77+
// use in the comparison. The attribute name and value specified in the filter
78+
// expression cannot be empty strings.
79+
//
80+
// +optional
81+
Prefix map[string]string `json:"prefix,omitempty"`
82+
83+
// Suffix evaluates to true if the value of the matching CloudEvents
84+
// attribute ends with the String value specified (case-sensitive). Suffix
85+
// must contain exactly one property, where the key is the name of the
86+
// CloudEvents attribute to be matched, and its value is the String value to
87+
// use in the comparison. The attribute name and value specified in the filter
88+
// expression cannot be empty strings.
89+
//
90+
// +optional
91+
Suffix map[string]string `json:"suffix,omitempty"`
92+
}
93+
4694
// TriggerSpec defines the desired state of Trigger
4795
type TriggerSpec struct {
4896
// Broker is the broker that this trigger receives events from.
@@ -60,7 +108,7 @@ type TriggerSpec struct {
60108
// Trigger objects.
61109
//
62110
// +optional
63-
Filters []eventingv1.SubscriptionsAPIFilter `json:"filters,omitempty"`
111+
Filters []Filter `json:"filters,omitempty"`
64112

65113
// Target is the addressable that receives events from the Broker that pass
66114
// the Filter. It is required.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2022 TriggerMesh Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
"context"
8+
"regexp"
9+
10+
"knative.dev/pkg/apis"
11+
)
12+
13+
var (
14+
// Only allow lowercase alphanumeric, starting with letters.
15+
validAttributeName = regexp.MustCompile(`^[a-z][a-z0-9]*$`)
16+
)
17+
18+
// Validate the Trigger.
19+
func (t *Trigger) Validate(ctx context.Context) *apis.FieldError {
20+
errs := t.Spec.Validate(apis.WithinSpec(ctx)).ViaField("spec")
21+
return errs
22+
}
23+
24+
// Validate the TriggerSpec.
25+
func (ts *TriggerSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
26+
27+
errs = ts.Broker.Validate(ctx).ViaField("broker")
28+
29+
return errs.Also(
30+
ValidateSubscriptionAPIFiltersList(ctx, ts.Filters).ViaField("filters"),
31+
).Also(
32+
ts.Target.Validate(ctx).ViaField("target"),
33+
).Also(
34+
ts.Delivery.Validate(ctx).ViaField("delivery"),
35+
)
36+
}
37+
38+
func ValidateSubscriptionAPIFiltersList(ctx context.Context, filters []Filter) (errs *apis.FieldError) {
39+
for i, f := range filters {
40+
f := f
41+
errs = errs.Also(ValidateSubscriptionAPIFilter(ctx, &f)).ViaIndex(i)
42+
}
43+
return errs
44+
}
45+
46+
func ValidateAttributesNames(attrs map[string]string) (errs *apis.FieldError) {
47+
for attr := range attrs {
48+
if !validAttributeName.MatchString(attr) {
49+
errs = errs.Also(apis.ErrInvalidKeyName(attr, apis.CurrentField, "Attribute name must start with a letter and can only contain lowercase alphanumeric").ViaKey(attr))
50+
}
51+
}
52+
return errs
53+
}
54+
55+
func ValidateOneOf(filter *Filter) (err *apis.FieldError) {
56+
if filter != nil && hasMultipleDialects(filter) {
57+
return apis.ErrGeneric("multiple dialects found, filters can have only one dialect set")
58+
}
59+
return nil
60+
}
61+
62+
func hasMultipleDialects(filter *Filter) bool {
63+
dialectFound := false
64+
if len(filter.Exact) > 0 {
65+
dialectFound = true
66+
}
67+
if len(filter.Prefix) > 0 {
68+
if dialectFound {
69+
return true
70+
} else {
71+
dialectFound = true
72+
}
73+
}
74+
if len(filter.Suffix) > 0 {
75+
if dialectFound {
76+
return true
77+
} else {
78+
dialectFound = true
79+
}
80+
}
81+
if len(filter.All) > 0 {
82+
if dialectFound {
83+
return true
84+
} else {
85+
dialectFound = true
86+
}
87+
}
88+
if len(filter.Any) > 0 {
89+
if dialectFound {
90+
return true
91+
} else {
92+
dialectFound = true
93+
}
94+
}
95+
if filter.Not != nil && dialectFound {
96+
return true
97+
}
98+
return false
99+
}
100+
101+
func ValidateSubscriptionAPIFilter(ctx context.Context, filter *Filter) (errs *apis.FieldError) {
102+
if filter == nil {
103+
return nil
104+
}
105+
errs = errs.Also(
106+
ValidateOneOf(filter),
107+
).Also(
108+
ValidateAttributesNames(filter.Exact).ViaField("exact"),
109+
).Also(
110+
ValidateAttributesNames(filter.Prefix).ViaField("prefix"),
111+
).Also(
112+
ValidateAttributesNames(filter.Suffix).ViaField("suffix"),
113+
).Also(
114+
ValidateSubscriptionAPIFiltersList(ctx, filter.All).ViaField("all"),
115+
).Also(
116+
ValidateSubscriptionAPIFiltersList(ctx, filter.Any).ViaField("any"),
117+
).Also(
118+
ValidateSubscriptionAPIFilter(ctx, filter.Not).ViaField("not"),
119+
)
120+
return errs
121+
}

pkg/reconciler/redisbroker/reconcile_broker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func buildBrokerDeployment(rb *eventingv1alpha1.RedisBroker, redis *corev1.Servi
8484
resources.PodSpecAddVolume(v),
8585
resources.PodSpecAddContainer(
8686
resources.NewContainer("broker", image,
87-
resources.ContainerAddArgs("start --redis.address "+redisService+" --config-path "+configMountedPath),
87+
resources.ContainerAddArgs("start --redis.address "+redisService+" --broker-config-path "+configMountedPath),
8888
resources.ContainerAddVolumeMount(vm),
8989
),
9090
),

pkg/reconciler/redisbroker/reconcile_secret.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"go.uber.org/zap"
77
"sigs.k8s.io/yaml"
88

9-
"github.com/triggermesh/brokers/pkg/config"
9+
"github.com/triggermesh/brokers/pkg/config/broker"
1010
corev1 "k8s.io/api/core/v1"
1111
apierrs "k8s.io/apimachinery/pkg/api/errors"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -103,7 +103,7 @@ func (r *secretReconciler) buildConfigSecret(ctx context.Context, rb *eventingv1
103103
"Failed to list triggers: %w", err)
104104
}
105105

106-
cfg := &config.Config{}
106+
cfg := &broker.Config{}
107107
for _, t := range triggers {
108108
// Generate secret even if the trigger is not ready, as long as one of the URIs for target
109109
// or DLS exist.
@@ -120,19 +120,19 @@ func (r *secretReconciler) buildConfigSecret(ctx context.Context, rb *eventingv1
120120
targetURI = "http://"
121121
}
122122

123-
do := &config.DeliveryOptions{}
123+
do := &broker.DeliveryOptions{}
124124
if t.Spec.Delivery != nil {
125125
do.Retry = t.Spec.Delivery.Retry
126126
do.BackoffDelay = t.Spec.Delivery.BackoffDelay
127127

128128
if t.Spec.Delivery.BackoffPolicy != nil {
129-
var bop config.BackoffPolicyType
129+
var bop broker.BackoffPolicyType
130130
switch *t.Spec.Delivery.BackoffPolicy {
131131
case duckv1.BackoffPolicyLinear:
132-
bop = config.BackoffPolicyLinear
132+
bop = broker.BackoffPolicyLinear
133133

134134
case duckv1.BackoffPolicyExponential:
135-
bop = config.BackoffPolicyLinear
135+
bop = broker.BackoffPolicyLinear
136136
}
137137
do.BackoffPolicy = &bop
138138
}
@@ -143,19 +143,16 @@ func (r *secretReconciler) buildConfigSecret(ctx context.Context, rb *eventingv1
143143
}
144144
}
145145

146-
trg := config.Trigger{
147-
Name: t.Name,
146+
trg := broker.Trigger{
148147
Filters: t.Spec.Filters,
149-
Targets: []config.Target{
150-
{
151-
URL: targetURI,
152-
DeliveryOptions: do,
153-
},
148+
Target: broker.Target{
149+
URL: targetURI,
150+
DeliveryOptions: do,
154151
},
155152
}
156153

157154
// Add Trigger data to config
158-
cfg.Triggers = append(cfg.Triggers, trg)
155+
cfg.Triggers[t.Name] = trg
159156
}
160157

161158
// add user/password

0 commit comments

Comments
 (0)