-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Bug creating metric service monitors when watching a different namespace #2494
Comments
I will check it as soon as possible @davidkirwan. |
Hi @davidkirwan, As we spoke about it, following the explanation to attend the need that you are looking for which is; have a cluster-scope operator which will watch/cache just a few namespaces in the cluster and not all. Note that the operator will still with a cluster-scoped and then, is required to following the steps in the doc. After that, to define(restrict) the few namespaces that you would like to be watching/caching in the project you can use the manager.Options MultiNamespacedCacheBuilder. So, in the // List of Namespaces
// Here you can add all namespaces that the Operator will be dealing with
// Note that the namespace where the operator is deployed should be part of this context as well.
var namespaces []string
// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{
NewCache: cache.MultiNamespacedCacheBuilder(namespaces),
MapperProvider: restmapper.NewDynamicRESTMapper,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
}) This list must contain the operator namespace as well. See here that the metrics resources which are created by default will be done for the operator and its CR's which means that it needs to be able to watch/cache the namespace where it is deployed too. In this way, I am closing this one as sorted out. Please, feel free to re-open or ping us to do that if you see that still required any help with. |
… to Ansible/Helm operators to handle [multinamespace caching] (#2522) **Motivation for the change:** - Integration with OLM: See that OLM allows and config the MultiNamespace via the option `targetNamespaces` via the OperatorGroup. We are also in the olm commands setting these values in the WATCH-NAMESPACE EnvVar. - Address the requirements requested in tasks such as #2494, #2078, (which are a very common scenario in the channels: I as an operator dev, would like to deploy the operator in the nsA and WATCH the resources in the nsB and do not all cluster ), Closes #2361
Sorry to glob onto this, but I'm having a similar issue and am getting the following error (v0.15.2):
The explanation listed above doesn't seem applicable, as our operator is watching all namespaces (hence, I can workaround the issue by specifying the operator namespace, but I don't know enough about the service monitors to know what that might break. Please advise. |
@camilamacedo86, thanks. That's exactly the issue I'm having. I simply changed the code to use the operator namespace when creating the service monitors. |
) **Description of the change:** - Fix `ServiceMonitor` creation when the operator is cluster-scoped and the environment variable `WATCH_NAMESPACE` has not as value the namespace where the operator was deployed. - Update mock data ( test-framework ) with the latest version of the main.go. **Motivation for the change:** Closes: #2602 See: #2494 (comment)
Bug Report
What did you do?
A clear and concise description of the steps you took (or insert a code snippet).
I ran an operator from namespace A, which is set to watch namespace B.
What did you expect to see?
A clear and concise description of what you expected to happen (or insert a code snippet).
I expected to see a ServiceMonitor to be created on the operator metrics service in namespace A
What did you see instead? Under which circumstances?
A clear and concise description of what you expected to happen (or insert a code snippet).
I saw an error in the operator logs about it being unable to create the servicemonitor:
Environment
operator-sdk version: "v0.12.0", commit: "2445fcda834ca4b7cf0d6c38fba6317fb219b469", go version: "go1.12.13 linux/amd64"
go version go1.13.6 linux/amd64
Kubernetes cluster kind:
Openshift:
4.2.14
Kubernetes:
v1.14.6+b294fe5
Are you writing your operator in ansible, helm, or go?
I'm writing the operator in Go
Possible Solution
The solution which I have used as a workaround in my operator, is to pass the namespace that hte operator is running inside, to the function which creates the servicemonitor in the main.go. See PR:
Additional context
Add any other context about the problem here.
I've attached some log showing the steps to replicate:
test-operator-64b7c777cc-prqz9-test-operator.log
The text was updated successfully, but these errors were encountered: