use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.
the class ConnectorMockTest method testConnectorResourceMetricsScaledToZero.
// MockKube2 does not support "In" selector => https://github.com/strimzi/strimzi-kafka-operator/issues/6740
@Disabled
@Test
void testConnectorResourceMetricsScaledToZero(VertxTestContext context) {
String connectName = "cluster";
String connectorName = "connector";
KafkaConnect kafkaConnect = new KafkaConnectBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(connectName).addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().withNewSpec().withReplicas(0).endSpec().build();
Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).create(kafkaConnect);
waitForConnectReady(connectName);
KafkaConnector connector = defaultKafkaConnectorBuilder().editMetadata().withName(connectorName).addToLabels(Labels.STRIMZI_CLUSTER_LABEL, connectName).addToAnnotations(Annotations.ANNO_STRIMZI_IO_PAUSE_RECONCILIATION, "true").endMetadata().build();
Crds.kafkaConnectorOperation(client).inNamespace(NAMESPACE).create(connector);
waitForConnectorNotReady(connectorName, "RuntimeException", "Kafka Connect cluster 'cluster' in namespace ns has 0 replicas.");
MeterRegistry meterRegistry = metricsProvider.meterRegistry();
Tags tags = Tags.of("kind", KafkaConnector.RESOURCE_KIND, "namespace", NAMESPACE);
Promise<Void> reconciled = Promise.promise();
kafkaConnectOperator.reconcileAll("test", NAMESPACE, ignored -> reconciled.complete());
Checkpoint async = context.checkpoint();
reconciled.future().onComplete(context.succeeding(v -> context.verify(() -> {
Gauge resources = meterRegistry.get("strimzi.resources").tags(tags).gauge();
assertThat(resources.value(), is(1.0));
// to create metric, otherwise MeterNotFoundException will be thrown
kafkaConnectOperator.pausedConnectorsResourceCounter(NAMESPACE);
Gauge resourcesPaused = meterRegistry.get("strimzi.resources.paused").tags(tags).gauge();
assertThat(resourcesPaused.value(), is(0.0));
async.flag();
})));
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.
the class KafkaAssemblyOperatorCustomCertMockTest method setup.
@BeforeEach
public void setup() {
kafka = createKafka();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(kafka).withStrimziPodSetCrd().withPodController().withStatefulSetController().build();
mockKube.start();
client.secrets().inNamespace(namespace).create(getTlsSecret());
client.secrets().inNamespace(namespace).create(getExternalSecret());
Secret secret = new SecretBuilder().withNewMetadata().withNamespace(namespace).withName("testkafka-cluster-operator-certs").endMetadata().addToData("foo", "bar").build();
client.secrets().inNamespace(namespace).create(secret);
ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, client, mock(ZookeeperLeaderFinder.class), mock(AdminClientProvider.class), mock(ZookeeperScalerProvider.class), mock(MetricsProvider.class), new PlatformFeaturesAvailability(false, KubernetesVersion.V1_20), 10000);
operator = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method beforeEach.
@BeforeEach
public void beforeEach(Vertx vertx) {
ccServer.reset();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaRebalanceCrd().build();
mockKube.start();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Override to inject mocked cruise control address so real cruise control not required
kcrao = new KafkaRebalanceAssemblyOperator(vertx, supplier, ResourceUtils.dummyClusterOperatorConfig()) {
@Override
public String cruiseControlHost(String clusterName, String clusterNamespace) {
return HOST;
}
@Override
public CruiseControlApi cruiseControlClientProvider(Secret ccSecret, Secret ccApiSecret, boolean apiAuthEnabled, boolean apiSslEnabled) {
return new CruiseControlApiImpl(vertx, 1, ccSecret, ccApiSecret, true, true);
}
};
mockRebalanceOps = supplier.kafkaRebalanceOperator;
mockKafkaOps = supplier.kafkaOperator;
mockCmOps = supplier.configMapOperations;
mockSecretOps = supplier.secretOperations;
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.
the class ConnectorMockTest method setup.
@SuppressWarnings({ "checkstyle:MethodLength" })
@BeforeEach
public void setup(VertxTestContext testContext) {
vertx = Vertx.vertx();
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaConnectCrd().withKafkaConnectorCrd().withDeploymentController().build();
mockKube.start();
PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(false, KubernetesVersion.V1_18);
setupMockConnectAPI();
metricsProvider = ResourceUtils.metricsProvider();
ResourceOperatorSupplier ros = new ResourceOperatorSupplier(vertx, client, new ZookeeperLeaderFinder(vertx, // Retry up to 3 times (4 attempts), with overall max delay of 35000ms
() -> new BackOff(5_000, 2, 4)), new DefaultAdminClientProvider(), new DefaultZookeeperScalerProvider(), metricsProvider, pfa, 10_000);
ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(map(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString(), ClusterOperatorConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS, Long.toString(Long.MAX_VALUE)), KafkaVersionTestUtils.getKafkaVersionLookup());
kafkaConnectOperator = spy(new KafkaConnectAssemblyOperator(vertx, pfa, ros, config, x -> api));
Checkpoint async = testContext.checkpoint();
// Fail test if watcher closes for any reason
kafkaConnectOperator.createWatch(NAMESPACE, e -> testContext.failNow(e)).onComplete(testContext.succeeding()).compose(watch -> {
connectWatch = watch;
return AbstractConnectOperator.createConnectorWatch(kafkaConnectOperator, NAMESPACE, null);
}).compose(watch -> {
connectorWatch = watch;
// async.flag();
return Future.succeededFuture();
}).onComplete(testContext.succeeding(v -> async.flag()));
}
use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.
the class KafkaUpgradeDowngradeMockTest method initialize.
private Future<Void> initialize(VertxTestContext context, Kafka initialKafka) {
// Configure the Kubernetes Mock
mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(initialKafka).withStrimziPodSetCrd().withStatefulSetController().withPodController().withServiceController().withDeploymentController().build();
mockKube.start();
ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, client, ResourceUtils.zookeeperLeaderFinder(vertx, client), ResourceUtils.adminClientProvider(), ResourceUtils.zookeeperScalerProvider(), ResourceUtils.metricsProvider(), pfa, 2_000);
ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
LOGGER.info("Reconciling initially -> create");
return operator.reconcile(new Reconciliation("initial-reconciliation", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}
Aggregations