Sample kubebuilder cloud-native app, which sends email notifications on pod failure (sort of).
This is done by using existing tools provided by kubebuilder
framework, via extending existing Kubernetes object behavior - v1.Event
, and creating our own Custom Resource (CR)
- named Notifier
- Kubernetes 1.17+ / Openshift 3.11+
- Golang 1.13
- Kubebuilder 2.0.0
- Kustomize
- Deploy a cluster
- oc cluster up (openshift)
- Minikube
# Create initial project structure
kubebuilder init --domain email.notify.io --license apache2
# Scaffold our v1.Notifier CR
# Responding yes on both controller and resource creation
kubebuilder create api --group email --version v1 --kind Notifier
# Extending existing v1.Event kubernetes resource with our controller
# From provided options select only the controller scaffolding, as the resource will be already present
kubebuilder create api --group core --version v1 --kind Event
There are several places, where the code for this workshop will be edited. For better orientation here is an overview:
- notifier_types - Location of the
v1.Notifier
CR structures, helper functions and filters. - notifier_controller - Specifically
Reconcile
function, is the place where the controller logic is located at. This part will be executed every time any of:Create
|Update
|Delete
|Generic
events are captured by the controller, related to ourv1.Notifier
CR
. - event_controller - Our extension for
v1.Event
behavior, with another controller. Notice usage of predicates, to filter incoming events here - event_predicate - This file is specifically dedicated to filtering incoming events for
v1.Event
resource, which should trigger our custom event_controller reconciliation run.
apiVersion: email.notify.io/v1
kind: Notifier
metadata:
name: notifier-sample
namespace: test
spec:
# Add fields here
email: [email protected]
filters:
- BackOff
make
make manifests
make install
make run
- Create a namespace, faulty pod and a
Notifier
CR from samples by running
oc create -f ./samples
- First you will need to edit container image url, where the final application will be published, then later on pulled and used in production - here
- Same thing for the
Makefile
- here - Then:
make
make manifests
make install
make docker-build
make docker-push
make deploy
- Create a namespace, faulty pod and a
Notifier
CR from samples by running
oc create -f ./samples