Skip to content

Latest commit

 

History

History

notifier

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Sample kubebuilder application - Event Notifier

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

Prerequisites

  1. Kubernetes 1.17+ / Openshift 3.11+
  2. Golang 1.13
  3. Kubebuilder 2.0.0
  4. Kustomize

Install

  1. Deploy a cluster
  1. Install golang
  2. Install kubebuilder

Cloud-native application behavior

Expected behavior

Preparation

# 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:

  1. notifier_types - Location of the v1.Notifier CR structures, helper functions and filters.
  2. 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 our v1.Notifier CR.
  3. event_controller - Our extension for v1.Event behavior, with another controller. Notice usage of predicates, to filter incoming events here
  4. event_predicate - This file is specifically dedicated to filtering incoming events for v1.Event resource, which should trigger our custom event_controller reconciliation run.

Example CR - email.notify.io/v1.Notifier

apiVersion: email.notify.io/v1
kind: Notifier
metadata:
  name: notifier-sample
  namespace: test
spec:
  # Add fields here
  email: [email protected]
  filters:
  - BackOff

Executing the controller's code

Locally

make
make manifests
make install
make run
  • Create a namespace, faulty pod and a Notifier CR from samples by running
oc create -f ./samples

Production

  • 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

Sources