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

fix: remove ingress option from delivery format #8086

Merged
merged 1 commit into from
Jul 9, 2024
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
28 changes: 25 additions & 3 deletions docs/eventing-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ For more details: <a href="https://github.com/knative/eventing/issues/5811">http
<td>
<code>format</code><br/>
<em>
string
<a href="#duck.knative.dev/v1.FormatType">
FormatType
</a>
</em>
</td>
<td>
Expand All @@ -517,8 +519,7 @@ string
It can be one of the following values:
- nil: default value, no specific format required.
- &ldquo;JSON&rdquo;: indicates the event should be in structured mode.
- &ldquo;binary&rdquo;: indicates the event should be in binary mode.
- &ldquo;ingress&rdquo;: indicates the event should be in ingress mode.</p>
- &ldquo;binary&rdquo;: indicates the event should be in binary mode.</p>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -581,6 +582,27 @@ string
</tr>
</tbody>
</table>
<h3 id="duck.knative.dev/v1.FormatType">FormatType
(<code>string</code> alias)</p></h3>
<p>
(<em>Appears on:</em><a href="#duck.knative.dev/v1.DeliverySpec">DeliverySpec</a>)
</p>
<p>
<p>FormatType is the type for delivery format</p>
</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr><td><p>&#34;binary&#34;</p></td>
<td></td>
</tr><tr><td><p>&#34;json&#34;</p></td>
<td></td>
</tr></tbody>
</table>
<h3 id="duck.knative.dev/v1.Subscribable">Subscribable
</h3>
<p>
Expand Down
22 changes: 13 additions & 9 deletions pkg/apis/duck/v1/delivery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package v1

import (
"context"
"strings"

"github.com/rickb777/date/period"
"knative.dev/pkg/apis"
Expand Down Expand Up @@ -88,9 +87,8 @@ type DeliverySpec struct {
// - nil: default value, no specific format required.
// - "JSON": indicates the event should be in structured mode.
// - "binary": indicates the event should be in binary mode.
// - "ingress": indicates the event should be in ingress mode.
//+optional
Format *string `json:"format,omitempty"`
Format *FormatType `json:"format,omitempty"`
}

func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
Expand Down Expand Up @@ -134,12 +132,10 @@ func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
}

if ds.Format != nil {
validFormats := map[string]bool{
"json": true,
"binary": true,
"ingress": true,
}
if _, ok := validFormats[strings.ToLower(*ds.Format)]; !ok {
switch *ds.Format {
case DeliveryFormatBinary, DeliveryFormatJson:
// nothing
default:
errs = errs.Also(apis.ErrInvalidValue(*ds.Format, "format"))
}
}
Expand Down Expand Up @@ -169,6 +165,14 @@ const (
BackoffPolicyExponential BackoffPolicyType = "exponential"
)

// FormatType is the type for delivery format
type FormatType string

const (
DeliveryFormatJson FormatType = "json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not calling it structured?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an idea from #8080 (comment), I'm personally happy either way :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I was guess it was along those lines.

OK.

DeliveryFormatBinary FormatType = "binary"
)

// DeliveryStatus contains the Status of an object supporting delivery options. This type is intended to be embedded into a status struct.
type DeliveryStatus struct {
// DeadLetterSink is a KReference that is the reference to the native, platform specific channel
Expand Down
11 changes: 4 additions & 7 deletions pkg/apis/duck/v1/delivery_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/google/go-cmp/cmp"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

Expand Down Expand Up @@ -144,20 +145,16 @@ func TestDeliverySpecValidation(t *testing.T) {
},
{
name: "valid format JSON",
spec: &DeliverySpec{Format: pointer.String("json")},
spec: &DeliverySpec{Format: ptr.To(DeliveryFormatJson)},
want: nil,
},
{
name: "vaalid format binary",
spec: &DeliverySpec{Format: pointer.String("binary")},
want: nil,
}, {
name: "valid format ingress",
spec: &DeliverySpec{Format: pointer.String("ingress")},
spec: &DeliverySpec{Format: ptr.To(DeliveryFormatBinary)},
want: nil,
}, {
name: "invalid format",
spec: &DeliverySpec{Format: pointer.String("invalid")},
spec: &DeliverySpec{Format: ptr.To(FormatType("invalid"))},
want: func() *apis.FieldError {
return apis.ErrInvalidValue("invalid", "format")
}(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/duck/v1/zz_generated.deepcopy.go

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

Loading