Skip to content
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
22 changes: 22 additions & 0 deletions api/v1alpha1/conversion_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
logf "sigs.k8s.io/controller-runtime/pkg/log"

libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
v1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
)

var (
Expand All @@ -45,3 +47,23 @@ func convertV1Beta1SelectorToV1Alpha1(clusterSelector *libsveltosv1beta1.Selecto

return Selector(labelSelector.String()), nil
}

func Convert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(srcSpec *v1beta1.EventReportSpec,
dstSpec *EventReportSpec, scope conversion.Scope) error {

if err := autoConvert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(srcSpec, dstSpec, nil); err != nil {
return err
}

return nil
}

func Convert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(srcSpec *v1beta1.EventSourceSpec,
dstSpec *EventSourceSpec, scope conversion.Scope) error {

if err := autoConvert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(srcSpec, dstSpec, nil); err != nil {
return err
}

return nil
}
80 changes: 56 additions & 24 deletions api/v1alpha1/zz_generated.conversion.go

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

28 changes: 28 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,34 @@ type ResourceSelector struct {
Evaluate string `json:"evaluate,omitempty"`
}

// MessagingMatchCriteria defines criteria for matching CloudEvents received via NATS.
// Sveltos listens to NATS/JetStream subjects, and the messages delivered on those
// subjects are expected to be CloudEvents.
type MessagingMatchCriteria struct {
// Subject is an optional NATS/JetStream subject filter. If specified, this criteria will
// only consider CloudEvents received on this specific subject. Leaving it empty
// means the criteria will match CloudEvents from any of the subjects Sveltos
// is subscribed to.
// +optional
Subject string `json:"subject,omitempty"`

// CloudEventSource filters CloudEvents based on their "source" attribute.
// If specified, only CloudEvents with a matching source will be considered.
// Supports exact matching.
// +optional
CloudEventSource string `json:"cloudEventSource,omitempty"`

// CloudEventType filters CloudEvents based on their "type" attribute.
// If specified, only CloudEvents with a matching type will be considered.
// Supports exact matching.
CloudEventType string `json:"cloudEventType,omitempty"`

// CloudEventSubject filters CloudEvents based on their "subject" attribute.
// If specified, only CloudEvents with a matching subject will be considered.
// Supports exact matching.
CloudEventSubject string `json:"cloudEventSubject,omitempty"`
}

type PatchSelector struct {

// Version of the API Group to select resources from.
Expand Down
6 changes: 5 additions & 1 deletion api/v1beta1/eventreport_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@ type EventReportSpec struct {
// is for.
EventSourceName string `json:"eventSourceName"`

// MatchingResources contains a list of resources matching an event
// MatchingResources contains a list of resources matching an EventSource
// +optional
MatchingResources []corev1.ObjectReference `json:"matchingResources,omitempty"`

// If EventSource Spec.CollectResources is set to true, all matching resources
// will be collected and contained in the Resources field.
// +optional
Resources []byte `json:"resources,omitempty"`

// CloudEvents contains a list of CloudEvents matching an EventSource
// +optional
CloudEvents [][]byte `json:"cloudEvents,omitempty"`
}

// EventReportStatus defines the observed state of EventReport
Expand Down
10 changes: 8 additions & 2 deletions api/v1beta1/eventsource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const (

// EventSourceSpec defines the desired state of EventSource
type EventSourceSpec struct {
// ResourceSelectors identifies what resources to select
ResourceSelectors []ResourceSelector `json:"resourceSelectors"`
// ResourceSelectors identifies what Kubernetes resources to select
// +optional
ResourceSelectors []ResourceSelector `json:"resourceSelectors,omitempty"`

// This field is optional and can be used to specify a Lua function
// that will be used to further select a subset of the resources that
Expand All @@ -53,6 +54,11 @@ type EventSourceSpec struct {
// +kubebuilder:default:=false
// +optional
CollectResources bool `json:"collectResources,omitempty"`

// MessagingMatchCriteria defines a list of MessagingMatchCriteria. Each criteria specifies
// how to match CloudEvents received on specific NATS/JetStream subjects.
// +optional
MessagingMatchCriteria []MessagingMatchCriteria `json:"messagingMatchCriteria,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
31 changes: 31 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

9 changes: 8 additions & 1 deletion config/crd/bases/lib.projectsveltos.io_eventreports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ spec:
type: object
spec:
properties:
cloudEvents:
description: CloudEvents contains a list of CloudEvents matching an
EventSource
items:
format: byte
type: string
type: array
clusterName:
description: |-
ClusterName is the name of the Cluster this EventReport
Expand All @@ -180,7 +187,7 @@ spec:
type: string
matchingResources:
description: MatchingResources contains a list of resources matching
an event
an EventSource
items:
description: ObjectReference contains enough information to let
you inspect or modify the referred object.
Expand Down
42 changes: 39 additions & 3 deletions config/crd/bases/lib.projectsveltos.io_eventsources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,46 @@ spec:
CollectResources indicates whether matching resources need
to be collected and added to EventReport.
type: boolean
messagingMatchCriteria:
description: |-
MessagingMatchCriteria defines a list of MessagingMatchCriteria. Each criteria specifies
how to match CloudEvents received on specific NATS/JetStream subjects.
items:
description: |-
MessagingMatchCriteria defines criteria for matching CloudEvents received via NATS.
Sveltos listens to NATS/JetStream subjects, and the messages delivered on those
subjects are expected to be CloudEvents.
properties:
cloudEventSource:
description: |-
CloudEventSource filters CloudEvents based on their "source" attribute.
If specified, only CloudEvents with a matching source will be considered.
Supports exact matching.
type: string
cloudEventSubject:
description: |-
CloudEventSubject filters CloudEvents based on their "subject" attribute.
If specified, only CloudEvents with a matching subject will be considered.
Supports exact matching.
type: string
cloudEventType:
description: |-
CloudEventType filters CloudEvents based on their "type" attribute.
If specified, only CloudEvents with a matching type will be considered.
Supports exact matching.
type: string
subject:
description: |-
Subject is an optional NATS/JetStream subject filter. If specified, this criteria will
only consider CloudEvents received on this specific subject. Leaving it empty
means the criteria will match CloudEvents from any of the subjects Sveltos
is subscribed to.
type: string
type: object
type: array
resourceSelectors:
description: ResourceSelectors identifies what resources to select
description: ResourceSelectors identifies what Kubernetes resources
to select
items:
description: ResourceSelector defines what resources are a match
properties:
Expand Down Expand Up @@ -235,8 +273,6 @@ spec:
- version
type: object
type: array
required:
- resourceSelectors
type: object
type: object
served: true
Expand Down
Loading