Skip to content

Commit

Permalink
fix: remove ingress option from delivery format (#8086)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <cmurray@redhat.com>
  • Loading branch information
Cali0707 authored Jul 9, 2024
1 parent 9eed163 commit 71d7e5e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
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"
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.

0 comments on commit 71d7e5e

Please sign in to comment.