From 4fe8fdaf988242e1355182a655b36f878f4804e3 Mon Sep 17 00:00:00 2001
From: EraKin575
Date: Fri, 5 Jul 2024 11:23:08 +0530
Subject: [PATCH 1/4] added format flag
Signed-off-by: EraKin575
---
pkg/apis/duck/v1/delivery_types.go | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/pkg/apis/duck/v1/delivery_types.go b/pkg/apis/duck/v1/delivery_types.go
index 48048a09d6e..67baef4e5de 100644
--- a/pkg/apis/duck/v1/delivery_types.go
+++ b/pkg/apis/duck/v1/delivery_types.go
@@ -81,6 +81,11 @@ type DeliverySpec struct {
//
// +optional
RetryAfterMax *string `json:"retryAfterMax,omitempty"`
+
+ //Format supports more destinations of cloudevents (which may require a specific event format)
+ // +optional
+
+ Format *string `json:"format, omityempty"`
}
func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
@@ -123,6 +128,17 @@ func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
}
}
+ if ds.Format != nil {
+ validFormats := map[string]bool{
+ "structured": true,
+ "binary": true,
+ "ingress": true,
+ }
+ if !validFormats[*ds.Format] {
+ errs = errs.Also(apis.ErrInvalidValue(*ds.Format, "format"))
+ }
+ }
+
if ds.RetryAfterMax != nil {
if feature.FromContext(ctx).IsEnabled(feature.DeliveryRetryAfter) {
p, me := period.Parse(*ds.RetryAfterMax)
From 56323005c17ca56d09eb7721cdd27338bac24e83 Mon Sep 17 00:00:00 2001
From: EraKin575
Date: Fri, 5 Jul 2024 14:32:47 +0530
Subject: [PATCH 2/4] corrected lint
Signed-off-by: EraKin575
---
pkg/apis/duck/v1/delivery_types.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pkg/apis/duck/v1/delivery_types.go b/pkg/apis/duck/v1/delivery_types.go
index 67baef4e5de..d72ccb0b022 100644
--- a/pkg/apis/duck/v1/delivery_types.go
+++ b/pkg/apis/duck/v1/delivery_types.go
@@ -85,7 +85,7 @@ type DeliverySpec struct {
//Format supports more destinations of cloudevents (which may require a specific event format)
// +optional
- Format *string `json:"format, omityempty"`
+ Format *string `json:"format,omitempty"`
}
func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
From 55433b1dbdb5e807b8cf43d32a8c6ae06c1a6d72 Mon Sep 17 00:00:00 2001
From: EraKin575
Date: Sat, 6 Jul 2024 02:08:45 +0530
Subject: [PATCH 3/4] updated generated code
Signed-off-by: EraKin575
---
docs/eventing-api.md | 17 +++++++++++++++++
pkg/apis/duck/v1/delivery_types.go | 19 ++++++++++++-------
pkg/apis/duck/v1/zz_generated.deepcopy.go | 5 +++++
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/docs/eventing-api.md b/docs/eventing-api.md
index 2244e88604f..cefd2e02164 100644
--- a/docs/eventing-api.md
+++ b/docs/eventing-api.md
@@ -504,6 +504,23 @@ For more details: http
- https://en.wikipedia.org/wiki/ISO_8601
+
+
+format
+
+string
+
+ |
+
+(Optional)
+ format specifies the desired event format for the cloud event.
+It can be one of the following values:
+- 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.
+ |
+
DeliveryStatus
diff --git a/pkg/apis/duck/v1/delivery_types.go b/pkg/apis/duck/v1/delivery_types.go
index d72ccb0b022..5ef07cf2fe0 100644
--- a/pkg/apis/duck/v1/delivery_types.go
+++ b/pkg/apis/duck/v1/delivery_types.go
@@ -18,6 +18,7 @@ package v1
import (
"context"
+ "strings"
"github.com/rickb777/date/period"
"knative.dev/pkg/apis"
@@ -82,9 +83,13 @@ type DeliverySpec struct {
// +optional
RetryAfterMax *string `json:"retryAfterMax,omitempty"`
- //Format supports more destinations of cloudevents (which may require a specific event format)
- // +optional
-
+ // format specifies the desired event format for the cloud event.
+ // It can be one of the following values:
+ // - 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"`
}
@@ -130,11 +135,11 @@ func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
if ds.Format != nil {
validFormats := map[string]bool{
- "structured": true,
- "binary": true,
- "ingress": true,
+ "JSON": true,
+ "binary": true,
+ "ingress": true,
}
- if !validFormats[*ds.Format] {
+ if _, ok := validFormats[strings.ToLower(*ds.Format)]; !ok {
errs = errs.Also(apis.ErrInvalidValue(*ds.Format, "format"))
}
}
diff --git a/pkg/apis/duck/v1/zz_generated.deepcopy.go b/pkg/apis/duck/v1/zz_generated.deepcopy.go
index d7965aaf4c6..313f09afa74 100644
--- a/pkg/apis/duck/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/duck/v1/zz_generated.deepcopy.go
@@ -201,6 +201,11 @@ func (in *DeliverySpec) DeepCopyInto(out *DeliverySpec) {
*out = new(string)
**out = **in
}
+ if in.Format != nil {
+ in, out := &in.Format, &out.Format
+ *out = new(string)
+ **out = **in
+ }
return
}
From 975b5ce47b177b01a2ed6400edf37a1b4932b98f Mon Sep 17 00:00:00 2001
From: EraKin575
Date: Sat, 6 Jul 2024 03:09:32 +0530
Subject: [PATCH 4/4] added test
Signed-off-by: EraKin575
---
pkg/apis/duck/v1/delivery_types.go | 2 +-
pkg/apis/duck/v1/delivery_types_test.go | 22 +++++++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/pkg/apis/duck/v1/delivery_types.go b/pkg/apis/duck/v1/delivery_types.go
index 5ef07cf2fe0..b70b33d65da 100644
--- a/pkg/apis/duck/v1/delivery_types.go
+++ b/pkg/apis/duck/v1/delivery_types.go
@@ -135,7 +135,7 @@ func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
if ds.Format != nil {
validFormats := map[string]bool{
- "JSON": true,
+ "json": true,
"binary": true,
"ingress": true,
}
diff --git a/pkg/apis/duck/v1/delivery_types_test.go b/pkg/apis/duck/v1/delivery_types_test.go
index 5ac8f469d56..9605e21f588 100644
--- a/pkg/apis/duck/v1/delivery_types_test.go
+++ b/pkg/apis/duck/v1/delivery_types_test.go
@@ -141,7 +141,27 @@ func TestDeliverySpecValidation(t *testing.T) {
want: func() *apis.FieldError {
return apis.ErrDisallowedFields("retryAfterMax")
}(),
- }}
+ },
+ {
+ name: "valid format JSON",
+ spec: &DeliverySpec{Format: pointer.String("json")},
+ want: nil,
+ },
+ {
+ name: "vaalid format binary",
+ spec: &DeliverySpec{Format: pointer.String("binary")},
+ want: nil,
+ }, {
+ name: "valid format ingress",
+ spec: &DeliverySpec{Format: pointer.String("ingress")},
+ want: nil,
+ }, {
+ name: "invalid format",
+ spec: &DeliverySpec{Format: pointer.String("invalid")},
+ want: func() *apis.FieldError {
+ return apis.ErrInvalidValue("invalid", "format")
+ }(),
+ }}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {