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

feat:added format flag #8080

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Changes from 2 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
16 changes: 16 additions & 0 deletions pkg/apis/duck/v1/delivery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

@pierDipi pierDipi Jul 5, 2024

Choose a reason for hiding this comment

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

I would change the description here to be more specific

Something like

Format specifies the event format sent to subscriber and dead letter sink. 
Valid values are: 
- `json` <add link_to_cloudevents_spec_json_strucutred_format>
- `binary` <add link_to_cloudevents_spec binary format for HTTP>
- `ingress` <add description>

// +optional

Format *string `json:"format,omitempty"`
}

func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
Expand Down Expand Up @@ -123,6 +128,17 @@ func (ds *DeliverySpec) Validate(ctx context.Context) *apis.FieldError {
}
}

if ds.Format != nil {
validFormats := map[string]bool{
"structured": true,
Copy link
Member

Choose a reason for hiding this comment

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

@Cali0707 I was thinking now, since "structured" is not an event format but rather "JSON" is an event format, should we use JSON, so that if we would need to support "XML" or "protobuf" we could?

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point- let's use JSON instead then. @EraKin575 can you make the necessary changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will

"binary": true,
"ingress": true,
}
if !validFormats[*ds.Format] {
Copy link
Member

Choose a reason for hiding this comment

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

I would do a case insensitive comparison !validFormats[strings.ToLower(*ds.Format)]

Copy link
Member

Choose a reason for hiding this comment

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

This panics if ds.Format is not in the map, we need to do something like

_, ok := validFormats[*ds.Format]; !ok {

}

errs = errs.Also(apis.ErrInvalidValue(*ds.Format, "format"))
Copy link
Member

@pierDipi pierDipi Jul 5, 2024

Choose a reason for hiding this comment

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

I would add the details of the error with the list of valid values (3rd parameter to ErrInvalidValue)

apis.ErrInvalidValue(*ds.Format, "format", <detailed error>)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I will make the changes

}
}

if ds.RetryAfterMax != nil {
if feature.FromContext(ctx).IsEnabled(feature.DeliveryRetryAfter) {
p, me := period.Parse(*ds.RetryAfterMax)
Expand Down