Search in sources :

Example 1 with StrimziVersionStatusBuilder

use of org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder 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());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) EventList(io.javaoperatorsdk.operator.processing.event.EventList) StrimziManager(org.bf2.operator.managers.StrimziManager) CustomResourceEvent(io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with StrimziVersionStatusBuilder

use of org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder 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());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) EventList(io.javaoperatorsdk.operator.processing.event.EventList) StrimziManager(org.bf2.operator.managers.StrimziManager) CustomResourceEvent(io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent) ManagedKafkaCondition(org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 3 with StrimziVersionStatusBuilder

use of org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class StrimziManager method setStrimziPendingInstallationVersions.

/**
 * Notify the strimzi manager of pending versions.
 * @param pendingVersions
 * @return true if the pending state has changed
 */
public boolean setStrimziPendingInstallationVersions(List<String> pendingVersions) {
    if (!Collections.disjoint(strimziPendingInstallationVersions.keySet(), pendingVersions)) {
        return false;
    }
    log.infof("Notified of pending strimzi versions %s", pendingVersions);
    ConcurrentHashMap<String, StrimziVersionStatus> next = new ConcurrentHashMap<>();
    for (String version : pendingVersions) {
        StrimziVersionStatus existing = strimziVersions.get(version);
        if (existing != null) {
            next.put(version, new StrimziVersionStatusBuilder(existing).withReady(false).build());
        } else {
            next.put(version, EMPTY_STATUS);
        }
    }
    this.strimziPendingInstallationVersions = next;
    informerManager.resyncManagedKafkaAgent();
    return true;
}
Also used : StrimziVersionStatus(org.bf2.operator.resources.v1alpha1.StrimziVersionStatus) StrimziVersionStatusBuilder(org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

StrimziVersionStatusBuilder (org.bf2.operator.resources.v1alpha1.StrimziVersionStatusBuilder)3 EventList (io.javaoperatorsdk.operator.processing.event.EventList)2 CustomResourceEvent (io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 StrimziManager (org.bf2.operator.managers.StrimziManager)2 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)2 ManagedKafkaCondition (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)2 Test (org.junit.jupiter.api.Test)2 OwnerReferenceBuilder (io.fabric8.kubernetes.api.model.OwnerReferenceBuilder)1 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 StrimziVersionStatus (org.bf2.operator.resources.v1alpha1.StrimziVersionStatus)1