use of io.strimzi.api.kafka.model.EntityUserOperatorSpec in project strimzi by strimzi.
the class EntityUserOperatorTest method testFromCrdCaValidityAndRenewal.
@ParallelTest
public void testFromCrdCaValidityAndRenewal() {
EntityUserOperatorSpec entityUserOperatorSpec = new EntityUserOperatorSpecBuilder().build();
EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().withUserOperator(entityUserOperatorSpec).build();
CertificateAuthority ca = new CertificateAuthority();
ca.setValidityDays(42);
ca.setRenewalDays(69);
Kafka customValues = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).withClientsCa(ca).endSpec().build();
EntityUserOperator entityUserOperator = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), customValues);
Kafka defaultValues = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).endSpec().build();
EntityUserOperator entityUserOperator2 = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), defaultValues);
assertThat(entityUserOperator.getClientsCaValidityDays(), is(42L));
assertThat(entityUserOperator.getClientsCaRenewalDays(), is(69L));
assertThat(entityUserOperator2.getClientsCaValidityDays(), is(Long.valueOf(CertificateAuthority.DEFAULT_CERTS_VALIDITY_DAYS)));
assertThat(entityUserOperator2.getClientsCaRenewalDays(), is(Long.valueOf(CertificateAuthority.DEFAULT_CERTS_RENEWAL_DAYS)));
}
use of io.strimzi.api.kafka.model.EntityUserOperatorSpec in project strimzi by strimzi.
the class EntityUserOperatorTest method testFromCrdDefault.
@ParallelTest
public void testFromCrdDefault() {
EntityUserOperatorSpec entityUserOperatorSpec = new EntityUserOperatorSpecBuilder().build();
EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().withUserOperator(entityUserOperatorSpec).build();
Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).endSpec().build();
EntityUserOperator entityUserOperator = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource);
assertThat(entityUserOperator.getWatchedNamespace(), is(namespace));
assertThat(entityUserOperator.getImage(), is("quay.io/strimzi/operator:latest"));
assertThat(entityUserOperator.getReconciliationIntervalMs(), is(EntityUserOperatorSpec.DEFAULT_FULL_RECONCILIATION_INTERVAL_SECONDS * 1000));
assertThat(entityUserOperator.readinessProbeOptions.getInitialDelaySeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_DELAY));
assertThat(entityUserOperator.readinessProbeOptions.getTimeoutSeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_TIMEOUT));
assertThat(entityUserOperator.livenessProbeOptions.getInitialDelaySeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_DELAY));
assertThat(entityUserOperator.livenessProbeOptions.getTimeoutSeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_TIMEOUT));
assertThat(entityUserOperator.getKafkaBootstrapServers(), is(EntityUserOperator.defaultBootstrapServers(cluster)));
assertThat(entityUserOperator.getLogging(), is(nullValue()));
assertThat(entityUserOperator.getSecretPrefix(), is(EntityUserOperatorSpec.DEFAULT_SECRET_PREFIX));
}
use of io.strimzi.api.kafka.model.EntityUserOperatorSpec in project strimzi by strimzi.
the class KafkaST method testRemoveUserOperatorFromEntityOperator.
@ParallelNamespaceTest
void testRemoveUserOperatorFromEntityOperator(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
Instant startTime = Instant.now();
LOGGER.info("Deploying Kafka cluster {}", clusterName);
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).build());
String eoPodName = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName)).get(0).getMetadata().getName();
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> k.getSpec().getEntityOperator().setUserOperator(null), namespaceName);
// Waiting when EO pod will be recreated without UO
PodUtils.deletePodWithWait(namespaceName, eoPodName);
DeploymentUtils.waitForDeploymentAndPodsReady(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName), 1);
PodUtils.waitUntilPodContainersCount(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName), 2);
// Checking that UO was removed
kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName)).forEach(pod -> {
pod.getSpec().getContainers().forEach(container -> {
assertThat(container.getName(), not(containsString("user-operator")));
});
});
eoPodName = kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName)).get(0).getMetadata().getName();
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> k.getSpec().getEntityOperator().setUserOperator(new EntityUserOperatorSpec()), namespaceName);
// Waiting when EO pod will be recreated with UO
PodUtils.deletePodWithWait(namespaceName, eoPodName);
DeploymentUtils.waitForDeploymentAndPodsReady(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName), 1);
// Checking that UO was created
kubeClient(namespaceName).listPodsByPrefixInName(namespaceName, KafkaResources.entityOperatorDeploymentName(clusterName)).forEach(pod -> {
pod.getSpec().getContainers().forEach(container -> {
assertThat(container.getName(), anyOf(containsString("topic-operator"), containsString("user-operator"), containsString("tls-sidecar")));
});
});
Instant endTime = Instant.now();
long duration = Duration.between(startTime, endTime).toSeconds();
assertNoCoErrorsLogged(duration);
}
use of io.strimzi.api.kafka.model.EntityUserOperatorSpec in project strimzi by strimzi.
the class KafkaST method testRemoveUserAndTopicOperatorsFromEntityOperator.
@ParallelNamespaceTest
void testRemoveUserAndTopicOperatorsFromEntityOperator(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(namespace, extensionContext);
final String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
Instant startTime = Instant.now();
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(clusterName, 3).build());
String eoDeploymentName = KafkaResources.entityOperatorDeploymentName(clusterName);
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
k.getSpec().getEntityOperator().setTopicOperator(null);
k.getSpec().getEntityOperator().setUserOperator(null);
}, namespaceName);
PodUtils.waitUntilPodStabilityReplicasCount(namespaceName, eoDeploymentName, 0);
KafkaResource.replaceKafkaResourceInSpecificNamespace(clusterName, k -> {
k.getSpec().getEntityOperator().setTopicOperator(new EntityTopicOperatorSpec());
k.getSpec().getEntityOperator().setUserOperator(new EntityUserOperatorSpec());
}, namespaceName);
DeploymentUtils.waitForDeploymentReady(namespaceName, eoDeploymentName);
// Checking that EO was created
kubeClient().listPodsByPrefixInName(namespaceName, eoDeploymentName).forEach(pod -> {
pod.getSpec().getContainers().forEach(container -> {
assertThat(container.getName(), anyOf(containsString("topic-operator"), containsString("user-operator"), containsString("tls-sidecar")));
});
});
Instant endTime = Instant.now();
long duration = Duration.between(startTime, endTime).toSeconds();
assertNoCoErrorsLogged(duration);
}
use of io.strimzi.api.kafka.model.EntityUserOperatorSpec in project strimzi by strimzi.
the class EntityOperatorTest method testTopicOperatorContainerEnvVarsConflict.
@ParallelTest
public void testTopicOperatorContainerEnvVarsConflict() {
ContainerEnvVar envVar1 = new ContainerEnvVar();
String testEnvOneKey = EntityTopicOperator.ENV_VAR_RESOURCE_LABELS;
String testEnvOneValue = "test.env.one";
envVar1.setName(testEnvOneKey);
envVar1.setValue(testEnvOneValue);
ContainerEnvVar envVar2 = new ContainerEnvVar();
String testEnvTwoKey = EntityTopicOperator.ENV_VAR_KAFKA_BOOTSTRAP_SERVERS;
String testEnvTwoValue = "test.env.two";
envVar2.setName(testEnvTwoKey);
envVar2.setValue(testEnvTwoValue);
List<ContainerEnvVar> testEnvs = new ArrayList<>();
testEnvs.add(envVar1);
testEnvs.add(envVar2);
ContainerTemplate topicOperatorContainer = new ContainerTemplate();
topicOperatorContainer.setEnv(testEnvs);
Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withNewEntityOperator().withTopicOperator(entityTopicOperatorSpec).withUserOperator(entityUserOperatorSpec).withNewTemplate().withTopicOperatorContainer(topicOperatorContainer).endTemplate().endEntityOperator().endSpec().build();
List<EnvVar> containerEnvVars = EntityOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource, VERSIONS).getTopicOperator().getEnvVars();
assertThat("Failed to prevent over writing existing container environment variable: " + testEnvOneKey, containerEnvVars.stream().filter(env -> testEnvOneKey.equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals(testEnvOneValue), is(false));
assertThat("Failed to prevent over writing existing container environment variable: " + testEnvTwoKey, containerEnvVars.stream().filter(env -> testEnvTwoKey.equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals(testEnvTwoValue), is(false));
}
Aggregations