use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class DefaultServiceEnricherTest method setupExpectations.
private void setupExpectations(final boolean withPorts, String... configParams) {
// Setup mock behaviour
final TreeMap<String, Object> config = new TreeMap<>();
for (int i = 0; i < configParams.length; i += 2) {
config.put(configParams[i], configParams[i + 1]);
}
new Expectations() {
{
Configuration configuration = Configuration.builder().image(imageConfiguration).processorConfig(new ProcessorConfig(null, null, Collections.singletonMap("jkube-service", config))).build();
context.getConfiguration();
result = configuration;
imageConfiguration.getBuildConfiguration();
result = initBuildConfig(withPorts);
}
};
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class ControllerViaPluginConfigurationEnricher method create.
@Override
public void create(PlatformMode platformMode, KubernetesListBuilder builder) {
final String name = getConfig(Config.NAME, JKubeProjectUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId()));
ResourceConfig xmlResourceConfig = getConfiguration().getResource();
final ResourceConfig config = ResourceConfig.builder().controllerName(name).imagePullPolicy(getImagePullPolicy(xmlResourceConfig, getConfig(Config.PULL_POLICY))).replicas(getReplicaCount(builder, xmlResourceConfig, Configs.asInt(getConfig(Config.REPLICA_COUNT)))).build();
final List<ImageConfiguration> images = getImages();
// 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.get(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.get(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 org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class ContainerHandlerTest method getImageNameTest.
@Test
public void getImageNameTest() {
ContainerHandler handler = createContainerHandler(project);
// Image Configuration with name and without registry
ImageConfiguration imageConfiguration2 = ImageConfiguration.builder().name("test").alias("test-app").build(buildImageConfiguration1).build();
// Image Configuration without name and with registry
ImageConfiguration imageConfiguration3 = ImageConfiguration.builder().alias("test-app").build(buildImageConfiguration1).registry("docker.io").build();
// Image Configuration without name and registry
ImageConfiguration imageConfiguration4 = ImageConfiguration.builder().alias("test-app").build(buildImageConfiguration1).registry("docker.io").build();
images.clear();
images.add(imageConfiguration1);
images.add(imageConfiguration2);
images.add(imageConfiguration3);
images.add(imageConfiguration4);
containers = handler.getContainers(config1, images);
assertEquals("docker.io/test:latest", containers.get(0).getImage());
assertEquals("test:latest", containers.get(1).getImage());
assertNull(containers.get(2).getImage());
assertNull(containers.get(3).getImage());
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class DeploymentConfigHandlerTest method get_withNoImages_shouldReturnConfigWithNoContainers.
@Test
public void get_withNoImages_shouldReturnConfigWithNoContainers() {
// Given
final ResourceConfig resourceConfig = resourceConfigBuilder.controllerName("controller").build();
final List<ImageConfiguration> images = Collections.emptyList();
// When
final DeploymentConfig result = deploymentConfigHandler.get(resourceConfig, images);
// Then
assertThat(result).hasFieldOrPropertyWithValue("metadata.name", "controller").extracting("spec.template.spec.containers").asList().isEmpty();
}
use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.
the class DeploymentHandlerTest method before.
@Before
public void before() {
// volume config with name and multiple mount
mounts.add("/path/system");
mounts.add("/path/sys");
ports.add("8080");
ports.add("9090");
tags.add("latest");
tags.add("test");
VolumeConfig volumeConfig1 = VolumeConfig.builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
volumes1.add(volumeConfig1);
// container name with alias
final BuildConfiguration buildImageConfiguration = BuildConfiguration.builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compressionString("gzip").build();
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test").alias("test-app").build(buildImageConfiguration).registry("docker.io").build();
images.add(imageConfiguration);
deploymentHandler = new DeploymentHandler(new PodTemplateHandler(new ContainerHandler(project.getProperties(), new GroupArtifactVersion("g", "a", "v"), probeHandler)));
}
Aggregations