Java Code Examples for io.fabric8.kubernetes.client.KubernetesClient#customResources()

The following examples show how to use io.fabric8.kubernetes.client.KubernetesClient#customResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesConnection.java    From vault-crd with Apache License 2.0 6 votes vote down vote up
@Bean
public MixedOperation<Vault, VaultList, DoneableVault, Resource<Vault, DoneableVault>> customResource(
        KubernetesClient client, @Value("${kubernetes.crd.name}") String crdName) {
    Resource<CustomResourceDefinition, DoneableCustomResourceDefinition> crdResource
            = client.customResourceDefinitions().withName(crdName);

    // Hack for bug in Kubernetes-Client for CRDs https://github.com/fabric8io/kubernetes-client/issues/1099
    String kind = StringUtils.substringAfter(crdName, ".") + "/v1#Vault";
    KubernetesDeserializer.registerCustomKind(kind, Vault.class);

    CustomResourceDefinition customResourceDefinition = crdResource.get();
    if (customResourceDefinition == null) {
        log.error("Please first apply custom resource definition and then restart vault-crd");
        System.exit(1);
    }

    return client.customResources(customResourceDefinition, Vault.class, VaultList.class, DoneableVault.class);
}
 
Example 2
Source File: PodSetControllerTest.java    From podsetoperatorinjava with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("Should create pods for with respect to a specified PodSet")
public void testReconcile() throws InterruptedException {
    // Given
    String testNamespace = "ns1";
    PodSet testPodSet = getPodSet("example-podset", testNamespace, "0800cff3-9d80-11ea-8973-0e13a02d8ebd");
    server.expect().post().withPath("/api/v1/namespaces/" + testNamespace + "/pods")
            .andReturn(HttpURLConnection.HTTP_CREATED, new PodBuilder().withNewMetadata().withName("pod1-clone").endMetadata().build())
            .times(testPodSet.getSpec().getReplicas());
    KubernetesClient client = server.getClient();

    SharedInformerFactory informerFactory = client.informers();
    MixedOperation<PodSet, PodSetList, DoneablePodSet, Resource<PodSet, DoneablePodSet>> podSetClient = client.customResources(podSetCustomResourceDefinition, PodSet.class, PodSetList.class, DoneablePodSet.class);
    SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, PodList.class, RESYNC_PERIOD_MILLIS);
    SharedIndexInformer<PodSet> podSetSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(podSetCustomResourceDefinitionContext, PodSet.class, PodSetList.class, RESYNC_PERIOD_MILLIS);
    PodSetController podSetController = new PodSetController(client, podSetClient, podSharedIndexInformer, podSetSharedIndexInformer, testNamespace);

    // When
    podSetController.reconcile(testPodSet);

    // Then
    RecordedRequest recordedRequest = server.getLastRequest();
    assertEquals("POST", recordedRequest.getMethod());
    assertTrue(recordedRequest.getBody().readUtf8().contains(testPodSet.getMetadata().getName()));
}
 
Example 3
Source File: CustomResourceCrudTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCrudWithDashSymbolInCRDName() throws IOException {
  CronTab cronTab1 = createCronTab("my-new-cron-object", "* * * * */5", 3, "my-awesome-cron-image");
  CronTab cronTab2 = createCronTab("my-second-cron-object", "* * * * */4", 2, "my-second-cron-image");
  CronTab cronTab3 = createCronTab("my-third-cron-object", "* * * * */3", 1, "my-third-cron-image");
  KubernetesClient client = kubernetesServer.getClient();

  MixedOperation<CronTab, CronTabList, DoneableCronTab, Resource<CronTab, DoneableCronTab>> cronTabClient = client
    .customResources(cronTabCrd, CronTab.class, CronTabList.class, DoneableCronTab.class);

  cronTabClient.inNamespace("test-ns").create(cronTab1);
  cronTabClient.inNamespace("test-ns").create(cronTab2);
  cronTabClient.inNamespace("test-ns").create(cronTab3);

  CronTabList cronTabList = cronTabClient.inNamespace("test-ns").list();
  assertNotNull(cronTabList);
  assertEquals(3, cronTabList.getItems().size());

  CronTab fromServerCronTab = cronTabClient.inNamespace("test-ns").withName("my-new-cron-object").get();
  assertNotNull(fromServerCronTab);
  assertCronTab(fromServerCronTab, "my-new-cron-object", "* * * * */5", 3, "my-awesome-cron-image");

  CronTab fromServerCronTab2 = cronTabClient.inNamespace("test-ns").withName("my-second-cron-object").get();
  assertNotNull(fromServerCronTab2);
  assertCronTab(fromServerCronTab2, "my-second-cron-object", "* * * * */4", 2, "my-second-cron-image");

  CronTab fromServerCronTab3 = cronTabClient.inNamespace("test-ns").withName("my-third-cron-object").get();
  assertNotNull(fromServerCronTab3);
  assertCronTab(fromServerCronTab3, "my-third-cron-object", "* * * * */3", 1, "my-third-cron-image");

  cronTabClient.inNamespace("test-ns").withName("my-third-cron-object").delete();
  cronTabList = cronTabClient.inNamespace("test-ns").list();
  assertEquals(2, cronTabList.getItems().size());
}
 
Example 4
Source File: CustomResourceCrudTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCrud() throws IOException {
  CronTab cronTab1 = createCronTab("my-new-cron-object", "* * * * */5", 3, "my-awesome-cron-image");
  CronTab cronTab2 = createCronTab("my-second-cron-object", "* * * * */4", 2, "my-second-cron-image");
  CronTab cronTab3 = createCronTab("my-third-cron-object", "* * * * */3", 1, "my-third-cron-image");
  KubernetesClient client = kubernetesServer.getClient();

  MixedOperation<CronTab, CronTabList, DoneableCronTab, Resource<CronTab, DoneableCronTab>> cronTabClient = client
    .customResources(crdContext, CronTab.class, CronTabList.class, DoneableCronTab.class);

  cronTabClient.inNamespace("test-ns").create(cronTab1);
  cronTabClient.inNamespace("test-ns").create(cronTab2);
  cronTabClient.inNamespace("test-ns").create(cronTab3);

  CronTabList cronTabList = cronTabClient.inNamespace("test-ns").list();
  assertNotNull(cronTabList);
  assertEquals(3, cronTabList.getItems().size());

  CronTab fromServerCronTab = cronTabClient.inNamespace("test-ns").withName("my-new-cron-object").get();
  assertNotNull(fromServerCronTab);
  assertCronTab(fromServerCronTab, "my-new-cron-object", "* * * * */5", 3, "my-awesome-cron-image");

  CronTab fromServerCronTab2 = cronTabClient.inNamespace("test-ns").withName("my-second-cron-object").get();
  assertNotNull(fromServerCronTab2);
  assertCronTab(fromServerCronTab2, "my-second-cron-object", "* * * * */4", 2, "my-second-cron-image");

  CronTab fromServerCronTab3 = cronTabClient.inNamespace("test-ns").withName("my-third-cron-object").get();
  assertNotNull(fromServerCronTab3);
  assertCronTab(fromServerCronTab3, "my-third-cron-object", "* * * * */3", 1, "my-third-cron-image");

  cronTabClient.inNamespace("test-ns").withName("my-third-cron-object").delete();
  cronTabList = cronTabClient.inNamespace("test-ns").list();
  assertEquals(2, cronTabList.getItems().size());
}
 
Example 5
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public static <T extends CustomResource, L extends CustomResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>>
        operation(KubernetesClient client,
                  Class<T> cls,
                  Class<L> listCls,
                  Class<D> doneableCls) {
    return client.customResources(crd(cls), cls, listCls, doneableCls);
}
 
Example 6
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaConnector, KafkaConnectorList, DoneableKafkaConnector, Resource<KafkaConnector, DoneableKafkaConnector>> kafkaConnectorOperation(KubernetesClient client) {
    return client.customResources(kafkaConnector(), KafkaConnector.class, KafkaConnectorList.class, DoneableKafkaConnector.class);
}
 
Example 7
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static <D extends CustomResourceDoneable<T>, T extends CustomResource> MixedOperation<KafkaConnectS2I, KafkaConnectS2IList, DoneableKafkaConnectS2I, Resource<KafkaConnectS2I, DoneableKafkaConnectS2I>> kafkaConnectS2iOperation(KubernetesClient client) {
    return client.customResources(Crds.kafkaConnectS2I(), KafkaConnectS2I.class, KafkaConnectS2IList.class, DoneableKafkaConnectS2I.class);
}
 
Example 8
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaTopic, KafkaTopicList, DoneableKafkaTopic, Resource<KafkaTopic, DoneableKafkaTopic>> topicOperation(KubernetesClient client) {
    return client.customResources(kafkaTopic(), KafkaTopic.class, KafkaTopicList.class, DoneableKafkaTopic.class);
}
 
Example 9
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaUser, KafkaUserList, DoneableKafkaUser, Resource<KafkaUser, DoneableKafkaUser>> kafkaUserOperation(KubernetesClient client) {
    return client.customResources(kafkaUser(), KafkaUser.class, KafkaUserList.class, DoneableKafkaUser.class);
}
 
Example 10
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaMirrorMaker, KafkaMirrorMakerList, DoneableKafkaMirrorMaker, Resource<KafkaMirrorMaker, DoneableKafkaMirrorMaker>> mirrorMakerOperation(KubernetesClient client) {
    return client.customResources(kafkaMirrorMaker(), KafkaMirrorMaker.class, KafkaMirrorMakerList.class, DoneableKafkaMirrorMaker.class);
}
 
Example 11
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaBridge, KafkaBridgeList, DoneableKafkaBridge, Resource<KafkaBridge, DoneableKafkaBridge>> kafkaBridgeOperation(KubernetesClient client) {
    return client.customResources(kafkaBridge(), KafkaBridge.class, KafkaBridgeList.class, DoneableKafkaBridge.class);
}
 
Example 12
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaMirrorMaker2, KafkaMirrorMaker2List, DoneableKafkaMirrorMaker2, Resource<KafkaMirrorMaker2, DoneableKafkaMirrorMaker2>> kafkaMirrorMaker2Operation(KubernetesClient client) {
    return client.customResources(kafkaMirrorMaker2(), KafkaMirrorMaker2.class, KafkaMirrorMaker2List.class, DoneableKafkaMirrorMaker2.class);
}
 
Example 13
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaRebalance, KafkaRebalanceList, DoneableKafkaRebalance, Resource<KafkaRebalance, DoneableKafkaRebalance>> kafkaRebalanceOperation(KubernetesClient client) {
    return client.customResources(kafkaRebalance(), KafkaRebalance.class, KafkaRebalanceList.class, DoneableKafkaRebalance.class);
}
 
Example 14
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<KafkaConnect, KafkaConnectList, DoneableKafkaConnect, Resource<KafkaConnect, DoneableKafkaConnect>> kafkaConnectOperation(KubernetesClient client) {
    return client.customResources(kafkaConnect(), KafkaConnect.class, KafkaConnectList.class, DoneableKafkaConnect.class);
}
 
Example 15
Source File: IoTProjects.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<IoTProject, IoTProjectList, DoneableIoTProject, Resource<IoTProject, DoneableIoTProject>> clientForProject(final KubernetesClient client) {
    return client
            .customResources(project(),
                    IoTProject.class, IoTProjectList.class, DoneableIoTProject.class);
}
 
Example 16
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<Kafka, KafkaList, DoneableKafka, Resource<Kafka, DoneableKafka>> kafkaV1Alpha1Operation(KubernetesClient client) {
    return client.customResources(crd(Kafka.class, Constants.V1ALPHA1), Kafka.class, KafkaList.class, DoneableKafka.class);
}
 
Example 17
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static MixedOperation<Kafka, KafkaList, DoneableKafka, Resource<Kafka, DoneableKafka>> kafkaOperation(KubernetesClient client) {
    return client.customResources(kafka(), Kafka.class, KafkaList.class, DoneableKafka.class);
}