apiserversource

package
v0.38.5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Example (Full)
package main

import (
	"embed"
	"os"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"knative.dev/pkg/apis"

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

	v1 "knative.dev/eventing/pkg/apis/sources/v1"

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	duckv1 "knative.dev/pkg/apis/duck/v1"
	"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",
	}

	sinkRef := &duckv1.Destination{
		Ref: &duckv1.KReference{
			Kind:       "sinkkind",
			Namespace:  "sinknamespace",
			Name:       "sinkname",
			APIVersion: "sinkversion",
		},
		URI: &apis.URL{Path: "uri/parts"},
	}

	res1 := v1.APIVersionKindSelector{
		APIVersion:    "res1apiVersion",
		Kind:          "res1kind",
		LabelSelector: nil,
	}

	res2 := v1.APIVersionKindSelector{
		APIVersion: "res2apiVersion",
		Kind:       "res2kind",
		LabelSelector: &metav1.LabelSelector{
			MatchLabels:      map[string]string{"foo": "bar"},
			MatchExpressions: nil,
		},
	}

	res3 := v1.APIVersionKindSelector{
		APIVersion: "res3apiVersion",
		Kind:       "res3kind",
		LabelSelector: &metav1.LabelSelector{
			MatchLabels: map[string]string{"foo": "bar"},
			MatchExpressions: []metav1.LabelSelectorRequirement{{
				Key:      "daf",
				Operator: "uk",
				Values:   []string{"a", "b"},
			}},
		},
	}

	apiserversource.WithServiceAccountName("src-sa")(cfg)
	apiserversource.WithEventMode(v1.ReferenceMode)(cfg)
	apiserversource.WithSink(sinkRef)(cfg)
	apiserversource.WithResources(res1, res2, res3)(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  serviceAccountName: src-sa
  mode: Reference
  resources:
    - apiVersion: res1apiVersion
      kind: res1kind
    - apiVersion: res2apiVersion
      kind: res2kind
      selector:
        matchLabels:
          foo: bar
    - apiVersion: res3apiVersion
      kind: res3kind
      selector:
        matchLabels:
          foo: bar
        matchExpressions:
          - key: daf
            operator: uk
            values:
              - a
              - b
  sink:
    ref:
      kind: sinkkind
      namespace: sinknamespace
      name: sinkname
      apiVersion: sinkversion
    uri: uri/parts
Example (Min)
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",
	}

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
Example (WithEmptyNamespaceSelector)
package main

import (
	"embed"
	"os"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	"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",
	}

	apiserversource.WithNamespaceSelector(&metav1.LabelSelector{
		MatchLabels:      map[string]string{},
		MatchExpressions: []metav1.LabelSelectorRequirement{},
	})(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  namespaceSelector:
    matchLabels:
    matchExpressions:
Example (WithEventMode)
package main

import (
	"embed"
	"os"

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

	v1 "knative.dev/eventing/pkg/apis/sources/v1"

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	"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",
	}

	apiserversource.WithEventMode(v1.ReferenceMode)(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  mode: Reference
Example (WithNamespaceSelector)
package main

import (
	"embed"
	"os"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	"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",
	}

	apiserversource.WithNamespaceSelector(&metav1.LabelSelector{
		MatchLabels: map[string]string{"env": "development"},
		MatchExpressions: []metav1.LabelSelectorRequirement{{
			Key:      "daf",
			Operator: "uk",
			Values:   []string{"a", "b"},
		}},
	})(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  namespaceSelector:
    matchLabels:
      env: development
    matchExpressions:
      - key: daf
        operator: uk
        values:
          - a
          - b
Example (WithResources)
package main

import (
	"embed"
	"os"

	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

	v1 "knative.dev/eventing/pkg/apis/sources/v1"

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	"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",
	}

	res1 := v1.APIVersionKindSelector{
		APIVersion:    "res1apiVersion",
		Kind:          "res1kind",
		LabelSelector: nil,
	}

	res2 := v1.APIVersionKindSelector{
		APIVersion: "res2apiVersion",
		Kind:       "res2kind",
		LabelSelector: &metav1.LabelSelector{
			MatchLabels:      map[string]string{"foo": "bar"},
			MatchExpressions: nil,
		},
	}

	res3 := v1.APIVersionKindSelector{
		APIVersion: "res3apiVersion",
		Kind:       "res3kind",
		LabelSelector: &metav1.LabelSelector{
			MatchLabels: map[string]string{"foo": "bar"},
			MatchExpressions: []metav1.LabelSelectorRequirement{{
				Key:      "daf",
				Operator: "uk",
				Values:   []string{"a", "b"},
			}},
		},
	}

	apiserversource.WithResources(res1, res2, res3)(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  resources:
    - apiVersion: res1apiVersion
      kind: res1kind
    - apiVersion: res2apiVersion
      kind: res2kind
      selector:
        matchLabels:
          foo: bar
    - apiVersion: res3apiVersion
      kind: res3kind
      selector:
        matchLabels:
          foo: bar
        matchExpressions:
          - key: daf
            operator: uk
            values:
              - a
              - b
Example (WithServiceAccountName)
package main

import (
	"embed"
	"os"

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

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	"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",
	}

	apiserversource.WithServiceAccountName("src-sa")(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  serviceAccountName: src-sa
Example (WithSink)
package main

import (
	"embed"
	"os"

	"knative.dev/pkg/apis"

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

	"knative.dev/eventing/test/rekt/resources/apiserversource"

	duckv1 "knative.dev/pkg/apis/duck/v1"
	"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",
	}

	sinkRef := &duckv1.Destination{
		Ref: &duckv1.KReference{
			Kind:       "sinkkind",
			Namespace:  "sinknamespace",
			Name:       "sinkname",
			APIVersion: "sinkversion",
		},
		URI: &apis.URL{Path: "uri/parts"},
	}
	apiserversource.WithSink(sinkRef)(cfg)

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

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

apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
  name: foo
  namespace: bar
spec:
  sink:
    ref:
      kind: sinkkind
      namespace: sinknamespace
      name: sinkname
      apiVersion: sinkversion
    uri: uri/parts

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 returns a step function which creates an ApiServerSource resource, augmented with the config fn options.

func InstallLocalYaml

func InstallLocalYaml(ctx context.Context, name string, opts ...manifest.CfgFn) (manifest.Manifest, error)

InstallLocalYaml will create a ApiServerSource resource, augmented with the config fn options.

func IsReady

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

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

func WithEventMode

func WithEventMode(eventMode string) manifest.CfgFn

WithEventMode sets the event mode on the ApiServerSource spec.

func WithNamespaceSelector added in v0.36.0

func WithNamespaceSelector(selector *metav1.LabelSelector) manifest.CfgFn

WithNamespaceSelector adds a namespace selector to an ApiServerSource spec.

func WithResources

func WithResources(resources ...v1.APIVersionKindSelector) manifest.CfgFn

WithResources adds the resources related config to a ApiServerSource spec.

func WithServiceAccountName

func WithServiceAccountName(serviceAccountName string) manifest.CfgFn

WithServiceAccountName sets the service account name on the ApiServerSource spec.

func WithSink

func WithSink(d *duckv1.Destination) manifest.CfgFn

WithSink adds the sink related config to a ApiServerSource spec.

Types

This section is empty.

Jump to

Keyboard shortcuts

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