use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class ModelUtilsTest method testParsePodDisruptionBudgetTemplate.
@Test
public void testParsePodDisruptionBudgetTemplate() {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().build();
PodDisruptionBudgetTemplate template = new PodDisruptionBudgetTemplateBuilder().withNewMetadata().withAnnotations(Collections.singletonMap("annoKey", "annoValue")).withLabels(Collections.singletonMap("labelKey", "labelValue")).endMetadata().withMaxUnavailable(2).build();
Model model = new Model(Reconciliation.DUMMY_RECONCILIATION, kafka);
ModelUtils.parsePodDisruptionBudgetTemplate(model, template);
assertThat(model.templatePodDisruptionBudgetLabels, is(Collections.singletonMap("labelKey", "labelValue")));
assertThat(model.templatePodDisruptionBudgetAnnotations, is(Collections.singletonMap("annoKey", "annoValue")));
assertThat(model.templatePodDisruptionBudgetMaxUnavailable, is(2));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class ModelUtilsTest method testEmptyTolerations.
@ParallelTest
public void testEmptyTolerations() {
Toleration t1 = new TolerationBuilder().withValue("").withEffect("NoExecute").build();
Toleration t2 = new TolerationBuilder().withValue(null).withEffect("NoExecute").build();
PodTemplate pt1 = new PodTemplate();
pt1.setTolerations(singletonList(t1));
PodTemplate pt2 = new PodTemplate();
pt2.setTolerations(singletonList(t2));
Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().withNewSpec().withNewKafka().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().withListeners(new GenericKafkaListenerBuilder().withType(KafkaListenerType.INTERNAL).withPort(9092).withName("plain").withTls(false).build()).endKafka().endSpec().build();
KafkaCluster model1 = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
ModelUtils.parsePodTemplate(model1, pt1);
KafkaCluster model2 = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, KafkaVersionTestUtils.getKafkaVersionLookup());
ModelUtils.parsePodTemplate(model2, pt2);
assertThat(model1.getTolerations(), is(model2.getTolerations()));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class ModelUtilsTest method testParseNullInternalServiceTemplate.
@Test
public void testParseNullInternalServiceTemplate() {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName("my-cluster").withNamespace("my-namespace").endMetadata().build();
Model model = new Model(Reconciliation.DUMMY_RECONCILIATION, kafka);
ModelUtils.parseInternalServiceTemplate(model, null);
assertThat(model.templateServiceLabels, is(nullValue()));
assertThat(model.templateServiceAnnotations, is(nullValue()));
assertThat(model.templateServiceIpFamilies, is(nullValue()));
assertThat(model.templateServiceIpFamilyPolicy, is(nullValue()));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class JbodStorageTest method init.
@BeforeEach
private void init() {
this.volumes = new ArrayList<>(2);
volumes.add(new PersistentClaimStorageBuilder().withId(0).withDeleteClaim(true).withSize("100Gi").build());
volumes.add(new PersistentClaimStorageBuilder().withId(1).withDeleteClaim(false).withSize("100Gi").build());
this.kafka = new KafkaBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(NAME).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build()).withNewJbodStorage().withVolumes(volumes).endJbodStorage().endKafka().withNewZookeeper().withReplicas(1).endZookeeper().endSpec().build();
// setting up the Kafka CRD
CustomResourceDefinition kafkaAssemblyCrd = Crds.kafka();
// setting up a mock Kubernetes client
this.mockClient = new MockKube().withCustomResourceDefinition(kafkaAssemblyCrd, Kafka.class, KafkaList.class).end().withCustomResourceDefinition(Crds.strimziPodSet(), StrimziPodSet.class, StrimziPodSetList.class).end().build();
// initialize a Kafka in MockKube
Crds.kafkaOperation(this.mockClient).inNamespace(NAMESPACE).withName(NAME).create(this.kafka);
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16);
// creating the Kafka operator
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(this.vertx, this.mockClient, ResourceUtils.zookeeperLeaderFinder(this.vertx, this.mockClient), ResourceUtils.adminClientProvider(), ResourceUtils.zookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, FeatureGates.NONE, 60_000L);
this.operator = new KafkaAssemblyOperator(this.vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), ros, ResourceUtils.dummyClusterOperatorConfig(VERSIONS, 2_000));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class JbodStorageTest method testReconcileWithNewVolumeAddedToJbodStorage.
@Test
public void testReconcileWithNewVolumeAddedToJbodStorage(VertxTestContext context) {
Checkpoint async = context.checkpoint();
// Add a new volume to Jbod Storage
volumes.add(new PersistentClaimStorageBuilder().withId(2).withDeleteClaim(false).withSize("100Gi").build());
Kafka kafkaWithNewJbodVolume = new KafkaBuilder(kafka).editSpec().editKafka().withStorage(new JbodStorageBuilder().withVolumes(volumes).build()).endKafka().endSpec().build();
Set<String> expectedPvcs = expectedPvcs(kafka);
Set<String> expectedPvcsWithNewJbodStorageVolume = expectedPvcs(kafkaWithNewJbodVolume);
// reconcile for kafka cluster creation
operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME)).onComplete(context.succeeding(v -> context.verify(() -> {
List<PersistentVolumeClaim> pvcs = getPvcs(NAMESPACE, NAME);
Set<String> pvcsNames = pvcs.stream().map(pvc -> pvc.getMetadata().getName()).collect(Collectors.toSet());
assertThat(pvcsNames, is(expectedPvcs));
}))).compose(v -> {
Crds.kafkaOperation(mockClient).inNamespace(NAMESPACE).withName(NAME).patch(kafkaWithNewJbodVolume);
// reconcile kafka cluster with new Jbod storage
return operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
List<PersistentVolumeClaim> pvcs = getPvcs(NAMESPACE, NAME);
Set<String> pvcsNames = pvcs.stream().map(pvc -> pvc.getMetadata().getName()).collect(Collectors.toSet());
assertThat(pvcsNames, is(expectedPvcsWithNewJbodStorageVolume));
async.flag();
})));
}
Aggregations