-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 for *Kubernetes* client (not openshift) #2740
Comments
Yes, you should be able to do it using the RAW API: https://github.com/fabric8io/kubernetes-client/blob/master/doc/CHEATSHEET.md#customresource-typeless-api |
Yes, I know I can, and that does work. I had opened this ticket before, which you responded to with the very nice work on ServiceMonitor you did for the OpenShift client. The problem is that I'm using the Kubernetes client. I guess I should bother to read the code and create a proper k8s version of ServiceMonitor, but my time is limited and the raw api does work fine, but the heart wants what the heart wants. |
ohk, I see. I don't think it's possible to add If you just want to use <dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model-monitoring</artifactId>
<version>5.0.0</version>
</dependency> and then create a try (KubernetesClient client = new DefaultKubernetesClient()) {
// Create ServiceMonitor Client
MixedOperation<ServiceMonitor, ServiceMonitorList, Resource<ServiceMonitor>> svcMonitorClient = client.customResources(ServiceMonitor.class);
// Use Client for ServiceMonitor related operations
svcMonitorClient.inNamespace("foo").list();
} If you don't want to add additional dependency you can copy-paste ServiceMonitor POJOs into your project too(You can find them while building the project):
|
Thank you, that's helpful. I'll poke around when I get a chance and see what works best. Feel free to close this ticket. Adding a small section in docs with advice similar to the above might be helpful for others as well. |
Hello i have a question, |
@shouldnotappearcalm: Hmm, I'm not sure if depending upon current CustomResource API you would be able to use it. Could you please create an issue for adding support for Prometheus Extension? It should be easy to implement. |
@rohanKanojia: This is how I use it now,but Config config = new ConfigBuilder().build();
KubernetesClient kubernetesClient = new DefaultKubernetesClient(config);
String crdName = "servicemonitors.monitoring.coreos.com";
CustomResourceDefinition crd = new ApiextensionsAPIGroupClient().v1beta1().customResourceDefinitions().withName(crdName).get();
MixedOperation<ServiceMonitor, ServiceMonitorList, Resource<ServiceMonitor>> svcMonitorClient = kubernetesClient.customResources(CustomResourceDefinitionContext.fromCrd(crd), ServiceMonitor.class, ServiceMonitorList.class);
ServiceMonitorList serviceMonitorList = svcMonitorClient.inNamespace("default").list(); |
Hmm, I see. We're discussing whether this should be part of API in future versions or not here #2738 . I think it should stay there since this can allow users to use same POJO for multiple versions too. |
Okay, the way I currently use can also achieve my needs |
@shouldnotappearcalm : Bdw, I would appreciate it if you could add your comment on #2738 to make this method not deprecated . It would help us in making the right decision. |
I have added a comment to 2738 |
@shouldnotappearcalm @rohanKanojia @zenbones: FWIW, we do have a client extension as part of dekorate: https://github.com/dekorateio/dekorate/tree/master/annotations/prometheus-annotations The extension bits:
package should move to the client as extension, or at least that was the intention. |
@iocanel : Could you please open a separate issue for this? I think we should do it. Right now our extensions also have |
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?
The text was updated successfully, but these errors were encountered: