use of io.strimzi.api.kafka.model.status.KafkaUserStatus in project strimzi by strimzi.
the class KafkaUserOperatorTest method testReconcileAllWithoutAcls.
@Test
public void testReconcileAllWithoutAcls(VertxTestContext context) {
CrdOperator mockCrdOps = mock(CrdOperator.class);
SecretOperator mockSecretOps = mock(SecretOperator.class);
SimpleAclOperator aclOps = mock(SimpleAclOperator.class);
ScramCredentialsOperator scramOps = mock(ScramCredentialsOperator.class);
QuotasOperator quotasOps = mock(QuotasOperator.class);
KafkaUser newTlsUser = ResourceUtils.createKafkaUserTls();
newTlsUser.getMetadata().setName("new-tls-user");
KafkaUser newScramShaUser = ResourceUtils.createKafkaUserScramSha();
newScramShaUser.getMetadata().setName("new-scram-sha-user");
KafkaUser existingTlsUser = ResourceUtils.createKafkaUserTls();
existingTlsUser.getMetadata().setName("existing-tls-user");
Secret clientsCa = ResourceUtils.createClientsCaCertSecret();
Secret existingTlsUserSecret = ResourceUtils.createUserSecretTls();
existingTlsUserSecret.getMetadata().setName("existing-tls-user");
Secret existingScramShaUserSecret = ResourceUtils.createUserSecretScramSha();
existingScramShaUserSecret.getMetadata().setName("existing-scram-sha-user");
KafkaUser existingScramShaUser = ResourceUtils.createKafkaUserTls();
existingScramShaUser.getMetadata().setName("existing-scram-sha-user");
when(mockCrdOps.listAsync(eq(ResourceUtils.NAMESPACE), eq(Optional.of(new LabelSelector(null, Labels.fromMap(ResourceUtils.LABELS).toMap()))))).thenReturn(Future.succeededFuture(Arrays.asList(newTlsUser, newScramShaUser, existingTlsUser, existingScramShaUser)));
when(mockSecretOps.list(eq(ResourceUtils.NAMESPACE), eq(Labels.fromMap(ResourceUtils.LABELS).withStrimziKind(KafkaUser.RESOURCE_KIND)))).thenReturn(Arrays.asList(existingTlsUserSecret, existingScramShaUserSecret));
when(scramOps.getAllUsers()).thenReturn(Future.succeededFuture(List.of("existing-tls-user", "deleted-scram-sha-user")));
when(quotasOps.getAllUsers()).thenReturn(Future.succeededFuture(Set.of("existing-tls-user", "quota-user")));
when(mockCrdOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(newTlsUser);
when(mockCrdOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(newScramShaUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUser);
when(mockCrdOps.getAsync(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newTlsUser));
when(mockCrdOps.getAsync(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newScramShaUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingTlsUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingScramShaUser));
when(mockCrdOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
when(mockSecretOps.get(eq(clientsCa.getMetadata().getNamespace()), eq(clientsCa.getMetadata().getName()))).thenReturn(clientsCa);
when(mockSecretOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUserSecret);
when(mockSecretOps.get(eq(existingScramShaUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUserSecret);
Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
Set<String> deleted = new CopyOnWriteArraySet<>();
Checkpoint async = context.checkpoint();
Promise reconcileAllCompleted = Promise.promise();
KafkaUserOperator op = new KafkaUserOperator(vertx, mockCertManager, mockCrdOps, mockSecretOps, scramOps, quotasOps, aclOps, ResourceUtils.createUserOperatorConfig(ResourceUtils.LABELS, false, "12")) {
@Override
public Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
createdOrUpdated.add(resource.getMetadata().getName());
return Future.succeededFuture(new KafkaUserStatus());
}
@Override
public Future<Boolean> delete(Reconciliation reconciliation) {
deleted.add(reconciliation.name());
return Future.succeededFuture(Boolean.TRUE);
}
};
// call reconcileAll and pass in promise to the handler to run assertions on completion
op.reconcileAll("test", ResourceUtils.NAMESPACE, ar -> reconcileAllCompleted.complete());
reconcileAllCompleted.future().compose(v -> context.verify(() -> {
assertThat(createdOrUpdated, is(new HashSet(asList("new-tls-user", "existing-tls-user", "new-scram-sha-user", "existing-scram-sha-user"))));
assertThat(deleted, is(new HashSet(asList("quota-user", "deleted-scram-sha-user"))));
verify(aclOps, never()).getAllUsers();
async.flag();
}));
}
use of io.strimzi.api.kafka.model.status.KafkaUserStatus in project strimzi-kafka-operator by strimzi.
the class KafkaUserOperatorTest method testReconcileAllWithoutAcls.
@Test
public void testReconcileAllWithoutAcls(VertxTestContext context) {
CrdOperator mockCrdOps = mock(CrdOperator.class);
SecretOperator mockSecretOps = mock(SecretOperator.class);
SimpleAclOperator aclOps = mock(SimpleAclOperator.class);
ScramCredentialsOperator scramOps = mock(ScramCredentialsOperator.class);
QuotasOperator quotasOps = mock(QuotasOperator.class);
KafkaUser newTlsUser = ResourceUtils.createKafkaUserTls();
newTlsUser.getMetadata().setName("new-tls-user");
KafkaUser newScramShaUser = ResourceUtils.createKafkaUserScramSha();
newScramShaUser.getMetadata().setName("new-scram-sha-user");
KafkaUser existingTlsUser = ResourceUtils.createKafkaUserTls();
existingTlsUser.getMetadata().setName("existing-tls-user");
Secret clientsCa = ResourceUtils.createClientsCaCertSecret();
Secret existingTlsUserSecret = ResourceUtils.createUserSecretTls();
existingTlsUserSecret.getMetadata().setName("existing-tls-user");
Secret existingScramShaUserSecret = ResourceUtils.createUserSecretScramSha();
existingScramShaUserSecret.getMetadata().setName("existing-scram-sha-user");
KafkaUser existingScramShaUser = ResourceUtils.createKafkaUserTls();
existingScramShaUser.getMetadata().setName("existing-scram-sha-user");
when(mockCrdOps.listAsync(eq(ResourceUtils.NAMESPACE), eq(Optional.of(new LabelSelector(null, Labels.fromMap(ResourceUtils.LABELS).toMap()))))).thenReturn(Future.succeededFuture(Arrays.asList(newTlsUser, newScramShaUser, existingTlsUser, existingScramShaUser)));
when(mockSecretOps.list(eq(ResourceUtils.NAMESPACE), eq(Labels.fromMap(ResourceUtils.LABELS).withStrimziKind(KafkaUser.RESOURCE_KIND)))).thenReturn(Arrays.asList(existingTlsUserSecret, existingScramShaUserSecret));
when(scramOps.getAllUsers()).thenReturn(Future.succeededFuture(List.of("existing-tls-user", "deleted-scram-sha-user")));
when(quotasOps.getAllUsers()).thenReturn(Future.succeededFuture(Set.of("existing-tls-user", "quota-user")));
when(mockCrdOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(newTlsUser);
when(mockCrdOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(newScramShaUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUser);
when(mockCrdOps.getAsync(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newTlsUser));
when(mockCrdOps.getAsync(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newScramShaUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingTlsUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingScramShaUser));
when(mockCrdOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
when(mockSecretOps.get(eq(clientsCa.getMetadata().getNamespace()), eq(clientsCa.getMetadata().getName()))).thenReturn(clientsCa);
when(mockSecretOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUserSecret);
when(mockSecretOps.get(eq(existingScramShaUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUserSecret);
Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
Set<String> deleted = new CopyOnWriteArraySet<>();
Checkpoint async = context.checkpoint();
Promise reconcileAllCompleted = Promise.promise();
KafkaUserOperator op = new KafkaUserOperator(vertx, mockCertManager, mockCrdOps, mockSecretOps, scramOps, quotasOps, aclOps, ResourceUtils.createUserOperatorConfig(ResourceUtils.LABELS, false, "12")) {
@Override
public Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
createdOrUpdated.add(resource.getMetadata().getName());
return Future.succeededFuture(new KafkaUserStatus());
}
@Override
public Future<Boolean> delete(Reconciliation reconciliation) {
deleted.add(reconciliation.name());
return Future.succeededFuture(Boolean.TRUE);
}
};
// call reconcileAll and pass in promise to the handler to run assertions on completion
op.reconcileAll("test", ResourceUtils.NAMESPACE, ar -> reconcileAllCompleted.complete());
reconcileAllCompleted.future().compose(v -> context.verify(() -> {
assertThat(createdOrUpdated, is(new HashSet(asList("new-tls-user", "existing-tls-user", "new-scram-sha-user", "existing-scram-sha-user"))));
assertThat(deleted, is(new HashSet(asList("quota-user", "deleted-scram-sha-user"))));
verify(aclOps, never()).getAllUsers();
async.flag();
}));
}
use of io.strimzi.api.kafka.model.status.KafkaUserStatus in project strimzi-kafka-operator by strimzi.
the class KafkaUserOperatorTest method testReconcileAll.
@Test
public void testReconcileAll(VertxTestContext context) {
CrdOperator mockCrdOps = mock(CrdOperator.class);
SecretOperator mockSecretOps = mock(SecretOperator.class);
SimpleAclOperator aclOps = mock(SimpleAclOperator.class);
ScramCredentialsOperator scramOps = mock(ScramCredentialsOperator.class);
QuotasOperator quotasOps = mock(QuotasOperator.class);
KafkaUser newTlsUser = ResourceUtils.createKafkaUserTls();
newTlsUser.getMetadata().setName("new-tls-user");
KafkaUser newScramShaUser = ResourceUtils.createKafkaUserScramSha();
newScramShaUser.getMetadata().setName("new-scram-sha-user");
KafkaUser existingTlsUser = ResourceUtils.createKafkaUserTls();
existingTlsUser.getMetadata().setName("existing-tls-user");
Secret clientsCa = ResourceUtils.createClientsCaCertSecret();
Secret existingTlsUserSecret = ResourceUtils.createUserSecretTls();
existingTlsUserSecret.getMetadata().setName("existing-tls-user");
Secret existingScramShaUserSecret = ResourceUtils.createUserSecretScramSha();
existingScramShaUserSecret.getMetadata().setName("existing-scram-sha-user");
KafkaUser existingScramShaUser = ResourceUtils.createKafkaUserTls();
existingScramShaUser.getMetadata().setName("existing-scram-sha-user");
when(mockCrdOps.listAsync(eq(ResourceUtils.NAMESPACE), eq(Optional.of(new LabelSelector(null, Labels.fromMap(ResourceUtils.LABELS).toMap()))))).thenReturn(Future.succeededFuture(Arrays.asList(newTlsUser, newScramShaUser, existingTlsUser, existingScramShaUser)));
when(mockSecretOps.list(eq(ResourceUtils.NAMESPACE), eq(Labels.fromMap(ResourceUtils.LABELS).withStrimziKind(KafkaUser.RESOURCE_KIND)))).thenReturn(Arrays.asList(existingTlsUserSecret, existingScramShaUserSecret));
when(aclOps.getAllUsers()).thenReturn(Future.succeededFuture(new HashSet<String>(Arrays.asList("existing-tls-user", "second-deleted-user"))));
when(scramOps.getAllUsers()).thenReturn(Future.succeededFuture(List.of("existing-tls-user", "deleted-scram-sha-user")));
when(quotasOps.getAllUsers()).thenReturn(Future.succeededFuture(Set.of("existing-tls-user", "quota-user")));
when(mockCrdOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(newTlsUser);
when(mockCrdOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(newScramShaUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUser);
when(mockCrdOps.getAsync(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newTlsUser));
when(mockCrdOps.getAsync(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newScramShaUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingTlsUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingScramShaUser));
when(mockCrdOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
when(mockSecretOps.get(eq(clientsCa.getMetadata().getNamespace()), eq(clientsCa.getMetadata().getName()))).thenReturn(clientsCa);
when(mockSecretOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUserSecret);
when(mockSecretOps.get(eq(existingScramShaUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUserSecret);
Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
Set<String> deleted = new CopyOnWriteArraySet<>();
Checkpoint async = context.checkpoint();
Promise reconcileAllCompleted = Promise.promise();
KafkaUserOperator op = new KafkaUserOperator(vertx, mockCertManager, mockCrdOps, mockSecretOps, scramOps, quotasOps, aclOps, ResourceUtils.createUserOperatorConfig(ResourceUtils.LABELS)) {
@Override
public Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
createdOrUpdated.add(resource.getMetadata().getName());
return Future.succeededFuture(new KafkaUserStatus());
}
@Override
public Future<Boolean> delete(Reconciliation reconciliation) {
deleted.add(reconciliation.name());
return Future.succeededFuture(Boolean.TRUE);
}
};
// call reconcileAll and pass in promise to the handler to run assertions on completion
op.reconcileAll("test", ResourceUtils.NAMESPACE, ar -> reconcileAllCompleted.complete());
reconcileAllCompleted.future().compose(v -> context.verify(() -> {
assertThat(createdOrUpdated, is(new HashSet(asList("new-tls-user", "existing-tls-user", "new-scram-sha-user", "existing-scram-sha-user"))));
assertThat(deleted, is(new HashSet(asList("quota-user", "second-deleted-user", "deleted-scram-sha-user"))));
async.flag();
}));
}
use of io.strimzi.api.kafka.model.status.KafkaUserStatus in project strimzi by strimzi.
the class KafkaUserOperator method createOrUpdate.
/**
* Creates or updates the user. The implementation
* should not assume that any resources are in any particular state (e.g. that the absence on
* one resource means that all resources need to be created).
*
* @param reconciliation Unique identification for the reconciliation
* @param resource KafkaUser resources with the desired user configuration.
* @return a Future
*/
@Override
protected Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
KafkaUserModel user;
KafkaUserStatus userStatus = new KafkaUserStatus();
try {
user = KafkaUserModel.fromCrd(resource, config.getSecretPrefix(), config.isAclsAdminApiSupported());
LOGGER.debugCr(reconciliation, "Updating User {} in namespace {}", reconciliation.name(), reconciliation.namespace());
} catch (Exception e) {
LOGGER.warnCr(reconciliation, e);
StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, Future.failedFuture(e));
return Future.failedFuture(new ReconciliationException(userStatus, e));
}
Promise<KafkaUserStatus> handler = Promise.promise();
secretOperations.getAsync(reconciliation.namespace(), user.getSecretName()).compose(userSecret -> maybeGenerateCredentials(reconciliation, user, userSecret)).compose(ignore -> reconcileCredentialsQuotasAndAcls(reconciliation, user, userStatus)).onComplete(reconciliationResult -> {
StatusUtils.setStatusConditionAndObservedGeneration(resource, userStatus, reconciliationResult.mapEmpty());
userStatus.setUsername(user.getUserName());
if (reconciliationResult.succeeded()) {
handler.complete(userStatus);
} else {
handler.fail(new ReconciliationException(userStatus, reconciliationResult.cause()));
}
});
return handler.future();
}
use of io.strimzi.api.kafka.model.status.KafkaUserStatus in project strimzi by strimzi.
the class KafkaUserOperatorTest method testReconcileAll.
@Test
public void testReconcileAll(VertxTestContext context) {
CrdOperator mockCrdOps = mock(CrdOperator.class);
SecretOperator mockSecretOps = mock(SecretOperator.class);
SimpleAclOperator aclOps = mock(SimpleAclOperator.class);
ScramCredentialsOperator scramOps = mock(ScramCredentialsOperator.class);
QuotasOperator quotasOps = mock(QuotasOperator.class);
KafkaUser newTlsUser = ResourceUtils.createKafkaUserTls();
newTlsUser.getMetadata().setName("new-tls-user");
KafkaUser newScramShaUser = ResourceUtils.createKafkaUserScramSha();
newScramShaUser.getMetadata().setName("new-scram-sha-user");
KafkaUser existingTlsUser = ResourceUtils.createKafkaUserTls();
existingTlsUser.getMetadata().setName("existing-tls-user");
Secret clientsCa = ResourceUtils.createClientsCaCertSecret();
Secret existingTlsUserSecret = ResourceUtils.createUserSecretTls();
existingTlsUserSecret.getMetadata().setName("existing-tls-user");
Secret existingScramShaUserSecret = ResourceUtils.createUserSecretScramSha();
existingScramShaUserSecret.getMetadata().setName("existing-scram-sha-user");
KafkaUser existingScramShaUser = ResourceUtils.createKafkaUserTls();
existingScramShaUser.getMetadata().setName("existing-scram-sha-user");
when(mockCrdOps.listAsync(eq(ResourceUtils.NAMESPACE), eq(Optional.of(new LabelSelector(null, Labels.fromMap(ResourceUtils.LABELS).toMap()))))).thenReturn(Future.succeededFuture(Arrays.asList(newTlsUser, newScramShaUser, existingTlsUser, existingScramShaUser)));
when(mockSecretOps.list(eq(ResourceUtils.NAMESPACE), eq(Labels.fromMap(ResourceUtils.LABELS).withStrimziKind(KafkaUser.RESOURCE_KIND)))).thenReturn(Arrays.asList(existingTlsUserSecret, existingScramShaUserSecret));
when(aclOps.getAllUsers()).thenReturn(Future.succeededFuture(new HashSet<String>(Arrays.asList("existing-tls-user", "second-deleted-user"))));
when(scramOps.getAllUsers()).thenReturn(Future.succeededFuture(List.of("existing-tls-user", "deleted-scram-sha-user")));
when(quotasOps.getAllUsers()).thenReturn(Future.succeededFuture(Set.of("existing-tls-user", "quota-user")));
when(mockCrdOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(newTlsUser);
when(mockCrdOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(newScramShaUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUser);
when(mockCrdOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUser);
when(mockCrdOps.getAsync(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newTlsUser));
when(mockCrdOps.getAsync(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(newScramShaUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingTlsUser));
when(mockCrdOps.getAsync(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(Future.succeededFuture(existingScramShaUser));
when(mockCrdOps.updateStatusAsync(any(), any())).thenReturn(Future.succeededFuture());
when(mockSecretOps.get(eq(clientsCa.getMetadata().getNamespace()), eq(clientsCa.getMetadata().getName()))).thenReturn(clientsCa);
when(mockSecretOps.get(eq(newTlsUser.getMetadata().getNamespace()), eq(newTlsUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(newScramShaUser.getMetadata().getNamespace()), eq(newScramShaUser.getMetadata().getName()))).thenReturn(null);
when(mockSecretOps.get(eq(existingTlsUser.getMetadata().getNamespace()), eq(existingTlsUser.getMetadata().getName()))).thenReturn(existingTlsUserSecret);
when(mockSecretOps.get(eq(existingScramShaUser.getMetadata().getNamespace()), eq(existingScramShaUser.getMetadata().getName()))).thenReturn(existingScramShaUserSecret);
Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
Set<String> deleted = new CopyOnWriteArraySet<>();
Checkpoint async = context.checkpoint();
Promise reconcileAllCompleted = Promise.promise();
KafkaUserOperator op = new KafkaUserOperator(vertx, mockCertManager, mockCrdOps, mockSecretOps, scramOps, quotasOps, aclOps, ResourceUtils.createUserOperatorConfig(ResourceUtils.LABELS)) {
@Override
public Future<KafkaUserStatus> createOrUpdate(Reconciliation reconciliation, KafkaUser resource) {
createdOrUpdated.add(resource.getMetadata().getName());
return Future.succeededFuture(new KafkaUserStatus());
}
@Override
public Future<Boolean> delete(Reconciliation reconciliation) {
deleted.add(reconciliation.name());
return Future.succeededFuture(Boolean.TRUE);
}
};
// call reconcileAll and pass in promise to the handler to run assertions on completion
op.reconcileAll("test", ResourceUtils.NAMESPACE, ar -> reconcileAllCompleted.complete());
reconcileAllCompleted.future().compose(v -> context.verify(() -> {
assertThat(createdOrUpdated, is(new HashSet(asList("new-tls-user", "existing-tls-user", "new-scram-sha-user", "existing-scram-sha-user"))));
assertThat(deleted, is(new HashSet(asList("quota-user", "second-deleted-user", "deleted-scram-sha-user"))));
async.flag();
}));
}
Aggregations