use of io.fabric8.kubernetes.api.model.PodTemplate in project keycloak by keycloak.
the class PodTemplateTest method testProbesAreMerged.
@Test
public void testProbesAreMerged() {
// Arrange
var ready = new ProbeBuilder().withNewExec().withCommand("foo").endExec().withFailureThreshold(1).withInitialDelaySeconds(2).withTimeoutSeconds(3).build();
var live = new ProbeBuilder().withNewHttpGet().withPort(new IntOrString(1000)).withScheme("UDP").withPath("/foo").endHttpGet().withFailureThreshold(4).withInitialDelaySeconds(5).withTimeoutSeconds(6).build();
var additionalPodTemplate = new PodTemplateSpecBuilder().withNewSpec().addNewContainer().withReadinessProbe(ready).withLivenessProbe(live).endContainer().endSpec().build();
// Act
var podTemplate = getDeployment(additionalPodTemplate).getSpec().getTemplate();
// Assert
var readyProbe = podTemplate.getSpec().getContainers().get(0).getReadinessProbe();
var liveProbe = podTemplate.getSpec().getContainers().get(0).getLivenessProbe();
assertEquals("foo", ready.getExec().getCommand().get(0));
assertEquals(1, readyProbe.getFailureThreshold());
assertEquals(2, readyProbe.getInitialDelaySeconds());
assertEquals(3, readyProbe.getTimeoutSeconds());
assertEquals(1000, liveProbe.getHttpGet().getPort().getIntVal());
assertEquals("UDP", liveProbe.getHttpGet().getScheme());
assertEquals("/foo", liveProbe.getHttpGet().getPath());
assertEquals(4, liveProbe.getFailureThreshold());
assertEquals(5, liveProbe.getInitialDelaySeconds());
assertEquals(6, liveProbe.getTimeoutSeconds());
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project keycloak by keycloak.
the class PodTemplateTest method testCommandsAndArgsAreMerged.
@Test
public void testCommandsAndArgsAreMerged() {
// Arrange
var command = "foo";
var arg = "bar";
var additionalPodTemplate = new PodTemplateSpecBuilder().withNewSpec().addNewContainer().withCommand(command).withArgs(arg).endContainer().endSpec().build();
// Act
var podTemplate = getDeployment(additionalPodTemplate).getSpec().getTemplate();
// Assert
assertEquals(1, podTemplate.getSpec().getContainers().get(0).getCommand().size());
assertEquals(command, podTemplate.getSpec().getContainers().get(0).getCommand().get(0));
assertEquals(1, podTemplate.getSpec().getContainers().get(0).getArgs().size());
assertEquals(arg, podTemplate.getSpec().getContainers().get(0).getArgs().get(0));
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project fabric8-maven-plugin by fabric8io.
the class DeploymentOpenShiftConverter method convert.
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
Deployment resource = (Deployment) item;
DeploymentConfigBuilder builder = new DeploymentConfigBuilder();
builder.withMetadata(resource.getMetadata());
DeploymentSpec spec = resource.getSpec();
if (spec != null) {
DeploymentConfigFluent.SpecNested<DeploymentConfigBuilder> specBuilder = builder.withNewSpec();
Integer replicas = spec.getReplicas();
if (replicas != null) {
specBuilder.withReplicas(replicas);
}
Integer revisionHistoryLimit = spec.getRevisionHistoryLimit();
if (revisionHistoryLimit != null) {
specBuilder.withRevisionHistoryLimit(revisionHistoryLimit);
}
LabelSelector selector = spec.getSelector();
if (selector != null) {
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
specBuilder.withSelector(matchLabels);
}
}
Map<String, String> containerToImageMap = new HashMap<>();
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
specBuilder.withTemplate(template);
PodSpec podSpec = template.getSpec();
notNull(podSpec, "No PodSpec for PodTemplate:" + template);
List<Container> containers = podSpec.getContainers();
notNull(podSpec, "No containers for PodTemplate.spec: " + template);
for (Container container : containers) {
validateContainer(container);
containerToImageMap.put(container.getName(), container.getImage());
}
}
DeploymentStrategy strategy = spec.getStrategy();
String strategyType = null;
if (strategy != null) {
strategyType = strategy.getType();
}
if (openshiftDeployTimeoutSeconds != null && openshiftDeployTimeoutSeconds > 0) {
if (Strings.isNullOrBlank(strategyType) || "Rolling".equals(strategyType)) {
specBuilder.withNewStrategy().withType("Rolling").withNewRollingParams().withTimeoutSeconds(openshiftDeployTimeoutSeconds).endRollingParams().endStrategy();
} else if ("Recreate".equals(strategyType)) {
specBuilder.withNewStrategy().withType("Recreate").withNewRecreateParams().withTimeoutSeconds(openshiftDeployTimeoutSeconds).endRecreateParams().endStrategy();
} else {
specBuilder.withNewStrategy().withType(strategyType).endStrategy();
}
} else if (Strings.isNotBlank(strategyType)) {
// TODO is there any values we can copy across?
specBuilder.withNewStrategy().withType(strategyType).endStrategy();
}
// lets add a default trigger so that its triggered when we change its config
if (enableAutomaticTrigger) {
specBuilder.addNewTrigger().withType("ConfigChange").endTrigger();
}
// add a new image change trigger for the build stream
if (containerToImageMap.size() != 0) {
if (mode.equals(PlatformMode.openshift)) {
for (Map.Entry<String, String> entry : containerToImageMap.entrySet()) {
String containerName = entry.getKey();
ImageName image = new ImageName(entry.getValue());
String tag = image.getTag() != null ? image.getTag() : "latest";
specBuilder.addNewTrigger().withType("ImageChange").withNewImageChangeParams().withAutomatic(enableAutomaticTrigger).withNewFrom().withKind("ImageStreamTag").withName(image.getSimpleName() + ":" + tag).withNamespace(image.getUser()).endFrom().withContainerNames(containerName).endImageChangeParams().endTrigger();
}
}
if (trimImageInContainerSpec) {
/*
* In Openshift 3.7, update to container image is automatically triggering redeployments
* and those subsequent rollouts lead to RC complaining about a missing image reference.
*
* See this : https://github.com/openshift/origin/issues/18406#issuecomment-364090247
*
* this the time it gets fixed. Do this:
* Since we're using ImageTrigger here, set container image to " ". If there is any config
* change never set to image else than " "; so doing oc apply/rollouts won't be creating
* re-deployments again and again.
*
*/
List<Container> containers = template.getSpec().getContainers();
for (Integer nIndex = 0; nIndex < containers.size(); nIndex++) {
containers.get(nIndex).setImage(" ");
}
template.getSpec().setContainers(containers);
specBuilder.withTemplate(template);
}
}
specBuilder.endSpec();
}
return builder.build();
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project fabric8 by fabric8io.
the class Example method listReplicationControllers.
protected static void listReplicationControllers(KubernetesClient kube) {
System.out.println("\n\nLooking up replicationControllers");
System.out.println("=========================================================================");
ReplicationControllerList replicationControllers = kube.replicationControllers().list();
List<ReplicationController> items = replicationControllers.getItems();
for (ReplicationController item : items) {
ReplicationControllerSpec replicationControllerSpec = item.getSpec();
if (replicationControllerSpec != null) {
System.out.println("ReplicationController " + KubernetesHelper.getName(item) + " labels: " + item.getMetadata().getLabels() + " replicas: " + replicationControllerSpec.getReplicas() + " replicatorSelector: " + replicationControllerSpec.getSelector() + " podTemplate: " + replicationControllerSpec.getTemplate());
} else {
System.out.println("ReplicationController " + KubernetesHelper.getName(item) + " labels: " + item.getMetadata().getLabels() + " no replicationControllerSpec");
}
}
System.out.println();
}
use of io.fabric8.kubernetes.api.model.PodTemplate in project flink by apache.
the class KubernetesJobManagerFactory method buildKubernetesJobManagerSpecification.
public static KubernetesJobManagerSpecification buildKubernetesJobManagerSpecification(FlinkPod podTemplate, KubernetesJobManagerParameters kubernetesJobManagerParameters) throws IOException {
FlinkPod flinkPod = Preconditions.checkNotNull(podTemplate).copy();
List<HasMetadata> accompanyingResources = new ArrayList<>();
final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitJobManagerDecorator(kubernetesJobManagerParameters), new EnvSecretsDecorator(kubernetesJobManagerParameters), new MountSecretsDecorator(kubernetesJobManagerParameters), new CmdJobManagerDecorator(kubernetesJobManagerParameters), new InternalServiceDecorator(kubernetesJobManagerParameters), new ExternalServiceDecorator(kubernetesJobManagerParameters), new HadoopConfMountDecorator(kubernetesJobManagerParameters), new KerberosMountDecorator(kubernetesJobManagerParameters), new FlinkConfMountDecorator(kubernetesJobManagerParameters), new PodTemplateMountDecorator(kubernetesJobManagerParameters) };
for (KubernetesStepDecorator stepDecorator : stepDecorators) {
flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
accompanyingResources.addAll(stepDecorator.buildAccompanyingKubernetesResources());
}
final Deployment deployment = createJobManagerDeployment(flinkPod, kubernetesJobManagerParameters);
return new KubernetesJobManagerSpecification(deployment, accompanyingResources);
}
Aggregations