use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project fabric8-maven-plugin by fabric8io.
the class ImageEnricherTest method checkEnrichStatefulSet.
@Test
public void checkEnrichStatefulSet() throws Exception {
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new StatefulSetBuilder().build());
imageEnricher.create(PlatformMode.kubernetes, builder);
assertCorrectlyGeneratedResources(builder.build(), "StatefulSet");
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder 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.apps.StatefulSetBuilder in project strimzi by strimzi.
the class StatefulSetDiffTest method testPvcSizeUnitChangeIgnored.
@Test
public void testPvcSizeUnitChangeIgnored() {
StatefulSet ss1 = new StatefulSetBuilder().withNewMetadata().withNamespace("test").withName("foo").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addToVolumes(0, new VolumeBuilder().withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(1).build()).build()).endSpec().endTemplate().withVolumeClaimTemplates(new PersistentVolumeClaimBuilder().withNewSpec().withNewResources().withRequests(singletonMap("storage", new Quantity("3072Gi"))).endResources().endSpec().build()).endSpec().build();
StatefulSet ss2 = new StatefulSetBuilder().withNewMetadata().withNamespace("test").withName("foo").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addToVolumes(0, new VolumeBuilder().withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(2).build()).build()).endSpec().endTemplate().withVolumeClaimTemplates(new PersistentVolumeClaimBuilder().withNewSpec().withNewResources().withRequests(singletonMap("storage", new Quantity("3Ti"))).endResources().endSpec().build()).endSpec().build();
assertThat(new StatefulSetDiff(Reconciliation.DUMMY_RECONCILIATION, ss1, ss2).changesVolumeClaimTemplates(), is(false));
assertThat(new StatefulSetDiff(Reconciliation.DUMMY_RECONCILIATION, ss1, ss2).changesVolumeSize(), is(false));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi by strimzi.
the class MockKubeRegressionTest method testStatefulSetCreationAndDeletion.
@Test
public void testStatefulSetCreationAndDeletion() {
StatefulSet sts = new StatefulSetBuilder().withNewMetadata().withName("foo").withNamespace("ns").endMetadata().withNewSpec().withReplicas(3).withNewTemplate().withNewMetadata().endMetadata().withNewSpec().endSpec().endTemplate().endSpec().build();
client.apps().statefulSets().inNamespace("ns").withName("foo").create(sts);
List<Pod> ns = client.pods().inNamespace("ns").list().getItems();
assertThat(ns, hasSize(3));
AtomicBoolean deleted = new AtomicBoolean(false);
AtomicBoolean recreated = new AtomicBoolean(false);
Watch watch = client.pods().inNamespace("ns").withName(ns.get(0).getMetadata().getName()).watch(new Watcher<Pod>() {
@Override
public void eventReceived(Action action, Pod resource) {
if (action == Action.DELETED) {
if (deleted.getAndSet(true)) {
fail("Deleted twice");
}
} else if (action == Action.ADDED) {
if (!deleted.get()) {
fail("Created before deleted");
}
if (recreated.getAndSet(true)) {
fail("Recreated twice");
}
}
}
@Override
public void onClose(WatcherException cause) {
}
});
client.pods().inNamespace("ns").withName(ns.get(0).getMetadata().getName()).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
assertThat(deleted.get(), is(true));
assertThat(recreated.get(), is(true));
watch.close();
ns = client.pods().inNamespace("ns").list().getItems();
assertThat(ns, hasSize(3));
client.apps().statefulSets().inNamespace("ns").withName("foo").withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi by strimzi.
the class TolerationsIT method testEmptyStringValueIntoleration.
@Test
public void testEmptyStringValueIntoleration(VertxTestContext context) {
Toleration t1 = new TolerationBuilder().withEffect("NoSchedule").withValue("").build();
List<Toleration> tolerationList = new ArrayList<>();
tolerationList.add(t1);
// CO does this over the generated STS
tolerationList = ModelUtils.removeEmptyValuesFromTolerations(tolerationList);
StatefulSet ss = new StatefulSetBuilder().withNewMetadata().withNamespace(namespace).withName("foo").endMetadata().withNewSpec().withSelector(new LabelSelectorBuilder().withMatchLabels(Collections.singletonMap("app", "test")).build()).withNewTemplate().withNewMetadata().withLabels(Collections.singletonMap("app", "test")).endMetadata().withNewSpec().withTolerations(tolerationList).withDnsPolicy("ClusterFirst").withRestartPolicy("Always").withSchedulerName("default-scheduler").withSecurityContext(null).withTerminationGracePeriodSeconds(30L).endSpec().endTemplate().endSpec().build();
KubernetesClient client = new DefaultKubernetesClient();
client.apps().statefulSets().inNamespace(namespace).create(ss);
StatefulSet stsk8s = client.apps().statefulSets().inNamespace(namespace).withName("foo").get();
StatefulSetDiff diff = new StatefulSetDiff(Reconciliation.DUMMY_RECONCILIATION, ss, stsk8s);
Checkpoint checkpoint = context.checkpoint();
context.verify(() -> {
assertThat(diff.changesSpecTemplate(), is(false));
assertThat(stsk8s.getSpec().getTemplate().getSpec().getTolerations().get(0).getValue(), is(nullValue()));
assertThat(ss.getSpec().getTemplate().getSpec().getTolerations().get(0).getValue(), is(nullValue()));
checkpoint.flag();
});
}
Aggregations