use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConditionUtilsTest method testBuildUpdateCondition.
@ParameterizedTest
@ValueSource(strings = { "Ready" })
void testBuildUpdateCondition(String type) {
ManagedKafkaCondition mkcondition = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.valueOf(type), Status.True);
assertEquals("True", mkcondition.getStatus());
assertEquals(type, mkcondition.getType());
ConditionUtils.updateConditionStatus(mkcondition, Status.False, null, null);
assertEquals("False", mkcondition.getStatus());
assertEquals(type, mkcondition.getType());
var mockCondition = Mockito.mock(ManagedKafkaCondition.class, Mockito.CALLS_REAL_METHODS);
ConditionUtils.updateConditionStatus(mockCondition, Status.False, Reason.Deleted, null);
Mockito.verify(mockCondition, Mockito.times(1)).setLastTransitionTime(Mockito.anyString());
// only update if different
ConditionUtils.updateConditionStatus(mockCondition, Status.False, Reason.Deleted, null);
Mockito.verify(mockCondition, Mockito.times(1)).setLastTransitionTime(Mockito.anyString());
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition 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.resources.v1alpha1.ManagedKafkaCondition 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.resources.v1alpha1.ManagedKafkaCondition in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziBundleManager method updateStatus.
/**
* Update status of ManagedKafkaAgent resource about approval of Strimzi bundle installation
* NOTE: it creates a condition if Strimzi bundle installation was not approved. The condition is taken out if approved.
*
* @param approval the status of the approval
*/
private void updateStatus(Approval approval) {
ManagedKafkaAgent resource = this.agentClient.getByName(this.agentClient.getNamespace(), ManagedKafkaAgentResourceClient.RESOURCE_NAME);
if (resource != null && resource.getStatus() != null) {
List<ManagedKafkaCondition> conditions = resource.getStatus().getConditions();
ManagedKafkaCondition bundleReadyCondition = ConditionUtils.findManagedKafkaCondition(conditions, ManagedKafkaCondition.Type.StrimziBundleReady).orElse(null);
ManagedKafkaCondition.Reason reason = ManagedKafkaCondition.Reason.OrphanedKafkas;
ManagedKafkaCondition.Status status = ManagedKafkaCondition.Status.False;
if (approval != Approval.ORPHANED) {
if (bundleReadyCondition == null) {
return;
}
conditions.remove(bundleReadyCondition);
} else {
if (bundleReadyCondition == null) {
bundleReadyCondition = ConditionUtils.buildCondition(ManagedKafkaCondition.Type.StrimziBundleReady, status);
bundleReadyCondition.reason(reason);
conditions.add(bundleReadyCondition);
} else {
ConditionUtils.updateConditionStatus(bundleReadyCondition, status, reason, null);
}
}
this.agentClient.replaceStatus(resource);
}
}
use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaResourceType method readiness.
@Override
public Predicate<ManagedKafka> readiness(KubeClient client) {
AtomicInteger count = new AtomicInteger();
Set<String> messages = Collections.synchronizedSet(new LinkedHashSet<>());
return mk -> {
if (mk == null) {
throw new IllegalStateException("ManagedKafka is null");
}
ManagedKafkaCondition mkc = getCondition(mk.getStatus(), ManagedKafkaCondition.Type.Ready).orElse(null);
if (mkc == null) {
return false;
}
if (ManagedKafkaCondition.Status.True.name().equals(mkc.getStatus())) {
return true;
}
if (ManagedKafkaCondition.Reason.Error.name().equals(mkc.getReason())) {
if (messages.add(mkc.getMessage())) {
LOGGER.warn("ManagedKafka {} in error state {}", mk.getMetadata().getName(), mkc.getMessage());
}
// throw new IllegalStateException(String.format("ManagedKafka %s in error state %s", mk.getMetadata().getName(), mkc.getMessage()));
}
if (count.getAndIncrement() % 15 == 0) {
ListOptions opts = new ListOptionsBuilder().withFieldSelector("status.phase=Pending").build();
client.client().pods().inNamespace(mk.getMetadata().getNamespace()).withLabel("strimzi.io/cluster").list(opts).getItems().forEach(ManagedKafkaResourceType::checkUnschedulablePod);
}
return false;
};
}
Aggregations