Skip to content

Standard way to add manifests used for implementing the operator (ex: Tekton Pipeline) #6186

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

Closed
VannTen opened this issue Nov 18, 2022 · 12 comments
Assignees
Labels
kind/documentation Categorizes issue or PR as related to documentation. triage/support Indicates an issue that is a support question.
Milestone

Comments

@VannTen
Copy link

VannTen commented Nov 18, 2022

What is the URL of the document?

https://sdk.operatorframework.io/docs/overview/project-layout/

Which section(s) is the issue in?

Common Base, I guess.

What needs fixing?

Precise how to ship resources which are part of the operator implementation.

Additional context

For some context, we're currently working on a operator which use Pipeline (CR provied by Tekton) to implement some parts of its functionality (we create PipelineRun from within the operator code).
The question is, where should those Pipelines lives in our repo ? Is there a standard location ?

The goal would be to be able to use the manifests target to deploy the Pipelines with the rest of the resources composing the operator.

bundle: manifests | $(KUSTOMIZE) ## Generate bundle manifests and metadata, then validate generated files.
	operator-sdk generate kustomize manifests -q
	cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
	$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
	operator-sdk bundle validate ./bundle

I looked through the documentation but didn't find (might be by my mistake) an answer

@VannTen VannTen added the kind/documentation Categorizes issue or PR as related to documentation. label Nov 18, 2022
@everettraven
Copy link
Contributor

@VannTen does your operator depend on Tekton being installed on the cluster? If so, then you shouldn't have to install the CRD as part of your operator installation.

If you are just using the CRD for something custom and it doesn't depend on Tekton being installed on the cluster, then I believe the best place for it would be to add it under the config/crd/ directory in the project.

Under the Common Base section, in the table there is this entry:

|config/crd/ | Contains the Custom Resources Definitions.|

@VannTen
Copy link
Author

VannTen commented Nov 21, 2022 via email

@everettraven
Copy link
Contributor

Ah okay, I think I understand now. Just to check my understanding, you are wanting to create a Pipeline CR as part of your reconciliation loop?

Also a follow up question, what kind of operator is this (Go, Ansible, Helm)?

@VannTen
Copy link
Author

VannTen commented Nov 21, 2022 via email

@varshaprasad96
Copy link
Member

@VannTen If I understand right, the goal is to include an external CR manifest in the operator project and not the definition for the name. manifests target uses KB markers and generates a bunch of manifests with the help of controller-tools. Additionally, when the make build target is called, the yaml files under config/manifests are used by kustomize to build the required files. If you are looking to include these files in the bundle, I would suggest to utilize the --input-dir flag in the operator-sdk generate bundle command (ref: https://sdk.operatorframework.io/docs/cli/operator-sdk_generate_bundle/). This way you can have the external CRs in any location inside config/ (which seems apt for your porject) and specify it in the command to include them in the bundle.

@jberkhahn jberkhahn added the triage/support Indicates an issue that is a support question. label Nov 21, 2022
@jberkhahn jberkhahn added this to the Backlog milestone Nov 21, 2022
@jberkhahn jberkhahn self-assigned this Nov 21, 2022
@jberkhahn
Copy link
Contributor

So, it looks like you're trying to create a single Pipeline object when your operator is installed, and then run stuff against it when an instance of your operator is created?

There (currently) isn't really a good way to include instances of a CR in your operator's bundle via OLM. This is a known issue, and is an feature explicitly being added in Rukpak.

However, if instances of your operator type are going to interact with that resource and do stuff, I'm not sure if statically specifying it is a good idea at all. I think I would include the information you need to instantiate the Pipeline (basically all the stuff it the Pipeline.spec), and check to see if the pipeline exists at the top of your reconciliation loop, and make sure it does there.

@VannTen
Copy link
Author

VannTen commented Nov 22, 2022 via email

@everettraven
Copy link
Contributor

@VannTen,

So basically, embed the definition of the Pipeline into the operator code, right ?

Yep that is the suggestion @jberkhahn is making. The logic for your reconciliation loop would essentially be updated to have the first step be:

  • Create the Pipeline CR if it does not already exist

What reasons make static Pipelines a bad idea ?

I think the problem here with making the Pipeline a static resource that is only applied as part of the installation of the operator is that your operator depends on the existence of that Pipeline resource to work.

If you create it only during the installation of the operator, what happens if someone unaware of what that specific Pipeline resource is for deletes it from the cluster? Having a check at the beginning of your reconciliation loop that says "if the Pipeline resource I depend on does not exist, then create it" helps to make your operator more resilient in a situation like this because you will just recreate it if it is removed, ensuring your operator always has what it needs to run properly.

I hope this helps a bit!

@VannTen
Copy link
Author

VannTen commented Nov 22, 2022 via email

@everettraven
Copy link
Contributor

But how does that differ from removing the operator itself ? (like someone deleting the Deployment which runs the controller, or the RBAC needed for its operation)
IMO, this is the responsibility of the cluster operator, or eventually of OLM.

I believe OLM does handle the case of Deployment or RBAC deletion (just deleting this stuff isn't the proper way to remove an operator). As mentioned by @jberkhahn:

There (currently) isn't really a good way to include instances of a CR in your operator's bundle via OLM. This is a known issue, and is an feature explicitly being added in Rukpak.

Due to this limitation unfortunately this route would likely have to be taken for the time being (and if you wanted to have it created once during operator startup that is an option as well. It is your operator after all).

Alternatively you could begin looking into using Rukpak but it is not a direct replacement to OLM. I would recommend really weighing the pros & cons of a switch like this prior to actually switching.

My operator should not have the rights to install itself, don't you think ?

I don't think in this case the operator would be "installing" itself. It would rather be creating the resources that it is dependent on existing in order to operate as expected.

In my opinion, it is your responsibility as the developer of the operator to make clear what happens when the operator is installed on the cluster and it is the responsibility of the cluster admin (or whoever is installing the operator) to have an understanding and accept what will happen on the cluster when they install the operator. This includes what permissions the operator requires and will be created, any dependent resources that are created on the cluster, and what happens when a CR is created and reconciled by the operator.

@VannTen
Copy link
Author

VannTen commented Nov 28, 2022 via email

@jberkhahn
Copy link
Contributor

Thanks. Feel free to reopen this if you do have any further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

4 participants