use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class MirrorMaker2IsolatedST method testConfigureDeploymentStrategy.
@ParallelNamespaceTest
void testConfigureDeploymentStrategy(ExtensionContext extensionContext) {
final String namespaceName = StUtils.getNamespaceBasedOnRbac(INFRA_NAMESPACE, extensionContext);
String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
String kafkaClusterSourceName = clusterName + "-source";
String kafkaClusterTargetName = clusterName + "-target";
// Deploy source kafka
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterSourceName, 1, 1).build());
// Deploy target kafka
resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(kafkaClusterTargetName, 1, 1).build());
resourceManager.createResource(extensionContext, KafkaMirrorMaker2Templates.kafkaMirrorMaker2(clusterName, kafkaClusterTargetName, kafkaClusterSourceName, 1, false).editSpec().editOrNewTemplate().editOrNewDeployment().withDeploymentStrategy(DeploymentStrategy.RECREATE).endDeployment().endTemplate().endSpec().build());
String mm2DepName = KafkaMirrorMaker2Resources.deploymentName(clusterName);
LOGGER.info("Adding label to MirrorMaker2 resource, the CR should be recreated");
KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2ResourceInSpecificNamespace(clusterName, mm2 -> mm2.getMetadata().setLabels(Collections.singletonMap("some", "label")), namespaceName);
DeploymentUtils.waitForDeploymentAndPodsReady(namespaceName, mm2DepName, 1);
KafkaMirrorMaker2 kmm2 = KafkaMirrorMaker2Resource.kafkaMirrorMaker2Client().inNamespace(namespaceName).withName(clusterName).get();
LOGGER.info("Checking that observed gen. is still on 1 (recreation) and new label is present");
assertThat(kmm2.getStatus().getObservedGeneration(), is(1L));
assertThat(kmm2.getMetadata().getLabels().toString(), containsString("some=label"));
assertThat(kmm2.getSpec().getTemplate().getDeployment().getDeploymentStrategy(), is(DeploymentStrategy.RECREATE));
LOGGER.info("Changing deployment strategy to {}", DeploymentStrategy.ROLLING_UPDATE);
KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2ResourceInSpecificNamespace(clusterName, mm2 -> mm2.getSpec().getTemplate().getDeployment().setDeploymentStrategy(DeploymentStrategy.ROLLING_UPDATE), namespaceName);
KafkaMirrorMaker2Utils.waitForKafkaMirrorMaker2Ready(namespaceName, clusterName);
LOGGER.info("Adding another label to MirrorMaker2 resource, pods should be rolled");
KafkaMirrorMaker2Resource.replaceKafkaMirrorMaker2ResourceInSpecificNamespace(clusterName, mm2 -> mm2.getMetadata().getLabels().put("another", "label"), namespaceName);
DeploymentUtils.waitForDeploymentAndPodsReady(namespaceName, mm2DepName, 1);
LOGGER.info("Checking that observed gen. higher (rolling update) and label is changed");
kmm2 = KafkaMirrorMaker2Resource.kafkaMirrorMaker2Client().inNamespace(namespaceName).withName(clusterName).get();
assertThat(kmm2.getStatus().getObservedGeneration(), is(2L));
assertThat(kmm2.getMetadata().getLabels().toString(), containsString("another=label"));
assertThat(kmm2.getSpec().getTemplate().getDeployment().getDeploymentStrategy(), is(DeploymentStrategy.ROLLING_UPDATE));
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class CustomResourceStatusIsolatedST method testKafkaMirrorMaker2WrongBootstrap.
@ParallelTest
@Tag(MIRROR_MAKER2)
void testKafkaMirrorMaker2WrongBootstrap(ExtensionContext extensionContext) {
String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
String mirrorMaker2Name = clusterName + "-mirror-maker-2";
KafkaMirrorMaker2 kafkaMirrorMaker2 = KafkaMirrorMaker2Templates.kafkaMirrorMaker2(mirrorMaker2Name, "non-existing-source", "non-existing-target", 1, false).build();
resourceManager.createResource(extensionContext, false, kafkaMirrorMaker2);
KafkaMirrorMaker2Utils.waitForKafkaMirrorMaker2NotReady(mirrorMaker2Name);
// delete
KafkaMirrorMaker2Resource.kafkaMirrorMaker2Client().inNamespace(Constants.INFRA_NAMESPACE).withName(mirrorMaker2Name).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
DeploymentUtils.waitForDeploymentDeletion(KafkaMirrorMaker2Resources.deploymentName(mirrorMaker2Name));
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class Crds method crd.
@SuppressWarnings({ "checkstyle:JavaNCSS" })
private static CustomResourceDefinition crd(Class<? extends CustomResource> cls) {
String scope, plural, singular, group, kind, listKind;
List<String> versions;
CustomResourceSubresourceStatus status = null;
if (cls.equals(Kafka.class)) {
scope = Kafka.SCOPE;
plural = Kafka.RESOURCE_PLURAL;
singular = Kafka.RESOURCE_SINGULAR;
group = Kafka.RESOURCE_GROUP;
kind = Kafka.RESOURCE_KIND;
listKind = Kafka.RESOURCE_LIST_KIND;
versions = Kafka.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaConnect.class)) {
scope = KafkaConnect.SCOPE;
plural = KafkaConnect.RESOURCE_PLURAL;
singular = KafkaConnect.RESOURCE_SINGULAR;
group = KafkaConnect.RESOURCE_GROUP;
kind = KafkaConnect.RESOURCE_KIND;
listKind = KafkaConnect.RESOURCE_LIST_KIND;
versions = KafkaConnect.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaTopic.class)) {
scope = KafkaTopic.SCOPE;
plural = KafkaTopic.RESOURCE_PLURAL;
singular = KafkaTopic.RESOURCE_SINGULAR;
group = KafkaTopic.RESOURCE_GROUP;
kind = KafkaTopic.RESOURCE_KIND;
listKind = KafkaTopic.RESOURCE_LIST_KIND;
versions = KafkaTopic.VERSIONS;
} else if (cls.equals(KafkaUser.class)) {
scope = KafkaUser.SCOPE;
plural = KafkaUser.RESOURCE_PLURAL;
singular = KafkaUser.RESOURCE_SINGULAR;
group = KafkaUser.RESOURCE_GROUP;
kind = KafkaUser.RESOURCE_KIND;
listKind = KafkaUser.RESOURCE_LIST_KIND;
versions = KafkaUser.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaMirrorMaker.class)) {
scope = KafkaMirrorMaker.SCOPE;
plural = KafkaMirrorMaker.RESOURCE_PLURAL;
singular = KafkaMirrorMaker.RESOURCE_SINGULAR;
group = KafkaMirrorMaker.RESOURCE_GROUP;
kind = KafkaMirrorMaker.RESOURCE_KIND;
listKind = KafkaMirrorMaker.RESOURCE_LIST_KIND;
versions = KafkaMirrorMaker.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaBridge.class)) {
scope = KafkaBridge.SCOPE;
plural = KafkaBridge.RESOURCE_PLURAL;
singular = KafkaBridge.RESOURCE_SINGULAR;
group = KafkaBridge.RESOURCE_GROUP;
kind = KafkaBridge.RESOURCE_KIND;
listKind = KafkaBridge.RESOURCE_LIST_KIND;
versions = KafkaBridge.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaConnector.class)) {
scope = KafkaConnector.SCOPE;
plural = KafkaConnector.RESOURCE_PLURAL;
singular = KafkaConnector.RESOURCE_SINGULAR;
group = KafkaConnector.RESOURCE_GROUP;
kind = KafkaConnector.RESOURCE_KIND;
listKind = KafkaConnector.RESOURCE_LIST_KIND;
versions = KafkaConnector.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaMirrorMaker2.class)) {
scope = KafkaMirrorMaker2.SCOPE;
plural = KafkaMirrorMaker2.RESOURCE_PLURAL;
singular = KafkaMirrorMaker2.RESOURCE_SINGULAR;
group = KafkaMirrorMaker2.RESOURCE_GROUP;
kind = KafkaMirrorMaker2.RESOURCE_KIND;
listKind = KafkaMirrorMaker2.RESOURCE_LIST_KIND;
versions = KafkaMirrorMaker2.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(KafkaRebalance.class)) {
scope = KafkaRebalance.SCOPE;
plural = KafkaRebalance.RESOURCE_PLURAL;
singular = KafkaRebalance.RESOURCE_SINGULAR;
group = KafkaRebalance.RESOURCE_GROUP;
kind = KafkaRebalance.RESOURCE_KIND;
listKind = KafkaRebalance.RESOURCE_LIST_KIND;
versions = KafkaRebalance.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else if (cls.equals(StrimziPodSet.class)) {
scope = StrimziPodSet.SCOPE;
plural = StrimziPodSet.RESOURCE_PLURAL;
singular = StrimziPodSet.RESOURCE_SINGULAR;
group = StrimziPodSet.RESOURCE_GROUP;
kind = StrimziPodSet.RESOURCE_KIND;
listKind = StrimziPodSet.RESOURCE_LIST_KIND;
versions = StrimziPodSet.VERSIONS;
status = new CustomResourceSubresourceStatus();
} else {
throw new RuntimeException();
}
List<CustomResourceDefinitionVersion> crVersions = new ArrayList<>(versions.size());
for (String apiVersion : versions) {
crVersions.add(new CustomResourceDefinitionVersionBuilder().withName(apiVersion).withNewSubresources().withStatus(status).endSubresources().withNewSchema().withNewOpenAPIV3Schema().withType("object").withXKubernetesPreserveUnknownFields(true).endOpenAPIV3Schema().endSchema().withStorage("v1beta2".equals(apiVersion)).withServed(true).build());
}
return new CustomResourceDefinitionBuilder().withNewMetadata().withName(plural + "." + group).endMetadata().withNewSpec().withScope(scope).withGroup(group).withVersions(crVersions).withNewNames().withSingular(singular).withPlural(plural).withKind(kind).withListKind(listKind).endNames().endSpec().build();
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2AssemblyOperator method reconcileConnectors.
/**
* Reconcile all the MirrorMaker 2.0 connectors selected by the given MirrorMaker 2.0 instance.
* @param reconciliation The reconciliation
* @param kafkaMirrorMaker2 The MirrorMaker 2.0
* @return A future, failed if any of the connectors could not be reconciled.
*/
protected Future<Void> reconcileConnectors(Reconciliation reconciliation, KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaMirrorMaker2Cluster mirrorMaker2Cluster, KafkaMirrorMaker2Status mirrorMaker2Status, String desiredLogging) {
String mirrorMaker2Name = kafkaMirrorMaker2.getMetadata().getName();
if (kafkaMirrorMaker2.getSpec() == null) {
return maybeUpdateMirrorMaker2Status(reconciliation, kafkaMirrorMaker2, new InvalidResourceException("spec property is required"));
}
List<KafkaMirrorMaker2MirrorSpec> mirrors = ModelUtils.asListOrEmptyList(kafkaMirrorMaker2.getSpec().getMirrors());
String host = KafkaMirrorMaker2Resources.qualifiedServiceName(mirrorMaker2Name, reconciliation.namespace());
KafkaConnectApi apiClient = getKafkaConnectApi();
return apiClient.list(host, KafkaConnectCluster.REST_API_PORT).compose(deleteMirrorMaker2ConnectorNames -> {
for (Map.Entry<String, Function<KafkaMirrorMaker2MirrorSpec, KafkaMirrorMaker2ConnectorSpec>> connectorEntry : MIRRORMAKER2_CONNECTORS.entrySet()) {
deleteMirrorMaker2ConnectorNames.removeAll(mirrors.stream().filter(// filter out non-existent connectors
mirror -> connectorEntry.getValue().apply(mirror) != null).map(mirror -> mirror.getSourceCluster() + "->" + mirror.getTargetCluster() + connectorEntry.getKey()).collect(Collectors.toSet()));
}
LOGGER.debugCr(reconciliation, "delete MirrorMaker 2.0 connectors: {}", deleteMirrorMaker2ConnectorNames);
Stream<Future<Void>> deletionFutures = deleteMirrorMaker2ConnectorNames.stream().map(connectorName -> apiClient.delete(reconciliation, host, KafkaConnectCluster.REST_API_PORT, connectorName));
Stream<Future<Void>> createUpdateFutures = mirrors.stream().map(mirror -> reconcileMirrorMaker2Connectors(reconciliation, host, apiClient, kafkaMirrorMaker2, mirror, mirrorMaker2Cluster, mirrorMaker2Status, desiredLogging));
return CompositeFuture.join(Stream.concat(deletionFutures, createUpdateFutures).collect(Collectors.toList())).map((Void) null);
});
}
use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.
the class KafkaMirrorMaker2AssemblyOperator method removeAnnotation.
/**
* Patches the KafkaMirrorMaker2 CR to remove the supplied annotation
*/
protected Future<Void> removeAnnotation(Reconciliation reconciliation, KafkaMirrorMaker2 resource, String annotationKey) {
LOGGER.debugCr(reconciliation, "Removing annotation {}", annotationKey);
KafkaMirrorMaker2 patchedKafkaMirrorMaker2 = new KafkaMirrorMaker2Builder(resource).editMetadata().removeFromAnnotations(annotationKey).endMetadata().build();
return resourceOperator.patchAsync(reconciliation, patchedKafkaMirrorMaker2).compose(ignored -> Future.succeededFuture());
}
Aggregations