eventpolicy

package
v0.43.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Example (Full)
package main

import (
	"embed"
	"os"

	eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
	"knative.dev/eventing/test/rekt/resources/broker"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"knative.dev/eventing/test/rekt/resources/eventpolicy"

	testlog "knative.dev/reconciler-test/pkg/logging"
	"knative.dev/reconciler-test/pkg/manifest"
)

//go:embed *.yaml
var yaml embed.FS

func main() {
	ctx := testlog.NewContext()
	images := map[string]string{}
	cfg := map[string]interface{}{
		"name":      "foo",
		"namespace": "bar",
	}

	cfgFn := []manifest.CfgFn{
		eventpolicy.WithToRef(
			broker.GVR().GroupVersion().WithKind("Broker"),
			"my-broker"),
		eventpolicy.WithToSelector(
			broker.GVR().GroupVersion().WithKind("Broker"),
			&metav1.LabelSelector{
				MatchLabels: map[string]string{
					"matchlabel1": "matchlabelvalue1",
					"matchlabel2": "matchlabelvalue2",
				},
				MatchExpressions: []metav1.LabelSelectorRequirement{
					{
						Key:      "matchlabelselector1",
						Values:   []string{"matchlabelselectorvalue1"},
						Operator: metav1.LabelSelectorOpIn,
					},
				},
			}),
		eventpolicy.WithFromRef(
			broker.GVR().GroupVersion().WithKind("Broker"),
			"my-broker",
			"my-ns-2",
		),
		eventpolicy.WithFromSubject("my-sub"),
		eventpolicy.WithFilters([]eventingv1.SubscriptionsAPIFilter{
			{
				CESQL: "type LIKE event.%.type",
			},
		}),
	}

	for _, fn := range cfgFn {
		fn(cfg)
	}

	files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)
	if err != nil {
		panic(err)
	}

	manifest.OutputYAML(os.Stdout, files)
}
Output:

apiVersion: eventing.knative.dev/v1alpha1
kind: EventPolicy
metadata:
  name: foo
  namespace: bar
spec:
  to:
    - ref:
        apiVersion: eventing.knative.dev/v1
        kind: Broker
        name: my-broker
    - selector:
        apiVersion: eventing.knative.dev/v1
        kind: Broker
        matchLabels:
          matchlabel1: matchlabelvalue1
          matchlabel2: matchlabelvalue2
        matchExpressions:
          - key: matchlabelselector1
            operator: In
            values:
            - matchlabelselectorvalue1
  from:
    - ref:
        apiVersion: eventing.knative.dev/v1
        kind: Broker
        name: my-broker
        namespace: my-ns-2
    - sub: my-sub
  filters:
    - cesql: type LIKE event.%.type
Example (Min)

The following examples validate the processing of the With* helper methods applied to config and go template parser.

package main

import (
	"embed"
	"os"

	testlog "knative.dev/reconciler-test/pkg/logging"
	"knative.dev/reconciler-test/pkg/manifest"
)

//go:embed *.yaml
var yaml embed.FS

func main() {
	ctx := testlog.NewContext()
	images := map[string]string{}
	cfg := map[string]interface{}{
		"name":      "foo",
		"namespace": "bar",
		"from": []map[string]interface{}{
			{
				"ref": map[string]string{
					"kind":       "Broker",
					"name":       "my-broker",
					"namespace":  "my-ns",
					"apiVersion": "eventing.knative.dev/v1",
				},
			},
		},
	}

	files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)
	if err != nil {
		panic(err)
	}

	manifest.OutputYAML(os.Stdout, files)
}
Output:

apiVersion: eventing.knative.dev/v1alpha1
kind: EventPolicy
metadata:
  name: foo
  namespace: bar
spec:
  from:
    - ref:
        apiVersion: eventing.knative.dev/v1
        kind: Broker
        name: my-broker
        namespace: my-ns

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GVR

func Install

func Install(name string, opts ...manifest.CfgFn) feature.StepFn

Install will create an EventPolicy resource, augmented with the config fn options.

func IsReady

func IsReady(name string, timing ...time.Duration) feature.StepFn

IsReady tests to see if an EventPolicy becomes ready within the time given.

func WithFilters added in v0.43.0

func WithFilters(filters []eventingv1.SubscriptionsAPIFilter) manifest.CfgFn

func WithFromRef added in v0.43.0

func WithFromRef(gvk schema.GroupVersionKind, name, namespace string) manifest.CfgFn

func WithFromSubject added in v0.43.0

func WithFromSubject(subject string) manifest.CfgFn

func WithToRef added in v0.43.0

func WithToRef(gvk schema.GroupVersionKind, name string) manifest.CfgFn

func WithToSelector added in v0.43.0

func WithToSelector(gvk schema.GroupVersionKind, labelSelector *metav1.LabelSelector) manifest.CfgFn

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL