abstract-operator

Build status License

{CRD|ConfigMap}-based approach for lyfecycle management of various resources in Kubernetes and OpenShift. Using the Operator pattern, you can leverage the Kubernetes control loop and react on various events in the cluster. The idea of the operator patern is to encapsulate the operational knowledge into the abovementioned control loop and declarative approach.

Example Implementations

Code

This library can be simply used by adding it to classpath; creating a new class that extends AbstractOperator. This 'concrete operator' class needs to also have the @Operator annotation on it. For capturing the information about the monitored resources one has to also create a class that extends EntityInfo and have arbitrary fields on it with getters and setters.

This class can be also generated from the JSON schema. To do that add jsonschema2pojo plugin to the pom.xml and json schema to resources (example).

This is a no-op operator in Scala that simply logs into console when config map with label radanalytics.io/kind = foo is created.

@Operator(forKind = "foo", prefix = "radanalytics.io", infoClass = classOf[FooInfo])
class FooOperator extends AbstractOperator[FooInfo] {
  val log: Logger = LoggerFactory.getLogger(classOf[FooInfo].getName)

  @Override
  def onAdd(foo: FooInfo) = {
    log.info(s"created foo with name ${foo.name} and someParameter = ${foo.someParameter}")
  }

  @Override
  def onDelete(foo: FooInfo) = {
    log.info(s"deleted foo with name ${foo.name} and someParameter = ${foo.someParameter}")
  }
}

CRDs

By default the operator is based on CustomResources, if you want to create ConfigMap-based operator, add crd=false parameter in the @Operator annotation. The CRD mode will try to create the custom resource definition from the infoClass if it's not already there and then it listens on the newly created, deleted or modified custom resources (CR) of the given type.

For the CRDs the:

Configuration

You can configure the operator using some environmental variables. Here is the list:

Documentation

javadoc