Search in sources :

Example 21 with DaemonSet

use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project jkube by eclipse.

the class TriggersAnnotationEnricherTest method testDaemonSetEnrichment.

@Test
public void testDaemonSetEnrichment() throws IOException {
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new DaemonSetBuilder().withNewMetadata().addToAnnotations("annkey", "annvalue").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(createContainers("c1", "iss:1.1.0", "c2", "docker.io/a-docker-user/is:latest")).endSpec().endTemplate().endSpec().build());
    TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context);
    enricher.enrich(PlatformMode.kubernetes, builder);
    DaemonSet res = (DaemonSet) builder.build().getItems().get(0);
    String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers");
    assertNotNull(triggers);
    List<ImageChangeTrigger> triggerList = OBJECT_MAPPER.readValue(triggers, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, ImageChangeTrigger.class));
    assertEquals(1, triggerList.size());
    ImageChangeTrigger trigger = triggerList.get(0);
    assertEquals("ImageStreamTag", trigger.getFrom().getKind());
    assertEquals("iss:1.1.0", trigger.getFrom().getName());
    assertTrue(trigger.getAdditionalProperties().containsKey("fieldPath"));
    assertEquals("annvalue", res.getMetadata().getAnnotations().get("annkey"));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DaemonSetBuilder(io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) ArrayList(java.util.ArrayList) List(java.util.List) ImageChangeTrigger(io.fabric8.openshift.api.model.ImageChangeTrigger) Test(org.junit.Test)

Example 22 with DaemonSet

use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project jkube by eclipse.

the class DaemonSetHandlerTest method daemonTemplateHandlerTest.

@Test
public void daemonTemplateHandlerTest() {
    ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").volumes(volumes1).build();
    DaemonSet daemonSet = daemonSetHandler.get(config, images);
    // Assertion
    assertNotNull(daemonSet.getSpec());
    assertNotNull(daemonSet.getMetadata());
    assertNotNull(daemonSet.getSpec().getTemplate());
    assertEquals("testing", daemonSet.getMetadata().getName());
    assertEquals("test-account", daemonSet.getSpec().getTemplate().getSpec().getServiceAccountName());
    assertFalse(daemonSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
    assertEquals("test", daemonSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", daemonSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(daemonSet.getSpec().getTemplate().getSpec().getContainers());
}
Also used : DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Test(org.junit.Test)

Example 23 with DaemonSet

use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project jkube by eclipse.

the class DaemonSetHandlerTest method overrideReplicas.

@Test
public void overrideReplicas() {
    // Given
    final KubernetesListBuilder klb = new KubernetesListBuilder().addToItems(new DaemonSet());
    // When
    daemonSetHandler.overrideReplicas(klb, 1337);
    // Then
    assertThat(klb.buildItems()).hasSize(1).first().isEqualTo(new DaemonSet());
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) Test(org.junit.Test)

Example 24 with DaemonSet

use of io.fabric8.kubernetes.api.model.apps.DaemonSet in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class OMB method pullAndHoldWorkerImageToAllNodesUsingDaemonSet.

/*
     * This Daemonset just forces the image to remain on all of the
     * worker nodes, so that there isn't any kind of pull storm (and
     * worker deploys will be slightly quicker). This DaemonSet (and
     * namespace) don't get cleaned up by the test, as it seems
     * beneficial to keep the image on the nodes between tests.
     */
private void pullAndHoldWorkerImageToAllNodesUsingDaemonSet() {
    String ombWorkerImageHolder = "omb-worker-image-holder";
    ombCluster.kubeClient().client().namespaces().createOrReplace(new NamespaceBuilder().withNewMetadata().withName(ombWorkerImageHolder).endMetadata().build());
    ombCluster.kubeClient().client().apps().daemonSets().inNamespace(ombWorkerImageHolder).createOrReplace(new DaemonSetBuilder().withNewMetadata().withName(ombWorkerImageHolder).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("app", ombWorkerImageHolder).endSelector().withNewTemplate().withNewMetadata().withLabels(Map.of("app", ombWorkerImageHolder)).endMetadata().withNewSpec().addNewContainer().withName(ombWorkerImageHolder).withImage(Constants.OMB_WORKER_IMAGE).withCommand("sh", "-c").withArgs("tail -f /dev/null").withNewResources().addToRequests(Collections.singletonMap("memory", new Quantity("12Mi"))).addToLimits(Collections.singletonMap("memory", new Quantity("50Mi"))).endResources().endContainer().withTerminationGracePeriodSeconds(5L).endSpec().endTemplate().endSpec().build());
    try {
        LOGGER.info("Waiting for DaemonSet to become ready");
        DaemonSetStatus daemonSetStatus;
        do {
            Thread.sleep(5000);
            daemonSetStatus = ombCluster.kubeClient().client().apps().daemonSets().inNamespace(ombWorkerImageHolder).withName(ombWorkerImageHolder).get().getStatus();
            LOGGER.info("DaemonSet reporting {} pods ready, expecting {}", daemonSetStatus.getNumberReady(), daemonSetStatus.getDesiredNumberScheduled());
        } while (!Objects.equals(daemonSetStatus.getNumberReady(), daemonSetStatus.getDesiredNumberScheduled()));
    } catch (InterruptedException e) {
        throw new RuntimeException("Failed to wait for DaemonSet to become ready, received InterruptedException", e);
    }
}
Also used : DaemonSetBuilder(io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) DaemonSetStatus(io.fabric8.kubernetes.api.model.apps.DaemonSetStatus) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder)

Aggregations

DaemonSet (io.fabric8.kubernetes.api.model.apps.DaemonSet)15 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)11 DaemonSetBuilder (io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder)10 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)10 Test (org.junit.Test)8 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)7 ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)7 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)7 Template (io.fabric8.openshift.api.model.Template)6 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)4 Namespace (io.fabric8.kubernetes.api.model.Namespace)4 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)4 Secret (io.fabric8.kubernetes.api.model.Secret)4 Service (io.fabric8.kubernetes.api.model.Service)4 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)4