use of io.kubernetes.client.util.generic.GenericKubernetesApi in project java by kubernetes-client.
the class PromOpExample method main.
public static void main(String[] args) throws IOException, ApiException {
GenericKubernetesApi<V1Prometheus, V1PrometheusList> prometheusApi = new GenericKubernetesApi<>(V1Prometheus.class, V1PrometheusList.class, "monitoring.coreos.com", "v1", "prometheuses", ClientBuilder.defaultClient());
prometheusApi.create(new V1Prometheus().metadata(new V1ObjectMeta().namespace("default").name("my-prometheus")).kind("Prometheus").apiVersion("monitoring.coreos.com/v1").spec(new V1PrometheusSpec())).throwsApiException();
}
use of io.kubernetes.client.util.generic.GenericKubernetesApi in project java by kubernetes-client.
the class GenericClientExample method main.
public static void main(String[] args) throws Exception {
// The following codes demonstrates using generic client to manipulate pods
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name("foo").namespace("default")).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name("c").image("test"))));
ApiClient apiClient = ClientBuilder.standard().build();
GenericKubernetesApi<V1Pod, V1PodList> podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);
V1Pod latestPod = podClient.create(pod).throwsApiException().getObject();
System.out.println("Created!");
V1Pod patchedPod = podClient.patch("default", "foo", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}")).throwsApiException().getObject();
System.out.println("Patched!");
V1Pod deletedPod = podClient.delete("default", "foo").throwsApiException().getObject();
if (deletedPod != null) {
System.out.println("Received after-deletion status of the requested object, will be deleting in background!");
}
System.out.println("Deleted!");
}
use of io.kubernetes.client.util.generic.GenericKubernetesApi in project java by kubernetes-client.
the class CertManagerExample method main.
public static void main(String[] args) throws IOException {
GenericKubernetesApi<V1beta1Issuer, V1beta1IssuerList> issuerApi = new GenericKubernetesApi<>(V1beta1Issuer.class, V1beta1IssuerList.class, "cert-manager.io", "v1beta1", "issuers", ClientBuilder.defaultClient());
issuerApi.create(new V1beta1Issuer().metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer")).kind("Issuer").apiVersion("cert-manager.io/v1beta1").spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned())));
}
use of io.kubernetes.client.util.generic.GenericKubernetesApi in project java by kubernetes-client.
the class KubectlPatch method execute.
@Override
public ApiType execute() throws KubectlException {
refreshDiscovery();
GenericKubernetesApi genericKubernetesApi = getGenericApi();
try {
if (ModelMapper.isNamespaced(apiTypeClass)) {
return (ApiType) genericKubernetesApi.patch(namespace, name, patchType, patchContent).throwsApiException().getObject();
} else {
return (ApiType) genericKubernetesApi.patch(name, patchType, patchContent).throwsApiException().getObject();
}
} catch (ApiException e) {
throw new KubectlException(e);
}
}
use of io.kubernetes.client.util.generic.GenericKubernetesApi in project java by kubernetes-client.
the class KubernetesInformerFactoryProcessor method informer.
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T extends KubernetesObject> SharedInformer<T> informer(Class<T> type, KubernetesInformer kubernetesInformer) {
ApiClient apiClient = this.beanFactory.getBean(ApiClient.class);
if (apiClient.getHttpClient().readTimeoutMillis() > 0) {
log.warn("Enforcing read-timeout of the ApiClient {} to {} so that the watch connection won't abort from client-side", apiClient, informerProperties.getClientReadTimeout());
apiClient.setHttpClient(apiClient.getHttpClient().newBuilder().readTimeout(informerProperties.getClientReadTimeout()).build());
}
SharedInformerFactory sharedInformerFactory = this.beanFactory.getBean(SharedInformerFactory.class);
final GenericKubernetesApi api = new GenericKubernetesApi(kubernetesInformer.apiTypeClass(), kubernetesInformer.apiListTypeClass(), kubernetesInformer.groupVersionResource().apiGroup(), kubernetesInformer.groupVersionResource().apiVersion(), kubernetesInformer.groupVersionResource().resourcePlural(), apiClient);
SharedIndexInformer<T> sharedIndexInformer = sharedInformerFactory.sharedIndexInformerFor(api, type, kubernetesInformer.resyncPeriodMillis(), kubernetesInformer.namespace());
return sharedIndexInformer;
}
Aggregations