diff --git a/api/v1alpha1/conversion_utils.go b/api/v1alpha1/conversion_utils.go index 2139912f..dcb2a1a6 100644 --- a/api/v1alpha1/conversion_utils.go +++ b/api/v1alpha1/conversion_utils.go @@ -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 ( @@ -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 +} diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index 5a276353..9e1bdfb6 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -333,11 +333,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1beta1.EventReportSpec)(nil), (*EventReportSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(a.(*v1beta1.EventReportSpec), b.(*EventReportSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*EventReportStatus)(nil), (*v1beta1.EventReportStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_EventReportStatus_To_v1beta1_EventReportStatus(a.(*EventReportStatus), b.(*v1beta1.EventReportStatus), scope) }); err != nil { @@ -373,11 +368,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1beta1.EventSourceSpec)(nil), (*EventSourceSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(a.(*v1beta1.EventSourceSpec), b.(*EventSourceSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*HealthCheck)(nil), (*v1beta1.HealthCheck)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_HealthCheck_To_v1beta1_HealthCheck(a.(*HealthCheck), b.(*v1beta1.HealthCheck), scope) }); err != nil { @@ -848,6 +838,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.EventReportSpec)(nil), (*EventReportSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(a.(*v1beta1.EventReportSpec), b.(*EventReportSpec), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*v1beta1.EventSourceSpec)(nil), (*EventSourceSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(a.(*v1beta1.EventSourceSpec), b.(*EventSourceSpec), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.RoleRequestSpec)(nil), (*RoleRequestSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_RoleRequestSpec_To_v1alpha1_RoleRequestSpec(a.(*v1beta1.RoleRequestSpec), b.(*RoleRequestSpec), scope) }); err != nil { @@ -1625,7 +1625,17 @@ func Convert_v1beta1_EventReport_To_v1alpha1_EventReport(in *v1beta1.EventReport func autoConvert_v1alpha1_EventReportList_To_v1beta1_EventReportList(in *EventReportList, out *v1beta1.EventReportList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1beta1.EventReport)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.EventReport, len(*in)) + for i := range *in { + if err := Convert_v1alpha1_EventReport_To_v1beta1_EventReport(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1636,7 +1646,17 @@ func Convert_v1alpha1_EventReportList_To_v1beta1_EventReportList(in *EventReport func autoConvert_v1beta1_EventReportList_To_v1alpha1_EventReportList(in *v1beta1.EventReportList, out *EventReportList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]EventReport)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]EventReport, len(*in)) + for i := range *in { + if err := Convert_v1beta1_EventReport_To_v1alpha1_EventReport(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1667,14 +1687,10 @@ func autoConvert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(in *v1beta1 out.EventSourceName = in.EventSourceName out.MatchingResources = *(*[]v1.ObjectReference)(unsafe.Pointer(&in.MatchingResources)) out.Resources = *(*[]byte)(unsafe.Pointer(&in.Resources)) + // WARNING: in.CloudEvents requires manual conversion: does not exist in peer-type return nil } -// Convert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec is an autogenerated conversion function. -func Convert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(in *v1beta1.EventReportSpec, out *EventReportSpec, s conversion.Scope) error { - return autoConvert_v1beta1_EventReportSpec_To_v1alpha1_EventReportSpec(in, out, s) -} - func autoConvert_v1alpha1_EventReportStatus_To_v1beta1_EventReportStatus(in *EventReportStatus, out *v1beta1.EventReportStatus, s conversion.Scope) error { out.Phase = (*v1beta1.ReportPhase)(unsafe.Pointer(in.Phase)) return nil @@ -1723,7 +1739,17 @@ func Convert_v1beta1_EventSource_To_v1alpha1_EventSource(in *v1beta1.EventSource func autoConvert_v1alpha1_EventSourceList_To_v1beta1_EventSourceList(in *EventSourceList, out *v1beta1.EventSourceList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1beta1.EventSource)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1beta1.EventSource, len(*in)) + for i := range *in { + if err := Convert_v1alpha1_EventSource_To_v1beta1_EventSource(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1734,7 +1760,17 @@ func Convert_v1alpha1_EventSourceList_To_v1beta1_EventSourceList(in *EventSource func autoConvert_v1beta1_EventSourceList_To_v1alpha1_EventSourceList(in *v1beta1.EventSourceList, out *EventSourceList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]EventSource)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]EventSource, len(*in)) + for i := range *in { + if err := Convert_v1beta1_EventSource_To_v1alpha1_EventSource(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1759,14 +1795,10 @@ func autoConvert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(in *v1beta1 out.ResourceSelectors = *(*[]ResourceSelector)(unsafe.Pointer(&in.ResourceSelectors)) out.AggregatedSelection = in.AggregatedSelection out.CollectResources = in.CollectResources + // WARNING: in.MessagingMatchCriteria requires manual conversion: does not exist in peer-type return nil } -// Convert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec is an autogenerated conversion function. -func Convert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(in *v1beta1.EventSourceSpec, out *EventSourceSpec, s conversion.Scope) error { - return autoConvert_v1beta1_EventSourceSpec_To_v1alpha1_EventSourceSpec(in, out, s) -} - func autoConvert_v1alpha1_HealthCheck_To_v1beta1_HealthCheck(in *HealthCheck, out *v1beta1.HealthCheck, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1alpha1_HealthCheckSpec_To_v1beta1_HealthCheckSpec(&in.Spec, &out.Spec, s); err != nil { diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index b1ffc6a6..5f8dcfe9 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -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. diff --git a/api/v1beta1/eventreport_type.go b/api/v1beta1/eventreport_type.go index bd448389..315c3238 100644 --- a/api/v1beta1/eventreport_type.go +++ b/api/v1beta1/eventreport_type.go @@ -73,7 +73,7 @@ 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"` @@ -81,6 +81,10 @@ type EventReportSpec struct { // 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 diff --git a/api/v1beta1/eventsource_type.go b/api/v1beta1/eventsource_type.go index fff4eeff..4a61d5d1 100644 --- a/api/v1beta1/eventsource_type.go +++ b/api/v1beta1/eventsource_type.go @@ -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 @@ -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 diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index c3c39328..5a92fd72 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -836,6 +836,17 @@ func (in *EventReportSpec) DeepCopyInto(out *EventReportSpec) { *out = make([]byte, len(*in)) copy(*out, *in) } + if in.CloudEvents != nil { + in, out := &in.CloudEvents, &out.CloudEvents + *out = make([][]byte, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make([]byte, len(*in)) + copy(*out, *in) + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EventReportSpec. @@ -936,6 +947,11 @@ func (in *EventSourceSpec) DeepCopyInto(out *EventSourceSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.MessagingMatchCriteria != nil { + in, out := &in.MessagingMatchCriteria, &out.MessagingMatchCriteria + *out = make([]MessagingMatchCriteria, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EventSourceSpec. @@ -1326,6 +1342,21 @@ func (in *MachingClusterStatus) DeepCopy() *MachingClusterStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MessagingMatchCriteria) DeepCopyInto(out *MessagingMatchCriteria) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MessagingMatchCriteria. +func (in *MessagingMatchCriteria) DeepCopy() *MessagingMatchCriteria { + if in == nil { + return nil + } + out := new(MessagingMatchCriteria) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Notification) DeepCopyInto(out *Notification) { *out = *in diff --git a/config/crd/bases/lib.projectsveltos.io_eventreports.yaml b/config/crd/bases/lib.projectsveltos.io_eventreports.yaml index ce316b00..9de876fc 100644 --- a/config/crd/bases/lib.projectsveltos.io_eventreports.yaml +++ b/config/crd/bases/lib.projectsveltos.io_eventreports.yaml @@ -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 @@ -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. diff --git a/config/crd/bases/lib.projectsveltos.io_eventsources.yaml b/config/crd/bases/lib.projectsveltos.io_eventsources.yaml index a1352be6..a5060a5d 100644 --- a/config/crd/bases/lib.projectsveltos.io_eventsources.yaml +++ b/config/crd/bases/lib.projectsveltos.io_eventsources.yaml @@ -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: @@ -235,8 +273,6 @@ spec: - version type: object type: array - required: - - resourceSelectors type: object type: object served: true diff --git a/go.mod b/go.mod index dffde1ff..6ea701dd 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/BurntSushi/toml v1.4.0 github.com/Masterminds/sprig/v3 v3.3.0 github.com/chai2010/glua-strings v0.0.0-20200705094630-a37fb1f4ddeb + github.com/cloudevents/sdk-go/v2 v2.15.2 github.com/go-logr/logr v1.4.2 github.com/google/gofuzz v1.2.0 github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf diff --git a/go.sum b/go.sum index 3e0109b6..a2384131 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/chai2010/glua-helper v0.0.0-20171228064744-0e9a290dbcdf h1:83/SiZ9gCO github.com/chai2010/glua-helper v0.0.0-20171228064744-0e9a290dbcdf/go.mod h1:g4T7SP6g4zcVGZu2Xt2l9v+j8WRUKnrSFI13MYeQtD4= github.com/chai2010/glua-strings v0.0.0-20200705094630-a37fb1f4ddeb h1:veL8m2ukpS0WornX1koriByiNIils7J+wB6urWgB18c= github.com/chai2010/glua-strings v0.0.0-20200705094630-a37fb1f4ddeb/go.mod h1:Ujv8AWr5PquFfwTqGV6c8MP+tuG1q7SgYdkZ7umTUsQ= +github.com/cloudevents/sdk-go/v2 v2.15.2 h1:54+I5xQEnI73RBhWHxbI1XJcqOFOVJN85vb41+8mHUc= +github.com/cloudevents/sdk-go/v2 v2.15.2/go.mod h1:lL7kSWAE/V8VI4Wh0jbL2v/jvqsm6tjmaQBSvxcv4uE= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/lib/crd/eventreports.go b/lib/crd/eventreports.go index 66d6bcb1..2c5acafe 100644 --- a/lib/crd/eventreports.go +++ b/lib/crd/eventreports.go @@ -176,6 +176,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 @@ -198,7 +205,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. diff --git a/lib/crd/eventsources.go b/lib/crd/eventsources.go index d5e5ad79..a660a5da 100644 --- a/lib/crd/eventsources.go +++ b/lib/crd/eventsources.go @@ -192,8 +192,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: @@ -253,8 +291,6 @@ spec: - version type: object type: array - required: - - resourceSelectors type: object type: object served: true diff --git a/lib/sveltos_upgrade/sveltos_agent_upgrade.go b/lib/sveltos_upgrade/sveltos_agent_upgrade.go index fadc092d..2dbca3e5 100644 --- a/lib/sveltos_upgrade/sveltos_agent_upgrade.go +++ b/lib/sveltos_upgrade/sveltos_agent_upgrade.go @@ -18,6 +18,7 @@ package sveltos_upgrade import ( "context" + "time" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -63,7 +64,11 @@ const ( func IsSveltosAgentVersionCompatible(ctx context.Context, c client.Client, version string) bool { cm := &corev1.ConfigMap{} - err := c.Get(ctx, types.NamespacedName{Namespace: configMapNamespace, Name: sveltosAgentConfigMapName}, cm) + const timeout = 10 * time.Second + ctxWithTimeout, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + err := c.Get(ctxWithTimeout, types.NamespacedName{Namespace: configMapNamespace, Name: sveltosAgentConfigMapName}, cm) if err != nil { return false } diff --git a/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventreports.lib.projectsveltos.io.yaml b/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventreports.lib.projectsveltos.io.yaml index 2925d1cc..afe1172c 100644 --- a/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventreports.lib.projectsveltos.io.yaml +++ b/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventreports.lib.projectsveltos.io.yaml @@ -157,6 +157,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 @@ -179,7 +186,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. diff --git a/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventsources.lib.projectsveltos.io.yaml b/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventsources.lib.projectsveltos.io.yaml index 0c1dff7f..2402108a 100644 --- a/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventsources.lib.projectsveltos.io.yaml +++ b/manifests/apiextensions.k8s.io_v1_customresourcedefinition_eventsources.lib.projectsveltos.io.yaml @@ -173,8 +173,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: @@ -234,8 +272,6 @@ spec: - version type: object type: array - required: - - resourceSelectors type: object type: object served: true