openshift / console-plugin-template

Minimal template for writing OpenShift console plugins
Apache License 2.0
39 stars 51 forks source link

Recommended pattern for bundling a plugin into an Operator #20

Closed RyanMillerC closed 8 months ago

RyanMillerC commented 1 year ago

Is there a recommended pattern to bundle a dynamic console plugin into a Go-based operator?

spadgett commented 1 year ago

We don't have an example for this today, although it's something we should look at adding since operators are a common way to deliver plugins.

If your operator already creates a service on the cluster, it's possible to use http.FileServer to serve the static plugin assets. Otherwise, you could add a sidecar container using any HTTP server like nginx or caddy. If your operator adds an console.openshift.io/plugins annotation to its CSV, console will prompt to enable the plugin on operator install. There's an example of the annotation in the enhancement here: https://github.com/openshift/enhancements/blob/master/enhancements/console/dynamic-plugins.md#delivering-plugins

Hope this helps.

cc @jhadvig @alimobrem

RyanMillerC commented 1 year ago

Thanks @spadgett, this helps! I'm close but not 100% there yet. If I can get it working I will gladly contribute an example using an Operator. 😃

I went the Nginx route and have generated a container image for my console plugin. In my operator's ./config/manifests/bases/ directory I've included a Deployment (using the nginx image), Service, and ConsolePlugin. When I run make bundle, only the Deployment and Service are generated under ./bundle/manifests.

If I deploy the bundle (without ConsolePlugin), manually add the ConsolePlugin, and enable it, everything works great! I need to figure out why make bundle isn't including that manifest... This could be simply my lack of knowledge around the Operator SDK.

Another question I have is around namespaces. At the moment I have hardcoded the namespace in my ConsolePlugin. If someone installs the operator into a different namespace, the ConsolePlugin won't match. Is there a way around that?

# Example spec from my ConsolePlugin
spec:
  service:
    name: cat-facts-console-plugin
    namespace: cat-facts-operator
RyanMillerC commented 1 year ago

The code needs cleaned up but I managed to get something working: console.go. Instead of supplying manifests through the OLM bundle, I'm creating the Deployment, Service, and ConsolePlugin in my controller's Go code. I'm calling that code in main.go before starting the reconcile loop on my controller. Not 100% if that is the best place to do it but it does work.

Two improvements I need to make:

openshift-bot commented 1 year ago

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

RyanMillerC commented 1 year ago

/remove-lifecycle stale

I'd like to add a reference link to my example operator from this repo's README. I should probably get my repo moved out from under my GitHub user first though. I'm thinking of moving it under redhat-cop, unless you have a better place for example OpenShift related code. https://github.com/RyanMillerC/cat-facts-operator

Another repo that could be linked for reference is https://github.com/kiali/openshift-servicemesh-plugin. That is an Ansible-based operator that includes a console dynamic plugin.

spadgett commented 1 year ago

@RyanMillerC Oh nice! Yes, this was definitely needed. I think we can link out to your personal GitHub repo for now and then update the link if we can move it somewhere better, maybe the openshift org? Have you talked to the OLM team about making it a sample?

As an aside, we've discussed creating a hello world operator for OpenShift console CI tests... We might consider using this instead, and it would let us test enabling plugins during operator install flows. @jhadvig @jcaianirh FYI

@alimobrem FYI

RyanMillerC commented 1 year ago

I was told redhat-cop is not a good place for example code. I'm open to moving the repo wherever makes the most sense. It would be awesome if I could still be a repo owner in the new location. I'm working on implementing a console plugin for the patterns operator. There's some things I'm doing there that I would like to copy over to cat facts when I have time.

In the meantime I will open a PR to add links for both my example and the service mesh plugin.

I haven't talked to the OLM team but I'm open to talking with them. Do you have a point of contact on their team?

Thanks! 😃

openshift-bot commented 10 months ago

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot commented 9 months ago

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten /remove-lifecycle stale

openshift-bot commented 8 months ago

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen. Mark the issue as fresh by commenting /remove-lifecycle rotten. Exclude this issue from closing again by commenting /lifecycle frozen.

/close

openshift-ci[bot] commented 8 months ago

@openshift-bot: Closing this issue.

In response to [this](https://github.com/openshift/console-plugin-template/issues/20#issuecomment-1859331988): >Rotten issues close after 30d of inactivity. > >Reopen the issue by commenting `/reopen`. >Mark the issue as fresh by commenting `/remove-lifecycle rotten`. >Exclude this issue from closing again by commenting `/lifecycle frozen`. > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.