use of org.bf2.operator.operands.KafkaInstanceConfiguration.Kafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaControllerTest method shouldCreateStatus.
@Test
void shouldCreateStatus() throws InterruptedException {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getMetadata().setUid(UUID.randomUUID().toString());
mk.getMetadata().setGeneration(1l);
mk.getMetadata().setResourceVersion("1");
// create
Context<ManagedKafka> context = Mockito.mock(Context.class);
Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
StrimziManager strimziManager = Mockito.mock(StrimziManager.class);
Mockito.when(strimziManager.getStrimziVersion("strimzi-cluster-operator.v0.23.0")).thenReturn(new StrimziVersionStatusBuilder().withVersion(mk.getSpec().getVersions().getStrimzi()).withKafkaVersions(mk.getSpec().getVersions().getKafka()).build());
Mockito.when(strimziManager.getVersionLabel()).thenReturn("managedkafka.bf2.org/strimziVersion");
QuarkusMock.installMockForType(strimziManager, StrimziManager.class);
mkController.createOrUpdateResource(mk, context);
ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
assertEquals(ManagedKafkaCondition.Reason.Installing.name(), condition.getReason());
mk.getSpec().setDeleted(true);
// this simulates, but not exactly an issue seen with older logic
// essentially there "last event" of the delete is something other than a deployment or a kafka
// it should still trigger the update of the status
Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new ResourceEvent<>(new ServiceBuilder().withNewMetadata().withOwnerReferences(new OwnerReferenceBuilder().withUid(mk.getMetadata().getUid()).build()).endMetadata().build(), null, Watcher.Action.DELETED))));
mkController.createOrUpdateResource(mk, context);
// should now be deleted
condition = mk.getStatus().getConditions().get(0);
assertEquals(ManagedKafkaCondition.Reason.Deleted.name(), condition.getReason());
}
use of org.bf2.operator.operands.KafkaInstanceConfiguration.Kafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaControllerTest method testWrongVersions.
@Test
void testWrongVersions() throws InterruptedException {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getMetadata().setUid(UUID.randomUUID().toString());
mk.getMetadata().setGeneration(1l);
mk.getMetadata().setResourceVersion("1");
// create
Context<ManagedKafka> context = Mockito.mock(Context.class);
Mockito.when(context.getEvents()).thenReturn(new EventList(Arrays.asList(new CustomResourceEvent(Action.ADDED, mk, null))));
StrimziManager strimziManager = Mockito.mock(StrimziManager.class);
Mockito.when(strimziManager.getVersionLabel()).thenReturn("managedkafka.bf2.org/strimziVersion");
QuarkusMock.installMockForType(strimziManager, StrimziManager.class);
mkController.createOrUpdateResource(mk, context);
ManagedKafkaCondition condition = mk.getStatus().getConditions().get(0);
assertEquals(ManagedKafkaCondition.Reason.Error.name(), condition.getReason());
assertEquals("The requested Strimzi version strimzi-cluster-operator.v0.23.0 is not supported", condition.getMessage());
Mockito.when(strimziManager.getStrimziVersion("strimzi-cluster-operator.v0.23.0")).thenReturn(new StrimziVersionStatusBuilder().withVersion(mk.getSpec().getVersions().getStrimzi()).withKafkaVersions("3.0.0").build());
mkController.createOrUpdateResource(mk, context);
condition = mk.getStatus().getConditions().get(0);
assertEquals(ManagedKafkaCondition.Reason.Error.name(), condition.getReason());
assertEquals("The requested Kafka version 2.7.0 is not supported by the Strimzi version strimzi-cluster-operator.v0.23.0", condition.getMessage());
}
use of org.bf2.operator.operands.KafkaInstanceConfiguration.Kafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class IngressControllerManagerTest method testSummarize.
@Test
public void testSummarize() {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
Kafka kafka = this.kafkaCluster.kafkaFrom(mk, null);
int replicas = kafka.getSpec().getKafka().getReplicas();
int instances = 4;
LongSummaryStatistics egress = IngressControllerManager.summarize(Collections.nCopies(instances, kafka), KafkaCluster::getFetchQuota, () -> {
throw new AssertionError();
});
long singleEgress = Quantity.getAmountInBytes(mk.getSpec().getCapacity().getEgressPerSec()).longValue() / replicas * replicas;
assertEquals(singleEgress, egress.getMax());
assertEquals(singleEgress * instances, egress.getSum());
}
use of org.bf2.operator.operands.KafkaInstanceConfiguration.Kafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class IngressControllerManagerTest method testReplicaReduction.
@Test
public void testReplicaReduction() {
openShiftClient.resourceList((List) buildNodes(12)).createOrReplace();
IntStream.range(0, 6).forEach(i -> {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getMetadata().setName("ingressTest" + i);
mk.getMetadata().setNamespace("ingressTest");
mk.getSpec().getCapacity().setIngressPerSec(Quantity.parse("125Mi"));
Kafka kafka = this.kafkaCluster.kafkaFrom(mk, null);
openShiftClient.resource(kafka).createOrReplace();
});
informerManager.createKafkaInformer();
ingressControllerManager.reconcileIngressControllers();
checkAzReplicaCount(4);
// remove two kafkas - we should keep the same number of replicas
var kafkas = openShiftClient.resources(Kafka.class).inNamespace("ingressTest");
assertTrue(kafkas.withName("ingressTest0").delete());
assertTrue(kafkas.withName("ingressTest1").delete());
ingressControllerManager.reconcileIngressControllers();
checkAzReplicaCount(4);
// remove two more kafkas - and we should reduce
assertTrue(kafkas.withName("ingressTest2").delete());
assertTrue(kafkas.withName("ingressTest3").delete());
ingressControllerManager.reconcileIngressControllers();
checkAzReplicaCount(2);
}
use of org.bf2.operator.operands.KafkaInstanceConfiguration.Kafka in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziManager method currentStrimziVersion.
/**
* Returns the current Strimzi version for the Kafka instance
* It comes directly from the Kafka custom resource label or from the ManagedKafka in case of creation
*
* @param managedKafka ManagedKafka instance
* @return current Strimzi version for the Kafka instance
*/
public String currentStrimziVersion(ManagedKafka managedKafka) {
Kafka kafka = cachedKafka(managedKafka);
// on first time Kafka resource creation, we take the Strimzi version from the ManagedKafka resource spec
String kafkaStrimziVersion = kafka != null && kafka.getMetadata().getLabels() != null && kafka.getMetadata().getLabels().containsKey(this.versionLabel) ? kafka.getMetadata().getLabels().get(this.versionLabel) : managedKafka.getSpec().getVersions().getStrimzi();
log.debugf("currentStrimziVersion = %s", kafkaStrimziVersion);
return kafkaStrimziVersion;
}
Aggregations