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

Creating a ServiceMonitor #2367

Closed
zenbones opened this issue Jul 21, 2020 · 3 comments · Fixed by #2412
Closed

Creating a ServiceMonitor #2367

zenbones opened this issue Jul 21, 2020 · 3 comments · Fixed by #2412
Assignees
Labels

Comments

@zenbones
Copy link

Is there any way to create a ServiceMonitor, as in..

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor

If it isn't directly wrapped by the API, can I use the client to create/install an arbitrary type from string or JsonNode or... something?

@rohanKanojia
Copy link
Member

@zenbones
Copy link
Author

It does help. I think this case is common enough that wrapping it in a specific api (as in client.serviceMonitors()..., etc.) seems useful. But the above worked as a workaround.

@manusa manusa added enhancement platform/openshift Specific to OpenShift labels Aug 3, 2020
@rohanKanojia rohanKanojia self-assigned this Aug 19, 2020
@rohanKanojia
Copy link
Member

#2412 should take care of this issue. You should be able to create ServiceMonitor like this once it gets merged:

        try (OpenShiftClient client = new DefaultOpenShiftClient()) {
            ServiceMonitor serviceMonitor = new ServiceMonitorBuilder()
                    .withNewMetadata()
                    .withName("foo")
                    .addToLabels("prometheus", "frontend")
                    .endMetadata()
                    .withNewSpec()
                    .withNewNamespaceSelector().withAny(true).endNamespaceSelector()
                    .withNewSelector()
                    .addToMatchLabels("prometheus", "frontend")
                    .endSelector()
                    .addNewEndpoint()
                    .withPort("http-metric")
                    .withInterval("15s")
                    .endEndpoint()
                    .endSpec()
                    .build();

            client.monitoring().serviceMonitors().inNamespace("rokumar").createOrReplace(serviceMonitor);
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants