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"));
}
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());
}
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());
}
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);
}
}
Aggregations