Search in sources :

Example 1 with GenericKubernetesApi

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();
}
Also used : V1Prometheus(com.coreos.monitoring.models.V1Prometheus) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1PrometheusList(com.coreos.monitoring.models.V1PrometheusList) GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) V1PrometheusSpec(com.coreos.monitoring.models.V1PrometheusSpec)

Example 2 with GenericKubernetesApi

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!");
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Patch(io.kubernetes.client.custom.V1Patch) V1Pod(io.kubernetes.client.openapi.models.V1Pod) GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) ApiClient(io.kubernetes.client.openapi.ApiClient) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec)

Example 3 with GenericKubernetesApi

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())));
}
Also used : V1alpha2IssuerSpecSelfSigned(io.cert.manager.models.V1alpha2IssuerSpecSelfSigned) V1beta1Issuer(io.cert.manager.models.V1beta1Issuer) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) V1beta1IssuerSpec(io.cert.manager.models.V1beta1IssuerSpec) V1beta1IssuerList(io.cert.manager.models.V1beta1IssuerList)

Example 4 with GenericKubernetesApi

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);
    }
}
Also used : GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) KubectlException(io.kubernetes.client.extended.kubectl.exception.KubectlException) ApiException(io.kubernetes.client.openapi.ApiException)

Example 5 with GenericKubernetesApi

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;
}
Also used : SharedInformerFactory(io.kubernetes.client.informer.SharedInformerFactory) GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) ApiClient(io.kubernetes.client.openapi.ApiClient)

Aggregations

GenericKubernetesApi (io.kubernetes.client.util.generic.GenericKubernetesApi)5 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)3 ApiClient (io.kubernetes.client.openapi.ApiClient)2 V1Prometheus (com.coreos.monitoring.models.V1Prometheus)1 V1PrometheusList (com.coreos.monitoring.models.V1PrometheusList)1 V1PrometheusSpec (com.coreos.monitoring.models.V1PrometheusSpec)1 V1alpha2IssuerSpecSelfSigned (io.cert.manager.models.V1alpha2IssuerSpecSelfSigned)1 V1beta1Issuer (io.cert.manager.models.V1beta1Issuer)1 V1beta1IssuerList (io.cert.manager.models.V1beta1IssuerList)1 V1beta1IssuerSpec (io.cert.manager.models.V1beta1IssuerSpec)1 V1Patch (io.kubernetes.client.custom.V1Patch)1 KubectlException (io.kubernetes.client.extended.kubectl.exception.KubectlException)1 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)1 ApiException (io.kubernetes.client.openapi.ApiException)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1 V1Pod (io.kubernetes.client.openapi.models.V1Pod)1 V1PodList (io.kubernetes.client.openapi.models.V1PodList)1 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)1