Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Commit dd3a4ff

Browse files
authored
Updating to latest 0.18 (go get -v -d knative.dev/eventing@release-0.18 && ./hack/update-deps.sh) (#1653)
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
1 parent b9ce948 commit dd3a4ff

40 files changed

+1181
-888
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
k8s.io/apimachinery v0.18.8
2626
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
2727
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451
28-
knative.dev/eventing v0.18.0
28+
knative.dev/eventing v0.18.4-0.20201028193234-25836253934e
2929
knative.dev/pkg v0.0.0-20200922164940-4bf40ad82aab
3030
knative.dev/test-infra v0.0.0-20200921012245-37f1a12adbd3
3131
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,8 +1931,8 @@ k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 h1:v8ud2Up6QK1lNOKFgiIVrZdMg7Mpm
19311931
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
19321932
knative.dev/caching v0.0.0-20190719140829-2032732871ff/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg=
19331933
knative.dev/caching v0.0.0-20200116200605-67bca2c83dfa/go.mod h1:dHXFU6CGlLlbzaWc32g80cR92iuBSpsslDNBWI8C7eg=
1934-
knative.dev/eventing v0.18.0 h1:DKRDpIAYZtFt959m4m9oWHnNBBH97yMP+nekrqmjOF8=
1935-
knative.dev/eventing v0.18.0/go.mod h1:Rv5V1Sk/XeG6vdEpRu+zDhEUDg2SgbkOJWRNssUyt50=
1934+
knative.dev/eventing v0.18.4-0.20201028193234-25836253934e h1:G56dQeg8sig6qubcLkl2u1OpYPHF1n/zowaiGD7p+HA=
1935+
knative.dev/eventing v0.18.4-0.20201028193234-25836253934e/go.mod h1:Rv5V1Sk/XeG6vdEpRu+zDhEUDg2SgbkOJWRNssUyt50=
19361936
knative.dev/eventing-contrib v0.6.1-0.20190723221543-5ce18048c08b/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g=
19371937
knative.dev/eventing-contrib v0.6.1-0.20190723221543-5ce18048c08b/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g=
19381938
knative.dev/eventing-contrib v0.6.1-0.20190723221543-5ce18048c08b/go.mod h1:SnXZgSGgMSMLNFTwTnpaOH7hXDzTFtw0J8OmHflNx3g=

vendor/knative.dev/eventing/pkg/adapter/v2/cloudevents.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import (
1919
"context"
2020
"errors"
2121
"fmt"
22+
nethttp "net/http"
2223
"net/url"
24+
"time"
2325

2426
cloudevents "github.com/cloudevents/sdk-go/v2"
2527
"github.com/cloudevents/sdk-go/v2/event"
@@ -35,9 +37,18 @@ import (
3537
// NewCloudEventsClient returns a client that will apply the ceOverrides to
3638
// outbound events and report outbound event counts.
3739
func NewCloudEventsClient(target string, ceOverrides *duckv1.CloudEventOverrides, reporter source.StatsReporter) (cloudevents.Client, error) {
38-
return NewCloudEventsClientCRStatus(target, ceOverrides, reporter, nil)
40+
return newCloudEventsClientCRStatus(nil, target, ceOverrides, reporter, nil)
3941
}
40-
func NewCloudEventsClientCRStatus(target string, ceOverrides *duckv1.CloudEventOverrides, reporter source.StatsReporter, crStatusEventClient *crstatusevent.CRStatusEventClient) (cloudevents.Client, error) {
42+
func NewCloudEventsClientCRStatus(env EnvConfigAccessor, reporter source.StatsReporter, crStatusEventClient *crstatusevent.CRStatusEventClient) (cloudevents.Client, error) {
43+
return newCloudEventsClientCRStatus(env, "", nil, reporter, crStatusEventClient)
44+
}
45+
func newCloudEventsClientCRStatus(env EnvConfigAccessor, target string, ceOverrides *duckv1.CloudEventOverrides, reporter source.StatsReporter,
46+
crStatusEventClient *crstatusevent.CRStatusEventClient) (cloudevents.Client, error) {
47+
48+
if target == "" && env != nil {
49+
target = env.GetSink()
50+
}
51+
4152
pOpts := make([]http.Option, 0)
4253
if len(target) > 0 {
4354
pOpts = append(pOpts, cloudevents.WithTarget(target))
@@ -46,6 +57,19 @@ func NewCloudEventsClientCRStatus(target string, ceOverrides *duckv1.CloudEventO
4657
Propagation: tracecontextb3.TraceContextEgress,
4758
}))
4859

60+
if env != nil {
61+
if sinkWait := env.GetSinktimeout(); sinkWait > 0 {
62+
pOpts = append(pOpts, setTimeOut(time.Duration(sinkWait)*time.Second))
63+
}
64+
var err error
65+
if ceOverrides == nil {
66+
ceOverrides, err = env.GetCloudEventOverrides()
67+
if err != nil {
68+
return nil, err
69+
}
70+
}
71+
}
72+
4973
p, err := cloudevents.NewHTTP(pOpts...)
5074
if err != nil {
5175
return nil, err
@@ -67,6 +91,19 @@ func NewCloudEventsClientCRStatus(target string, ceOverrides *duckv1.CloudEventO
6791
}, nil
6892
}
6993

94+
func setTimeOut(duration time.Duration) http.Option {
95+
return func(p *http.Protocol) error {
96+
if p == nil {
97+
return fmt.Errorf("http target option can not set nil protocol")
98+
}
99+
if p.Client == nil {
100+
p.Client = &nethttp.Client{}
101+
}
102+
p.Client.Timeout = duration
103+
return nil
104+
}
105+
}
106+
70107
type client struct {
71108
ceClient cloudevents.Client
72109
ceOverrides *duckv1.CloudEventOverrides

vendor/knative.dev/eventing/pkg/adapter/v2/config.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package adapter
1717

1818
import (
1919
"encoding/json"
20+
"os"
21+
"strconv"
2022
"time"
2123

2224
"go.uber.org/zap"
@@ -43,6 +45,7 @@ const (
4345
EnvConfigLoggingConfig = "K_LOGGING_CONFIG"
4446
EnvConfigTracingConfig = "K_TRACING_CONFIG"
4547
EnvConfigLeaderElectionConfig = "K_LEADER_ELECTION_CONFIG"
48+
EnvSinkTimeout = "K_SINK_TIMEOUT"
4649
)
4750

4851
// EnvConfig is the minimal set of configuration parameters
@@ -85,6 +88,9 @@ type EnvConfig struct {
8588

8689
// LeaderElectionConfigJson is the leader election component configuration.
8790
LeaderElectionConfigJson string `envconfig:"K_LEADER_ELECTION_CONFIG"`
91+
92+
// Time in seconds to wait for sink to respond
93+
EnvSinkTimeout int `envconfig:"K_SINK_TIMEOUT"`
8894
}
8995

9096
// EnvConfigAccessor defines accessors for the minimal
@@ -114,6 +120,9 @@ type EnvConfigAccessor interface {
114120

115121
// GetLeaderElectionConfig returns leader election configuration.
116122
GetLeaderElectionConfig() (*kle.ComponentConfig, error)
123+
124+
// Get the name of the adapter.
125+
GetSinktimeout() int
117126
}
118127

119128
var _ EnvConfigAccessor = (*EnvConfig)(nil)
@@ -158,6 +167,10 @@ func (e *EnvConfig) GetName() string {
158167
return e.Name
159168
}
160169

170+
func (e *EnvConfig) GetSinktimeout() int {
171+
return e.EnvSinkTimeout
172+
}
173+
161174
func (e *EnvConfig) SetupTracing(logger *zap.SugaredLogger) error {
162175
config, err := tracingconfig.JsonToTracingConfig(e.TracingConfigJson)
163176
if err != nil {
@@ -209,3 +222,19 @@ func LeaderElectionComponentConfigToJson(cfg *kle.ComponentConfig) (string, erro
209222
jsonCfg, err := json.Marshal(cfg)
210223
return string(jsonCfg), err
211224
}
225+
226+
func GetSinkTimeout(logger *zap.SugaredLogger) int {
227+
str := os.Getenv(EnvSinkTimeout)
228+
if str != "" {
229+
var err error
230+
duration, err := strconv.Atoi(str)
231+
if err != nil || duration < 0 {
232+
if logger != nil {
233+
logger.Errorf("%s environment value is invalid. It must be a integer greater than zero. (got %s)", EnvSinkTimeout, str)
234+
}
235+
return -1
236+
}
237+
return duration
238+
}
239+
return -1
240+
}

vendor/knative.dev/eventing/pkg/adapter/v2/main.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"flag"
2222
"fmt"
23-
2423
"log"
2524
"net/http"
2625
"strconv"
@@ -160,12 +159,7 @@ func MainWithInformers(ctx context.Context, component string, env EnvConfigAcces
160159
logger.Error("Error setting up trace publishing", zap.Error(err))
161160
}
162161

163-
ceOverrides, err := env.GetCloudEventOverrides()
164-
if err != nil {
165-
logger.Error("Error loading cloudevents overrides", zap.Error(err))
166-
}
167-
168-
eventsClient, err := NewCloudEventsClientCRStatus(env.GetSink(), ceOverrides, reporter, crStatusEventClient)
162+
eventsClient, err := NewCloudEventsClientCRStatus(env, reporter, crStatusEventClient)
169163
if err != nil {
170164
logger.Fatal("Error building cloud event client", zap.Error(err))
171165
}

vendor/knative.dev/eventing/pkg/apis/eventing/v1/trigger_lifecycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (ts *TriggerStatus) MarkDependencyNotConfigured() {
167167
"DependencyNotConfigured", "Dependency has not yet been reconciled.")
168168
}
169169

170-
func (ts *TriggerStatus) PropagateDependencyStatus(ks *duckv1.KResource) {
170+
func (ts *TriggerStatus) PropagateDependencyStatus(ks *duckv1.Source) {
171171
kc := ks.Status.GetCondition(apis.ConditionReady)
172172
if kc == nil {
173173
ts.MarkDependencyNotConfigured()

vendor/knative.dev/eventing/pkg/apis/sources/v1beta1/sinkbinding_context.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@ import (
2020
"context"
2121

2222
"knative.dev/pkg/apis"
23+
"knative.dev/pkg/resolver"
2324
)
2425

2526
// sinkURIKey is used as the key for associating information
2627
// with a context.Context.
2728
type sinkURIKey struct{}
29+
type resolverKey struct{}
2830

2931
// WithSinkURI notes on the context for binding that the resolved SinkURI
3032
// is the provided apis.URL.
3133
func WithSinkURI(ctx context.Context, uri *apis.URL) context.Context {
3234
return context.WithValue(ctx, sinkURIKey{}, uri)
3335
}
3436

37+
func WithURIResolver(ctx context.Context, resolver *resolver.URIResolver) context.Context {
38+
return context.WithValue(ctx, resolverKey{}, resolver)
39+
}
40+
3541
// GetSinkURI accesses the apis.URL for the Sink URI that has been associated
3642
// with this context.
3743
func GetSinkURI(ctx context.Context) *apis.URL {
@@ -41,3 +47,11 @@ func GetSinkURI(ctx context.Context) *apis.URL {
4147
}
4248
return value.(*apis.URL)
4349
}
50+
51+
func GetURIResolver(ctx context.Context) *resolver.URIResolver {
52+
value := ctx.Value(resolverKey{})
53+
if value == nil {
54+
return nil
55+
}
56+
return value.(*resolver.URIResolver)
57+
}

vendor/knative.dev/eventing/pkg/apis/sources/v1beta1/sinkbinding_lifecycle.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323

2424
"go.uber.org/zap"
25-
2625
corev1 "k8s.io/api/core/v1"
2726
"k8s.io/apimachinery/pkg/runtime/schema"
2827

@@ -33,7 +32,9 @@ import (
3332
"knative.dev/pkg/tracker"
3433
)
3534

36-
var sbCondSet = apis.NewLivingConditionSet()
35+
var sbCondSet = apis.NewLivingConditionSet(
36+
SinkBindingConditionSinkProvided,
37+
)
3738

3839
// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface.
3940
func (*SinkBinding) GetConditionSet() apis.ConditionSet {
@@ -82,16 +83,31 @@ func (sbs *SinkBindingStatus) MarkBindingAvailable() {
8283
sbCondSet.Manage(sbs).MarkTrue(SinkBindingConditionReady)
8384
}
8485

86+
// MarkSink sets the condition that the source has a sink configured.
87+
func (sbs *SinkBindingStatus) MarkSink(uri *apis.URL) {
88+
sbs.SinkURI = uri
89+
if uri != nil {
90+
sbCondSet.Manage(sbs).MarkTrue(SinkBindingConditionSinkProvided)
91+
} else {
92+
sbCondSet.Manage(sbs).MarkFalse(SinkBindingConditionSinkProvided, "SinkEmpty", "Sink has resolved to empty.%s", "")
93+
}
94+
}
95+
8596
// Do implements psbinding.Bindable
8697
func (sb *SinkBinding) Do(ctx context.Context, ps *duckv1.WithPod) {
8798
// First undo so that we can just unconditionally append below.
8899
sb.Undo(ctx, ps)
89100

90-
uri := GetSinkURI(ctx)
91-
if uri == nil {
92-
logging.FromContext(ctx).Errorf("No sink URI associated with context for %+v", sb)
101+
resolver := GetURIResolver(ctx)
102+
if resolver == nil {
103+
logging.FromContext(ctx).Errorf("No Resolver associated with context for sink: %+v", sb)
104+
}
105+
uri, err := resolver.URIFromDestinationV1(ctx, sb.Spec.Sink, sb)
106+
if err != nil {
107+
logging.FromContext(ctx).Errorw("URI could not be extracted from destination: ", zap.Error(err))
93108
return
94109
}
110+
sb.Status.MarkSink(uri)
95111

96112
var ceOverrides string
97113
if sb.Spec.CloudEventOverrides != nil {

vendor/knative.dev/eventing/pkg/apis/sources/v1beta1/sinkbinding_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ const (
7272
// SinkBindingConditionReady is configured to indicate whether the Binding
7373
// has been configured for resources subject to its runtime contract.
7474
SinkBindingConditionReady = apis.ConditionReady
75+
76+
// SinkBindingConditionSinkProvided is configured to indicate whether the
77+
// sink has been properly extracted from the resolver.
78+
SinkBindingConditionSinkProvided apis.ConditionType = "SinkProvided"
7579
)
7680

7781
// SinkBindingStatus communicates the observed state of the SinkBinding (from the controller).

vendor/knative.dev/eventing/pkg/kncloudevents/message_sender.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ func (s *HttpMessageSender) SendWithRetries(req *nethttp.Request, config *RetryC
139139
},
140140
}
141141

142-
return retryableClient.Do(&retryablehttp.Request{Request: req})
142+
retryableReq, err := retryablehttp.FromRequest(req)
143+
if err != nil {
144+
return nil, err
145+
}
146+
147+
return retryableClient.Do(retryableReq)
143148
}
144149

145150
func NoRetries() RetryConfig {

0 commit comments

Comments
 (0)