4 | 8 | abstract-operator 9 |
10 | 19 |{ConfigMap|CRD}
-based approach for lyfecycle management of various resources in Kubernetes and
20 | OpenShift. Using the Operator pattern, you can leverage the Kubernetes control loop and react on various events
21 | in the cluster.
23 | 27 | Example Implementations 28 |
29 |-
30 |
- spark-operator - Java operator for managing 31 | Apache Spark clusters and apps 32 | 33 |
- scala-example-operator - Minimalistic 34 | operator in Scala 35 | 36 |
- kotlin-example-operator - 37 | Minimalistic operator in Kotlin 38 | 39 |
41 | 45 | Code 46 |
47 |This library can be simply used by adding it to classpath; creating a new class that extends AbstractOperator
.
48 | This 'concrete operator' class needs to also have the @Operator
annotation on it. For capturing the
49 | information about the monitored resources one has to also create a class that extends EntityInfo
50 | 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 53 | plugin to the pom.xml and json schema to resources (example). 55 |
56 |This is a no-op operator in Scala that simply logs into console when config map with label radanalytics.io/kind
57 | = foo
is created.
@Operator(forKind = "foo", prefix = "radanalytics.io", infoClass = classOf[FooInfo])
63 | class FooOperator extends AbstractOperator[FooInfo] {
65 | val log: Logger = LoggerFactory.getLogger(classOf[FooInfo].getName)
68 |
69 | @Override
70 | def onAdd(foo: FooInfo) = {
72 | log.info(s"created foo with name ${foo.name} and someParameter = ${foo.someParameter}")
74 | }
75 |
76 | @Override
77 | def onDelete(foo: FooInfo) = {
79 | log.info(s"deleted foo with name ${foo.name} and someParameter = ${foo.someParameter}")
81 | }
82 | }
83 | 85 | 89 | CRDs 90 |
91 |By default the operator is based on CustomResourceDefinitions
, if you want to create ConfigMap
-based
92 | operator, add crd=false
parameter in the @Operator
annotation. Custom Resource operation mode will try to create
93 | the custom resource definition from the infoClass
if it's not already there and then it listens on
94 | the newly created, deleted or modified custom resources (CR) of the given type.
For the CRDs the:
96 |-
97 |
forKind
field represent the name of theCRD
('s' at the end for plular)
98 | pluralName
explicitly se the plural name of the CR
99 | prefix
field in the annotation represents the group
100 | shortNames
short names that can be used instead of the long version (service -> svc, namespace -> ns, etc.)
101 | enabled
by default it's enabled, but one may want to temporarily disable/silence the operator
102 | - as for the version, currently the
v1
is created automatically, but one can also create the 103 |CRD
on his own before running the operator and providing theforKind
andprefix
104 | matches, operator will use the existingCRD
105 |