apiserversource

package
v0.27.5 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Example (Full)
package main

import (
	"os"

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

	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"
)

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

	sinkRef := &duckv1.KReference{
		Kind:       "sinkkind",
		Namespace:  "sinknamespace",
		Name:       "sinkname",
		APIVersion: "sinkversion",
	}

	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, "uri/parts")(cfg)
	apiserversource.WithResources(res1, res2, res3)(cfg)

	files, err := manifest.ExecuteLocalYAML(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 (
	"os"

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

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

	files, err := manifest.ExecuteLocalYAML(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 (WithEventMode)
package main

import (
	"os"

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

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

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

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

	apiserversource.WithEventMode(v1.ReferenceMode)(cfg)

	files, err := manifest.ExecuteLocalYAML(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 (WithResources)
package main

import (
	"os"

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

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

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

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

func main() {
	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.ExecuteLocalYAML(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 (
	"os"

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

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

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

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

	files, err := manifest.ExecuteLocalYAML(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 (
	"os"

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

	duckv1 "knative.dev/pkg/apis/duck/v1"
	"knative.dev/reconciler-test/pkg/manifest"
)

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

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

	files, err := manifest.ExecuteLocalYAML(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 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(ref *duckv1.KReference, uri string) 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