use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class ReplicaSetHandlerTest method replicaSetHandlerTest.
@Test
public void replicaSetHandlerTest() {
ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
ReplicaSet replicaSet = replicaSetHandler.get(config, images);
// Assertion
assertNotNull(replicaSet.getSpec());
assertNotNull(replicaSet.getMetadata());
assertEquals(5, replicaSet.getSpec().getReplicas().intValue());
assertNotNull(replicaSet.getSpec().getTemplate());
assertEquals("testing", replicaSet.getMetadata().getName());
assertEquals("test-account", replicaSet.getSpec().getTemplate().getSpec().getServiceAccountName());
assertFalse(replicaSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
assertEquals("test", replicaSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
assertEquals("/test/path", replicaSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
assertNotNull(replicaSet.getSpec().getTemplate().getSpec().getContainers());
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class ReplicationControllerHandlerTest method replicationControllerHandlerWithoutControllerTest.
@Test(expected = IllegalArgumentException.class)
public void replicationControllerHandlerWithoutControllerTest() {
// without controller name
ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
replicationControllerHandler.get(config, images);
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class ReplicationControllerHandlerTest method replicationControllerHandlerTest.
@Test
public void replicationControllerHandlerTest() {
ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
ReplicationController replicationController = replicationControllerHandler.get(config, images);
// Assertion
assertNotNull(replicationController.getSpec());
assertNotNull(replicationController.getMetadata());
assertEquals(5, replicationController.getSpec().getReplicas().intValue());
assertNotNull(replicationController.getSpec().getTemplate());
assertEquals("testing", replicationController.getMetadata().getName());
assertEquals("test-account", replicationController.getSpec().getTemplate().getSpec().getServiceAccountName());
assertFalse(replicationController.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
assertEquals("test", replicationController.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
assertEquals("/test/path", replicationController.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
assertNotNull(replicationController.getSpec().getTemplate().getSpec().getContainers());
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig in project jkube by eclipse.
the class StatefulSetHandlerTest method statefulSetHandlerTest.
@Test
public void statefulSetHandlerTest() {
ResourceConfig config = ResourceConfig.builder().imagePullPolicy("IfNotPresent").controllerName("testing").serviceAccount("test-account").replicas(5).volumes(volumes1).build();
StatefulSet statefulSet = statefulSetHandler.get(config, images);
// Assertion
assertNotNull(statefulSet.getSpec());
assertNotNull(statefulSet.getMetadata());
assertEquals(5, statefulSet.getSpec().getReplicas().intValue());
assertNotNull(statefulSet.getSpec().getTemplate());
assertEquals("testing", statefulSet.getMetadata().getName());
assertEquals("testing", statefulSet.getSpec().getServiceName());
assertEquals("test-account", statefulSet.getSpec().getTemplate().getSpec().getServiceAccountName());
assertFalse(statefulSet.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
assertEquals("test", statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
assertEquals("/test/path", statefulSet.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
assertNotNull(statefulSet.getSpec().getTemplate().getSpec().getContainers());
}
use of org.eclipse.jkube.kit.config.resource.ResourceConfig 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));
}
}
});
}
}
}
}
}
Aggregations