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

Implement Trigger.Spec.DeliverySpec #612

Merged
merged 7 commits into from
Feb 10, 2021
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
150 changes: 82 additions & 68 deletions control-plane/pkg/contract/contract.pb.go

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

39 changes: 39 additions & 0 deletions control-plane/pkg/core/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package config

import (
"context"
"fmt"
"math"

"github.com/rickb777/date/period"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
duck "knative.dev/eventing/pkg/apis/duck/v1"
"knative.dev/pkg/resolver"

"knative.dev/eventing-kafka-broker/control-plane/pkg/contract"

Expand All @@ -44,6 +47,42 @@ func ContentModeFromString(mode string) contract.ContentMode {
}
}

func EgressConfigFromDelivery(
ctx context.Context,
resolver *resolver.URIResolver,
parent metav1.Object,
delivery *duck.DeliverySpec,
defaultBackoffDelayMs uint64,
) (*contract.EgressConfig, error) {

if delivery == nil || (delivery.DeadLetterSink == nil && delivery.Retry == nil) {
return nil, nil
}

egressConfig := &contract.EgressConfig{}

if delivery.DeadLetterSink != nil {
deadLetterSinkURL, err := resolver.URIFromDestinationV1(ctx, *delivery.DeadLetterSink, parent)
if err != nil {
return nil, fmt.Errorf("failed to resolve Spec.Delivery.DeadLetterSink: %w", err)
}
egressConfig.DeadLetter = deadLetterSinkURL.String()
}

if delivery.Retry != nil {
egressConfig.Retry = uint32(*delivery.Retry)
var err error
delay, err := BackoffDelayFromISO8601String(delivery.BackoffDelay, defaultBackoffDelayMs)
if err != nil {
return nil, fmt.Errorf("failed to parse Spec.Delivery.BackoffDelay: %w", err)
}
egressConfig.BackoffDelay = delay
egressConfig.BackoffPolicy = BackoffPolicyFromString(delivery.BackoffPolicy)
}

return egressConfig, nil
}

// BackoffPolicyFromString returns the BackoffPolicy from the given string.
//
// Default value is contract.BackoffPolicy_Exponential.
Expand Down
Loading