ApiServerSource reference
This topic provides reference information about the configurable fields for the ApiServerSource object.
An ApiServerSource definition supports the following fields:
The resources
parameter specifies the resources that the source tracks so that it can send related lifecycle events from the Kubernetes ApiServer. The parameter includes an optional label selector to help filter.
A resources
definition supports the following fields:
Example: Resources parameter
Given the following YAML, the ApiServerSource object receives events for all Pods and Deployments in the namespace:
Example: Resources parameter using matchExpressions
Given the following YAML, ApiServerSource object receives events for all Pods in the namespace that have a label app=myapp
or app=yourapp
:
apiVersion: sources.knative.dev/v1
metadata:
name: <apiserversource>
namespace: <namespace>
spec:
# ...
resources:
- apiVersion: v1
kind: Pod
selector:
matchExpressions:
- key: app
operator: In
values:
- myapp
- yourapp
Example: Resources parameter using matchLabels
kind: ApiServerSource
metadata:
name: <apiserversource>
namespace: <namespace>
spec:
# ...
resources:
- apiVersion: v1
kind: Pod
selector:
matchLabels:
app: myapp
ServiceAccountName is a reference to a Kubernetes service account.
To track the lifecycle events of the specified , you must assign the proper permissions to the ApiServerSource object.
Example: tracking Pods
The following YAML files create a ServiceAccount, Role and RoleBinding and grant the permission to get, list and watch Pod resources in the namespace apiserversource-example
for the ApiServerSource.
Example ServiceAccount:
Example Role with permission to get, list and watch Pod resources:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: test-role
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- watch
Example RoleBinding:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: test-role
subjects:
- kind: ServiceAccount
name: test-service-account
namespace: apiserversource-example
ResourceOwner is an additional filter to only track resources that are owned by a specific resource type. If ResourceOwner matches Resources[n] then Resources[n] is allowed to pass the ResourceOwner filter.
An owner
definition supports the following fields:
Example: Owner parameter
apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
name: <apiserversource>
namespace: <namespace>
spec:
...
owner:
apiVersion: apps/v1
kind: Deployment
...
CloudEvent Overrides defines overrides to control the output format and modifications of the event sent to the sink.
A ceOverrides
definition supports the following fields:
Note
Only valid CloudEvent attribute names are allowed as extensions. You cannot set the spec defined attributes from the extensions override configuration. For example, you can not modify the type
attribute.
Example: CloudEvent Overrides
apiVersion: sources.knative.dev/v1
kind: ApiServerSource
metadata:
name: <apiserversource>
namespace: <namespace>
spec:
...
ceOverrides:
extensions:
This results in the K_CE_OVERRIDES
environment variable being set on the sink container as follows: