use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.
the class AbstractHealthCheckEnricherTest method enrichSpecificContainers.
@Test
public void enrichSpecificContainers() {
final Properties properties = new Properties();
properties.put(AbstractHealthCheckEnricher.ENRICH_CONTAINERS, "app2,app3");
KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("app").withImage("app:latest").endContainer().addNewContainer().withName("app2").withImage("app2:latest").endContainer().addNewContainer().withName("app3").withImage("app3:latest").endContainer().endSpec().endTemplate().endSpec().build());
createEnricher(properties, Collections.emptyMap()).create(PlatformMode.kubernetes, list);
final AtomicInteger containerFound = new AtomicInteger(0);
list.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
if (container.getName().equals("app")) {
assertNull(container.build().getLivenessProbe());
assertNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
} else if (container.getName().equals("app2")) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
} else if (container.getName().equals("app3")) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
}
}
});
assertEquals(3, containerFound.get());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.
the class AbstractHealthCheckEnricherTest method enrichContainerWithSidecar.
@Test
public void enrichContainerWithSidecar() {
KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("app").withImage("app:latest").endContainer().addNewContainer().withName("sidecar").withImage("sidecar:latest").endContainer().endSpec().endTemplate().endSpec().build());
createEnricher(new Properties(), Collections.singletonMap("FABRIC8_GENERATED_CONTAINERS", "app")).create(PlatformMode.kubernetes, list);
final AtomicInteger containerFound = new AtomicInteger(0);
list.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
if (container.getName().equals("app")) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
} else if (container.getName().equals("sidecar")) {
assertNull(container.build().getLivenessProbe());
assertNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
}
}
});
assertEquals(2, containerFound.get());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.
the class AbstractHealthCheckEnricherTest method enrichAllContainers.
@Test
public void enrichAllContainers() {
final Properties properties = new Properties();
properties.put(AbstractHealthCheckEnricher.ENRICH_ALL_CONTAINERS, "true");
KubernetesListBuilder list = new KubernetesListBuilder().addToItems(new DeploymentBuilder().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("app").withImage("app:latest").endContainer().addNewContainer().withName("app2").withImage("app2:latest").endContainer().endSpec().endTemplate().endSpec().build());
createEnricher(properties, Collections.emptyMap()).create(PlatformMode.kubernetes, list);
final AtomicInteger containerFound = new AtomicInteger(0);
list.accept(new TypedVisitor<ContainerBuilder>() {
@Override
public void visit(ContainerBuilder container) {
if (container.getName().equals("app")) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
} else if (container.getName().equals("app2")) {
assertNotNull(container.build().getLivenessProbe());
assertNotNull(container.build().getReadinessProbe());
containerFound.incrementAndGet();
}
}
});
assertEquals(2, containerFound.get());
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.
the class ControllerViaPluginConfigurationEnricher method create.
@Override
public void create(PlatformMode platformMode, KubernetesListBuilder builder) {
final String name = getConfig(Config.name, MavenUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId()));
ResourceConfig xmlResourceConfig = getConfiguration().getResource().orElse(null);
final ResourceConfig config = new ResourceConfig.Builder().controllerName(name).imagePullPolicy(getImagePullPolicy(xmlResourceConfig, getConfig(Config.pullPolicy))).withReplicas(getReplicaCount(builder, xmlResourceConfig, Configs.asInt(getConfig(Config.replicaCount)))).build();
final List<ImageConfiguration> images = getImages().orElse(Collections.emptyList());
// Check if at least a replica set is added. If not add a default one
if (KubernetesResourceUtil.checkForKind(builder, POD_CONTROLLER_KINDS)) {
// At least one image must be present, otherwise the resulting config will be invalid
if (KubernetesResourceUtil.checkForKind(builder, "StatefulSet")) {
final StatefulSetSpec spec = statefulSetHandler.getStatefulSet(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<StatefulSetBuilder>() {
@Override
public void visit(StatefulSetBuilder statefulSetBuilder) {
statefulSetBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeStatefulSetSpec(statefulSetBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
if (defaultApplicationContainerName != null) {
setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
}
}
});
}
}
} else {
final DeploymentSpec spec = deployHandler.getDeployment(config, images).getSpec();
if (spec != null) {
builder.accept(new TypedVisitor<DeploymentBuilder>() {
@Override
public void visit(DeploymentBuilder deploymentBuilder) {
deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec();
mergeDeploymentSpec(deploymentBuilder, spec);
}
});
if (spec.getTemplate() != null && spec.getTemplate().getSpec() != null) {
final PodSpec podSpec = spec.getTemplate().getSpec();
builder.accept(new TypedVisitor<PodSpecBuilder>() {
@Override
public void visit(PodSpecBuilder builder) {
String defaultApplicationContainerName = KubernetesResourceUtil.mergePodSpec(builder, podSpec, name, getValueFromConfig(SIDECAR, false));
if (defaultApplicationContainerName != null) {
setProcessingInstruction(NEED_IMAGECHANGE_TRIGGERS, Collections.singletonList(defaultApplicationContainerName));
}
}
});
}
}
}
}
}
use of io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder in project strimzi-kafka-operator by strimzi.
the class MockKube2ControllersTest method testDeploymentController.
@Test
public void testDeploymentController() {
final String deploymentName = "my-deployment";
client.apps().deployments().inNamespace(NAMESPACE).create(new DeploymentBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(deploymentName).endMetadata().withNewSpec().withReplicas(3).withSelector(new LabelSelector(null, Map.of("app", "my-app"))).withNewTemplate().withNewSpec().withContainers(new ContainerBuilder().withName("nginx").withImage("nginx:1.14.2").build()).endSpec().endTemplate().endSpec().build());
TestUtils.waitFor("Wait for deployment to have status", 100L, 10_000L, () -> client.apps().deployments().inNamespace(NAMESPACE).withName(deploymentName).get() != null && client.apps().deployments().inNamespace(NAMESPACE).withName(deploymentName).get().getStatus() != null);
Deployment createdDeployment = client.apps().deployments().inNamespace(NAMESPACE).withName(deploymentName).get();
assertThat(createdDeployment, is(notNullValue()));
assertThat(createdDeployment.getStatus(), is(notNullValue()));
assertThat(createdDeployment.getStatus().getReplicas(), is(3));
assertThat(createdDeployment.getStatus().getAvailableReplicas(), is(3));
assertThat(createdDeployment.getStatus().getObservedGeneration(), is(1L));
}
Aggregations