Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New doc on how to integrate an operator #377

Merged
merged 1 commit into from
Oct 10, 2018

Conversation

rajatchopra
Copy link

@rajatchopra rajatchopra commented Sep 28, 2018

A document to help an operator developer to integrate the operator with the installer. It covers what files to keep where so that configurations can be properly generated.

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 28, 2018
Upshot of the above document is that the operator should keep its static manifest files in manifests/ folder of the operator repository and manage image references through an image-references file. 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.
:
```
0000_70_my-operator-name_04_service-account.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not recommended. Only special operators require this.
cc @smarterclayton

The files should be <internal order>_<name>.yaml like here https://github.com/openshift/machine-config-operator/tree/master/install

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

00-namaspace.yaml
...
03-roles.yaml
04-serviceaccount.yaml
05-deplopment.yaml

Take the static files and ready it for the Cluster Version Operator (CVO) to pick it up as its payload. See this document:
https://docs.google.com/document/d/1CGZVEyuloZ9oD4NUArW6dnEpi0WFc6BP2tqPSwFZTCY/edit#heading=h.1zgrwxmpgxbr

Upshot of the above document is that the operator should keep its static manifest files in manifests/ folder of the operator repository and manage image references through an image-references file. 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upshot of the above document is that the operator should keep its static manifest files in manifests/ folder of the operator repository and manage image references through an image-references file.

The document above requires more than keeping in /manifests of the repo. I would recommend not duplicate here.

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.

ClusterVersionOperator applies the manifests to cluster in alphabetical order. So it is recommended that manifests be order of dependencies.
For example,

  • a deployment requires service account, roles etc and,
  • everything requires the namespace to exist.

So the order of the manifests should be enforces like:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document above requires more than keeping in /manifests of the repo. I would recommend not duplicate here.

Agreed on not duplicating here. And any references to this that we keep should talk about the operator images; the operator Git repository doesn't come into it.

But if we punt this portion of the docs to external docs (whether in a Google Doc or github.com/openshift/cluster-version-operator Markdown), what's left to talk about here? Just:

Almost everyone should use external docs. {details about when that won't work}. {where to put things when you add them to this repo}.

Upshot of the above document is that the operator should keep its static manifest files in manifests/ folder of the operator repository and manage image references through an image-references file. 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.
:
```
0000_70_my-operator-name_04_service-account.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

00-namaspace.yaml
...
03-roles.yaml
04-serviceaccount.yaml
05-deplopment.yaml

0000_70_my-operator-name_04_service-account.yaml
0000_70_my-operator-name_05_deployment.yaml
```
where, 0000 is the global run-level, 70 is the operator level, and 04/05 is the internal ordering of the resource manifests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this. not required for most operators other than internal ordering.

Example:
https://github.com/openshift/machine-config-operator/blob/e932afdec07dc86d5b643590164f86811e205c57/pkg/operator/operator.go#L272

After discovering the InstallConfig, the operator pod can create its own configuration in memory. e.g. the discoverMCOConfig returns the configuration for the operator as it is discovered rather than picking it up from an actual configmap.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • either keep it in memory as users shouldn't be editing it.
  • push the discovered config to api, as users might change this in future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinavdahiya do you have an example of 'push the discovered config to api, as users might change this in future'?

@openshift-ci-robot
Copy link
Contributor

@rajatchopra: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws 4f66f9763ee71ea9cbabc3f0dc1edf8757f29727 link /test e2e-aws

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Member

@wking wking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits inline, take 'em if they sound useful ;).

More broadly, I'm not clear on how this is scoped vs. the Google Doc, and I feel like the CVO repository is feeling lonely and left-out. @smarterclayton, can you provide more details about where you see these docs being maintained long-term? If it's in multiple locations, I think we need clear scoping about what goes where so we can give good cross-links to guide newcomers between locations.

@@ -0,0 +1,53 @@
## How to add a new operator to the installer?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The page title should be h1 (one #), and subsections should increment by one level. It's not our fault if we think GitHub styles them too big ;).

Also, do we expect other levels of operator docs besides this? It seems unlikely to me, in which case I'd prefer docs/dev/operators.md and

# Operator integration

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h1 is indeed to big for a smallish document like this one. Too bad if someone is forced into a telescopic lens. Can I stick with h2/h4?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Headings should not be used for styling. That's what CSS is for. Just stick to the standard hierarchy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.
Convinced? No.
Complied? Yes.

docs/dev/integrate_operator_how_to.md Outdated Show resolved Hide resolved
docs/dev/integrate_operator_how_to.md Outdated Show resolved Hide resolved
docs/dev/integrate_operator_how_to.md Outdated Show resolved Hide resolved
docs/dev/integrate_operator_how_to.md Outdated Show resolved Hide resolved
Take the static files and ready it for the Cluster Version Operator (CVO) to pick it up as its payload. See this document:
https://docs.google.com/document/d/1CGZVEyuloZ9oD4NUArW6dnEpi0WFc6BP2tqPSwFZTCY/edit#heading=h.1zgrwxmpgxbr

Upshot of the above document is that the operator should keep its static manifest files in manifests/ folder of the operator repository and manage image references through an image-references file. 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document above requires more than keeping in /manifests of the repo. I would recommend not duplicate here.

Agreed on not duplicating here. And any references to this that we keep should talk about the operator images; the operator Git repository doesn't come into it.

But if we punt this portion of the docs to external docs (whether in a Google Doc or github.com/openshift/cluster-version-operator Markdown), what's left to talk about here? Just:

Almost everyone should use external docs. {details about when that won't work}. {where to put things when you add them to this repo}.


*What to do for my dynamic template files?*

An operator should auto-discover the install config rather than expand the templates through the installer-src 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.
Copy link
Member

@wking wking Sep 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth spending a bit more time (wherever these "standard approach" docs live), talking about how this wires in. As I understand it, you'd take the /manifests route with enough static content to get your operator launched, and then you pull everything else you need (e.g. the install config) live from well-known locations. You focus on the last part of that here, and the Google Doc focuses on the first part. I don't see anywhere that's tying them together, although the MCO link you have below probably gives a good example for folks who want to read the source ;).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done a bit of a shift up to tie the two methods (one for static, the other for templates). Review again please.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done a bit of a shift up to tie the two methods (one for static, the other for templates).

This paragraph looks largely unchanged from 4f66f97 -> 2650b11. I was thinking of an outline more like:

The recommended way

...Everyone following this integration path will need static manifests/configs (as discussed in the Google Doc) to launch their operator...

Dynamic configuration

Some operators will need dynamic configuration to accomplish their task. These operators should set up their static manifests/configs to launch their operator, and then have their operator fill in its configuration by pulling information from cluster resources. For example, you can pull the install-config as a config map:

...

docs/dev/integrate_operator_how_to.md Outdated Show resolved Hide resolved
docs/dev/integrate_operator_how_to.md Outdated Show resolved Hide resolved
Create a new operator asset, and fill up the Dependencies, Name 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 and return the entire list of configs and manifests in the Generate function.

- Template files
In the pkg/asset/manifests/content/tectonic directory, place the templatized files as golang variables. Then modify pkg/asset/manifests/tectonic.go to expand the template. Expand templateData in template.go for filling up the template variables.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "templateized files" -> "templates"?

And including the paths and variable names here seems brittle. But it's probably fine until we have commits we can link to showing good examples of adding a new operator so folks can pattern-match.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.
Agree on the paths and variable names. Will be intractable at some point.

@rajatchopra rajatchopra force-pushed the patch-1 branch 5 times, most recently from 2c6f306 to 2650b11 Compare October 3, 2018 00:05
@abhinavdahiya
Copy link
Contributor

/approve

@wking wking dismissed abhinavdahiya’s stale review October 3, 2018 20:12

He's approved this PR since: #377 (comment)

@wking
Copy link
Member

wking commented Oct 3, 2018

Can this be docs/dev/operators.md? Also, is the Google Doc public?

@rajatchopra
Copy link
Author

Can this be docs/dev/operators.md? Also, is the Google Doc public?

Renamed the file.
The doc is not public, but I guess the answer is have a PR in CVO repo with the contents of those docs.

@wking
Copy link
Member

wking commented Oct 3, 2018

The doc is not public, but I guess the answer is have a PR in CVO repo with the contents of those docs

@smarterclayton, would that be ok with you? If not, do we have a plan for public integration docs for "The recommended way"?

@rajatchopra
Copy link
Author

The doc is not public, but I guess the answer is have a PR in CVO repo with the contents of those docs

@smarterclayton, would that be ok with you? If not, do we have a plan for public integration docs for "The recommended way"?

Quick link to the doc in question here: https://docs.google.com/document/d/1CGZVEyuloZ9oD4NUArW6dnEpi0WFc6BP2tqPSwFZTCY/

@smarterclayton
Copy link
Contributor

smarterclayton commented Oct 4, 2018 via email

@rajatchopra
Copy link
Author

@wking PTAL: openshift/cluster-version-operator#34

Copy link
Contributor

@steveej steveej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions and language nits in the comments. Another one would be to use render instead of fill up to describe the temple process.

## The recommended way
The static and template files of your operator need to be dealt with separately.

*Static files*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a ### headline here?

```
where, 04/05 is the internal ordering of the resource manifests.

*What to do for the dynamic template files?*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a ### headline here?

*What to do for the dynamic template files?*

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.
Psuedo code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ue/eu/

After discovering the InstallConfig, the operator pod can do two things:

- create its own configuration in memory as users should not be editing it
- or, push the discovered config to an API as the operators users might want to change it in the future
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/operators/operator's/

- create its own configuration in memory as users should not be editing it
- or, push the discovered config to an API as the operators users might want to change it in the future

See example of the configuration for the operator being discovered rather than from a configmap:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/example/an example/

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:

- A new asset for the operator
Create a new operator asset, and fill up 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 and return the entire list of configs and manifests in the Generate function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the actual choice here in the last sentence, i.e. what's the alternative to "vendor the operator’s github pkg and return the entire list of configs and manifests in the Generate function"?


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.
```
00-namaspace.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namaste or namespace ?

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.
See this document:

https://docs.google.com/document/d/1CGZVEyuloZ9oD4NUArW6dnEpi0WFc6BP2tqPSwFZTCY/edit#heading=h.1zgrwxmpgxbr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this reference, and possibly the whole recommended-way section, with a link to here now that openshift/cluster-version-operator#34 has landed.

@rajatchopra rajatchopra force-pushed the patch-1 branch 2 times, most recently from c734231 to 4f8e7ac Compare October 10, 2018 23:02
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.
@abhinavdahiya
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 10, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinavdahiya, rajatchopra

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [abhinavdahiya,rajatchopra]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 42f7541 into openshift:master Oct 10, 2018
@rajatchopra rajatchopra deleted the patch-1 branch October 11, 2018 20:11
wking added a commit to wking/cluster-version-operator that referenced this pull request Nov 27, 2018
This content is descended from openshift/installer@9c8a77dd (docs/dev:
Doc on how to integrate an operator, 2018-09-28,
openshift/installer#377), but handling dynamic configuration is a
generic issue, so the docs should live in the generic CVO repository.
This will make these docs more discoverable.  It will also allow the
installer docs to focus on installer-specific issues for the small
subset of operators that need direct installer bindings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants