Skip to content

Commit

Permalink
fix: eventtype conversion sets all required attributes for new version (
Browse files Browse the repository at this point in the history
#8099)

Signed-off-by: Calum Murray <cmurray@redhat.com>
  • Loading branch information
Cali0707 authored Jul 12, 2024
1 parent bb2e0a3 commit 5d6c780
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
34 changes: 28 additions & 6 deletions pkg/apis/eventing/v1beta2/eventtype_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,27 @@ func (source *EventType) ConvertTo(ctx context.Context, to apis.Convertible) err
}
}

sink.Spec.Attributes = []v1beta3.EventAttributeDefinition{}
sink.Spec.Attributes = []v1beta3.EventAttributeDefinition{
{
Name: "specversion",
Required: true,
},
{
Name: "id",
Required: true,
},
}
// set all required attributes for the v1beta3 resource. if there is no value that makes sense, leave that empty
if source.Spec.Type != "" {
sink.Spec.Attributes = append(sink.Spec.Attributes, v1beta3.EventAttributeDefinition{
Name: "type",
Required: true,
Value: source.Spec.Type,
})
}
if source.Spec.Schema != nil {
} else {
sink.Spec.Attributes = append(sink.Spec.Attributes, v1beta3.EventAttributeDefinition{
Name: "schemadata",
Required: false,
Value: source.Spec.Schema.String(),
Name: "type",
Required: true,
})
}
if source.Spec.Source != nil {
Expand All @@ -66,6 +74,20 @@ func (source *EventType) ConvertTo(ctx context.Context, to apis.Convertible) err
Required: true,
Value: source.Spec.Source.String(),
})
} else {
sink.Spec.Attributes = append(sink.Spec.Attributes, v1beta3.EventAttributeDefinition{
Name: "source",
Required: true,
})
}

// convert the schema so that we don't lose it in the conversion.
if source.Spec.Schema != nil {
sink.Spec.Attributes = append(sink.Spec.Attributes, v1beta3.EventAttributeDefinition{
Name: "schemadata",
Required: false,
Value: source.Spec.Schema.String(),
})
}
return nil
default:
Expand Down
18 changes: 13 additions & 5 deletions pkg/apis/eventing/v1beta2/eventtype_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,28 @@ func TestEventTypeConversionV1Beta3(t *testing.T) {
Description: in.Spec.Description,
Attributes: []v1beta3.EventAttributeDefinition{
{
Name: "type",
Name: "specversion",
Required: true,
Value: in.Spec.Type,
},
{
Name: "schemadata",
Required: false,
Value: in.Spec.Schema.String(),
Name: "id",
Required: true,
},
{
Name: "type",
Required: true,
Value: in.Spec.Type,
},
{
Name: "source",
Required: true,
Value: in.Spec.Source.String(),
},
{
Name: "schemadata",
Required: false,
Value: in.Spec.Schema.String(),
},
},
},
Status: v1beta3.EventTypeStatus{
Expand Down

0 comments on commit 5d6c780

Please sign in to comment.