Source-to-Image for python kopf based operators.
This Python Kopf operator source-to-image can be used to build python-base operators using OpenShift source-to-image or Dockerfile based builds.
This s2i image may also be used with odo
to do in-cluster operator development.
Unless Kopf standalone mode is used, peering between Kopf operators should be enabled. The Kopf peering custom resource definitions are required for peering and can be installed with:
oc apply -f https://raw.githubusercontent.com/redhat-cop/containers-quickstarts/master/build-s2i-python-kopf/peering-crds.yaml
Kopf command line options are configured using environment variables.
The file kopf-opt.sh
may be used to set options at compile time.
These are used to build up the command line for kopf run
.
The following environment variables are supported:
Option | Default | Description |
---|---|---|
|
|
Set to "true" to run kopf with |
|
none |
Namespace for kopf watch. When run in cluster this defaults to the operator pod namespace. |
|
|
Set to "true" to run kopf with |
|
dynamic |
Operator priority in relation to other kopf operators.
The default when running containerized is to base the priority on the pod IP or otherwise |
|
none |
Kopf custom peering using |
|
none |
Command line options for |
Python requirements can be specified in the requirements.txt
file.
These will be processed and installed to the container image during source-to-image build using Python3 pip
.
This source-to-image project supports odo
for in-cluster operator development.
To use this image with odo
you can create an image stream in the openshift
namespace.
This will make python-kopf
appear as a valid project type for odo create
.
oc create -f imagestream.yaml
An OpenShift build template is provided for building this container image.
Create events console build configuration:
oc process --local -f build-template.yaml | oc apply -f -
Then either build the python-kopf-s2i image from git source:
oc start-build python-kopf-s2i
Or build the python-kopf-s2i image from local source:
oc start-build python-kopf-s2i --from-dir=../ -F
To verify the source-to-image base image is functional you will want to build an operator image to verify functionality.
A simple operator example is provided in the examples/
directory.
If testing the source-to-image build in an OpenShift cluster then you may use the example build template provided.
oc process --local -f examples/kopf-simple/build-template.yaml \ -p FROM_IMAGE=$(oc get is python-kopf-s2i -o jsonpath="{.status.tags[?(@.tag=='latest')].items[0].dockerImageReference}") \ | oc apply -f -
Then either build the example operator from git source:
oc start-build kopf-simple -F
Or build the example from local source:
oc start-build kopf-simple --from-dir=../ -F
Description for how to deploy and test this example can be found in Simple Example.
This example image may also be built with the provided Dockerfile
.
The provided configuration builds from the base image quay.io/redhat-cop/python-kopf-s2i:latest
.
In order to test your build of the s2i image you will need a modified version of the Dockerfile
:
sed 's/^FROM .*/FROM python-kopf-s2i:latest/' example/Dockerfile >example/Dockerfile.custom
Build using podman
:
sudo podman build --tag python-kopf-s2i-example:latest -f ./example/Dockerfile.custom
Using docker
:
sudo docker build -t python-kopf-s2i-example:latest -f ./example/Dockerfile.custom example/