use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaAssemblyOperatorNonParametrizedTest method testClientsCASecretsWithoutOwnerReference.
@Test
public void testClientsCASecretsWithoutOwnerReference(VertxTestContext context) {
OwnerReference ownerReference = new OwnerReferenceBuilder().withKind("Kafka").withName(NAME).withBlockOwnerDeletion(false).withController(false).build();
CertificateAuthority caConfig = new CertificateAuthority();
caConfig.setGenerateSecretOwnerReference(false);
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(NAME).withNamespace(NAMESPACE).endMetadata().withNewSpec().withNewKafka().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endKafka().withClientsCa(caConfig).withNewZookeeper().withReplicas(3).withNewEphemeralStorage().endEphemeralStorage().endZookeeper().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
SecretOperator secretOps = supplier.secretOperations;
PodOperator podOps = supplier.podOperations;
ArgumentCaptor<Secret> clusterCaCert = ArgumentCaptor.forClass(Secret.class);
ArgumentCaptor<Secret> clusterCaKey = ArgumentCaptor.forClass(Secret.class);
ArgumentCaptor<Secret> clientsCaCert = ArgumentCaptor.forClass(Secret.class);
ArgumentCaptor<Secret> clientsCaKey = ArgumentCaptor.forClass(Secret.class);
when(secretOps.reconcile(any(), eq(NAMESPACE), eq(AbstractModel.clusterCaCertSecretName(NAME)), clusterCaCert.capture())).thenAnswer(i -> Future.succeededFuture(ReconcileResult.created(i.getArgument(0))));
when(secretOps.reconcile(any(), eq(NAMESPACE), eq(AbstractModel.clusterCaKeySecretName(NAME)), clusterCaKey.capture())).thenAnswer(i -> Future.succeededFuture(ReconcileResult.created(i.getArgument(0))));
when(secretOps.reconcile(any(), eq(NAMESPACE), eq(KafkaResources.clientsCaCertificateSecretName(NAME)), clientsCaCert.capture())).thenAnswer(i -> Future.succeededFuture(ReconcileResult.created(i.getArgument(0))));
when(secretOps.reconcile(any(), eq(NAMESPACE), eq(KafkaResources.clientsCaKeySecretName(NAME)), clientsCaKey.capture())).thenAnswer(i -> Future.succeededFuture(ReconcileResult.created(i.getArgument(0))));
when(secretOps.reconcile(any(), eq(NAMESPACE), eq(ClusterOperator.secretName(NAME)), any())).thenAnswer(i -> Future.succeededFuture(ReconcileResult.created(i.getArgument(0))));
when(podOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(List.of()));
KafkaAssemblyOperator op = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), certManager, passwordGenerator, supplier, ResourceUtils.dummyClusterOperatorConfig(1L));
Reconciliation reconciliation = new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, NAME);
Checkpoint async = context.checkpoint();
op.new ReconciliationState(reconciliation, kafka).reconcileCas(() -> new Date()).onComplete(context.succeeding(c -> context.verify(() -> {
assertThat(clusterCaCert.getAllValues(), hasSize(1));
assertThat(clusterCaKey.getAllValues(), hasSize(1));
assertThat(clientsCaCert.getAllValues(), hasSize(1));
assertThat(clientsCaKey.getAllValues(), hasSize(1));
Secret clusterCaCertSecret = clusterCaCert.getValue();
Secret clusterCaKeySecret = clusterCaKey.getValue();
Secret clientsCaCertSecret = clientsCaCert.getValue();
Secret clientsCaKeySecret = clientsCaKey.getValue();
assertThat(clusterCaCertSecret.getMetadata().getOwnerReferences(), hasSize(1));
assertThat(clusterCaKeySecret.getMetadata().getOwnerReferences(), hasSize(1));
assertThat(clientsCaCertSecret.getMetadata().getOwnerReferences(), hasSize(0));
assertThat(clientsCaKeySecret.getMetadata().getOwnerReferences(), hasSize(0));
assertThat(clusterCaCertSecret.getMetadata().getOwnerReferences().get(0), is(ownerReference));
assertThat(clusterCaKeySecret.getMetadata().getOwnerReferences().get(0), is(ownerReference));
async.flag();
})));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsWithPreferredAddressType.
@Test
public void testKafkaReconcilerStatusWithNodePortsWithPreferredAddressType(VertxTestContext context) {
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).withNewConfiguration().withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).endConfiguration().build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is("node-0.my-kube:31234,node-1.my-kube:31234,node-3.my-kube:31234"));
assertThat(status.getListeners().get(0).getAddresses().size(), is(3));
assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("node-0.my-kube"));
assertThat(status.getListeners().get(0).getAddresses().get(1).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(1).getHost(), is("node-1.my-kube"));
assertThat(status.getListeners().get(0).getAddresses().get(2).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(2).getHost(), is("node-3.my-kube"));
async.flag();
}));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePorts.
@Test
public void testKafkaReconcilerStatusWithNodePorts(VertxTestContext context) {
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.1").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.25").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.13").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is("5.124.16.8:31234,55.36.78.115:31234,50.35.18.119:31234"));
assertThat(status.getListeners().get(0).getAddresses().size(), is(3));
assertThat(status.getListeners().get(0).getAddresses().get(0).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(0).getHost(), is("5.124.16.8"));
assertThat(status.getListeners().get(0).getAddresses().get(1).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(1).getHost(), is("55.36.78.115"));
assertThat(status.getListeners().get(0).getAddresses().get(2).getPort(), is(31234));
assertThat(status.getListeners().get(0).getAddresses().get(2).getHost(), is("50.35.18.119"));
async.flag();
}));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaReconcilerStatusTest method testKafkaReconcilerStatusWithNodePortsAndMissingNode.
@Test
public void testKafkaReconcilerStatusWithNodePortsAndMissingNode(VertxTestContext context) {
Kafka kafka = new KafkaBuilder(KAFKA).editOrNewSpec().editOrNewKafka().withListeners(new GenericKafkaListenerBuilder().withName("external").withPort(9094).withType(KafkaListenerType.NODEPORT).withTls(true).build()).endKafka().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the secrets needed for Kafka client
SecretOperator mockSecretOps = supplier.secretOperations;
Secret secret = new Secret();
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(KafkaResources.clusterCaCertificateSecretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
when(mockSecretOps.getAsync(eq(NAMESPACE), eq(ClusterOperator.secretName(CLUSTER_NAME)))).thenReturn(Future.succeededFuture(secret));
// Mock Kafka broker pods
Pod pod0 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 0).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
Pod pod1 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 1).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName(CLUSTER_NAME + "-kafka-" + 2).endMetadata().withNewStatus().withHostIP("10.0.0.5").endStatus().build();
List<Pod> pods = new ArrayList<>();
pods.add(pod0);
pods.add(pod1);
pods.add(pod2);
PodOperator mockPodOps = supplier.podOperations;
when(mockPodOps.listAsync(eq(NAMESPACE), any(Labels.class))).thenReturn(Future.succeededFuture(pods));
// Mock Kubernetes worker nodes
NodeOperator mockNodeOps = supplier.nodeOperator;
when(mockNodeOps.listAsync(any(Labels.class))).thenReturn(Future.succeededFuture(kubernetesWorkerNodes()));
// Run the test
KafkaReconciler reconciler = new MockKafkaReconcilerStatusTasks(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), supplier, kafka);
KafkaStatus status = new KafkaStatus();
Checkpoint async = context.checkpoint();
reconciler.reconcile(status, Date::new).onComplete(res -> context.verify(() -> {
assertThat(res.succeeded(), is(true));
// Check listener status
assertThat(status.getListeners().size(), is(1));
assertThat(status.getListeners().get(0).getName(), is("external"));
assertThat(status.getListeners().get(0).getType(), is("external"));
assertThat(status.getListeners().get(0).getBootstrapServers(), is(nullValue()));
assertThat(status.getListeners().get(0).getAddresses(), is(List.of()));
async.flag();
}));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class StrimziPodSetControllerMockTest method beforeEach.
@BeforeEach
public void beforeEach() {
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withStrimziPodSetCrd().withPodController().build();
mockKube.start();
vertx = Vertx.vertx();
kafkaOperator = new CrdOperator<>(vertx, client, Kafka.class, KafkaList.class, Kafka.RESOURCE_KIND);
podSetOperator = new StrimziPodSetOperator(vertx, client, 10_000L);
podOperator = new PodOperator(vertx, client);
kafkaOp().inNamespace(NAMESPACE).create(kafka(KAFKA_NAME, MATCHING_LABELS));
kafkaOp().inNamespace(NAMESPACE).create(kafka(OTHER_KAFKA_NAME, OTHER_LABELS));
startController();
}
Aggregations