eventpolicy

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Example (Full)
package main

import (
	"embed"
	"os"

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

	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.WithTo([]v1alpha1.EventPolicySpecTo{
			{
				Ref: &v1alpha1.EventPolicyToReference{
					Name:       "my-broker",
					Kind:       "Broker",
					APIVersion: "eventing.knative.dev/v1",
				},
			},
			{
				Selector: &v1alpha1.EventPolicySelector{
					LabelSelector: &metav1.LabelSelector{
						MatchLabels: map[string]string{
							"matchlabel1": "matchlabelvalue1",
							"matchlabel2": "matchlabelvalue2",
						},
						MatchExpressions: []metav1.LabelSelectorRequirement{
							{
								Key:      "matchlabelselector1",
								Values:   []string{"matchlabelselectorvalue1"},
								Operator: metav1.LabelSelectorOpIn,
							},
						},
					},
					TypeMeta: &metav1.TypeMeta{
						APIVersion: "eventing.knative.dev/v1",
						Kind:       "Broker",
					},
				},
			},
		}...),
		eventpolicy.WithFrom([]v1alpha1.EventPolicySpecFrom{
			{
				Ref: &v1alpha1.EventPolicyFromReference{
					APIVersion: "eventing.knative.dev/v1",
					Name:       "my-broker",
					Kind:       "Broker",
					Namespace:  "my-ns-2",
				},
			},
			{
				Sub: ptr.String("my-sub"),
			},
		}...),
	}

	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
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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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