Skip to content

Commit 9c8a77d

Browse files
author
Rajat Chopra
committed
docs/dev: Doc on how to integrate an operator
This document is meant for an operator author, who wants to integrate a second-level operator into the installer. The document is a guide on all the possible and acceptable methods.
1 parent 0284d4e commit 9c8a77d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

docs/dev/operators.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# How to add a new operator to the installer?
2+
3+
This document describes how to provide an operator's configuration files and manifests to installer-launched clusters.
4+
5+
One can classify all the manifest/config files of an operator in two categories:
6+
- Static
7+
- Templatized
8+
9+
The static ones are clearly just byte blobs and the templates are ones that have some variable that needs to be filled up. Typically the variables that need filling up will come from user preferences as specified in the install config (e.g. cluster name, cluster domain, service cidr etc). Other dependencies could be TLS cert keys for example.
10+
11+
## The recommended way
12+
The static and template files of your operator need to be dealt with separately.
13+
14+
### Static files
15+
16+
For static files use the Cluster Version Operator (CVO) payload mechanism. There is a particular way to keep the manifest files so that the CVO update payload can pick it up.
17+
See this document:
18+
19+
https://github.com/openshift/cluster-version-operator/tree/master/docs/dev/operators.md
20+
21+
Also remember that the order of creation of the files is alphabetical, so the files should be numbered like below to effectively create the service account before the deployment.
22+
```
23+
00-namespace.yaml
24+
...
25+
03-roles.yaml
26+
04-serviceaccount.yaml
27+
05-deployment.yaml
28+
```
29+
where, 04/05 is the internal ordering of the resource manifests.
30+
31+
### What to do for the dynamic template files?
32+
33+
An operator should auto-discover the install config rather than expand the templates through the installer integration (see alternative). Simply use the apiserver access to get the install-config as a config map. The config map is stored by the name ‘cluster-config-v1’ in the ‘kube-system’ namespaces.
34+
Pseudo code:
35+
```
36+
kube-client(apiserver-url).Get(Resource: "config-map", Namespace: "kube-system", Name: "cluster-config-v1")
37+
```
38+
where, apiserver-url is a cluster supplied ENV var ‘KUBERNETES_SERVICE_HOST’ in the pod.
39+
Example:
40+
41+
https://github.com/openshift/machine-config-operator/blob/e932afdec07dc86d5b643590164f86811e205c57/pkg/operator/operator.go#L272
42+
43+
After discovering the InstallConfig, the operator pod can do two things:
44+
45+
- create its own configuration in memory as users should not be editing it
46+
- or, push the discovered config to an API as the operator's users might want to change it in the future
47+
48+
See an example of the configuration for the operator being discovered rather than from a configmap:
49+
50+
https://github.com/openshift/machine-config-operator/blob/31c20eefca172d5c1173e7b79b30bad540958dfe/pkg/operator/render.go#L46
51+
52+
## The alternative (for exceptions only)
53+
54+
Creating a new asset in the installer source is only for exceptional cases where CVO cannot take all the required manifests/config files, and auto-discover is not possible or insufficient e.g. the network operator. As another example, the machine-config-operator needs TLS config.
55+
56+
Such operators need to be directly integrated in the installer's [`manifests` package](../../pkg/asset/manifests). Within this, there are two ways to get the manifests/config files integrated:
57+
58+
- A new asset for the operator
59+
Create a new operator asset, and render the Dependencies, Name, Load and Generate functions. The Dependencies might contain InstallConfig as an example. In the Generate function, create the config files as asset contents. For the config/manifest’s actual structure, one can choose to vendor the operator’s github pkg, or, if the configuration structures are fairly simple then just copy the definitions directly and avoid the hassle of vendoring. Finally, return the entire list of configs and manifests in the Generate function.
60+
61+
- Template files
62+
In the pkg/asset/manifests/content/tectonic directory, place the templates golang variables. Then modify pkg/asset/manifests/tectonic.go to expand the template. Expand templateData in template.go for filling up the template variables.

0 commit comments

Comments
 (0)