Search in sources :

Example 96 with KafkaMirrorMaker2

use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.

the class KafkaMirrorMaker2ClusterTest method testGenerateDeploymentWithTlsAuth.

@ParallelTest
public void testGenerateDeploymentWithTlsAuth() {
    KafkaMirrorMaker2ClusterSpec targetClusterWithTlsAuth = new KafkaMirrorMaker2ClusterSpecBuilder(this.targetCluster).editOrNewTls().addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("cert.crt").build()).endTls().withAuthentication(new KafkaClientAuthenticationTlsBuilder().withNewCertificateAndKey().withSecretName("user-secret").withCertificate("user.crt").withKey("user.key").endCertificateAndKey().build()).build();
    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withClusters(targetClusterWithTlsAuth).endSpec().build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(3).getName(), is("user-secret"));
    Container cont = getContainer(dep);
    assertThat(cont.getVolumeMounts().get(3).getMountPath(), is(KafkaMirrorMaker2Cluster.TLS_CERTS_BASE_VOLUME_MOUNT + "user-secret"));
    assertThat(AbstractModel.containerEnvVars(cont).get(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_TLS_AUTH_CERT), is("user-secret/user.crt"));
    assertThat(AbstractModel.containerEnvVars(cont).get(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_TLS_AUTH_KEY), is("user-secret/user.key"));
    assertThat(AbstractModel.containerEnvVars(cont).get(KafkaMirrorMaker2Cluster.ENV_VAR_KAFKA_CONNECT_TLS), is("true"));
}
Also used : KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) Container(io.fabric8.kubernetes.api.model.Container) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) KafkaMirrorMaker2ClusterSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpecBuilder) KafkaMirrorMaker2ClusterSpec(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpec) KafkaClientAuthenticationTlsBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTlsBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 97 with KafkaMirrorMaker2

use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.

the class KafkaMirrorMaker2ClusterTest method testNetworkPolicy.

@ParallelTest
public void testNetworkPolicy() {
    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resourceWithMetrics).build();
    KafkaMirrorMaker2Cluster kc = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    kc.generateMetricsAndLogConfigMap(new MetricsAndLogging(metricsCM, null));
    NetworkPolicy np = kc.generateNetworkPolicy(true, "operator-namespace", null);
    assertThat(np.getMetadata().getName(), is(kc.getName()));
    assertThat(np.getSpec().getPodSelector().getMatchLabels(), is(kc.getSelectorLabels().toMap()));
    assertThat(np.getSpec().getIngress().size(), is(2));
    assertThat(np.getSpec().getIngress().get(0).getPorts().size(), is(1));
    assertThat(np.getSpec().getIngress().get(0).getPorts().get(0).getPort().getIntVal(), is(KafkaConnectCluster.REST_API_PORT));
    assertThat(np.getSpec().getIngress().get(0).getFrom().size(), is(2));
    assertThat(np.getSpec().getIngress().get(0).getFrom().get(0).getPodSelector().getMatchLabels(), is(kc.getSelectorLabels().toMap()));
    assertThat(np.getSpec().getIngress().get(0).getFrom().get(0).getNamespaceSelector(), is(nullValue()));
    assertThat(np.getSpec().getIngress().get(0).getFrom().get(1).getPodSelector().getMatchLabels(), is(singletonMap(Labels.STRIMZI_KIND_LABEL, "cluster-operator")));
    assertThat(np.getSpec().getIngress().get(0).getFrom().get(1).getNamespaceSelector().getMatchLabels(), is(nullValue()));
    assertThat(np.getSpec().getIngress().get(1).getPorts().size(), is(1));
    assertThat(np.getSpec().getIngress().get(1).getPorts().get(0).getPort().getIntVal(), is(KafkaConnectCluster.METRICS_PORT));
}
Also used : KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) NetworkPolicy(io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy) MetricsAndLogging(io.strimzi.operator.common.MetricsAndLogging) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 98 with KafkaMirrorMaker2

use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.

the class KafkaMirrorMaker2ClusterTest method testJmxSecretCustomLabelsAndAnnotations.

@ParallelTest
public void testJmxSecretCustomLabelsAndAnnotations() {
    Map<String, String> customLabels = new HashMap<>(2);
    customLabels.put("label1", "value1");
    customLabels.put("label2", "value2");
    Map<String, String> customAnnotations = new HashMap<>(2);
    customAnnotations.put("anno1", "value3");
    customAnnotations.put("anno2", "value4");
    KafkaMirrorMaker2 kafkaMirrorMaker2 = new KafkaMirrorMaker2Builder(this.resource).editSpec().withJmxOptions(new KafkaJmxOptionsBuilder().withAuthentication(new KafkaJmxAuthenticationPasswordBuilder().build()).build()).withNewTemplate().withNewJmxSecret().withNewMetadata().withAnnotations(customAnnotations).withLabels(customLabels).endMetadata().endJmxSecret().endTemplate().endSpec().build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafkaMirrorMaker2, VERSIONS);
    Secret jmxSecret = kmm2.generateJmxSecret();
    for (Map.Entry<String, String> entry : customAnnotations.entrySet()) {
        assertThat(jmxSecret.getMetadata().getAnnotations(), hasEntry(entry.getKey(), entry.getValue()));
    }
    for (Map.Entry<String, String> entry : customLabels.entrySet()) {
        assertThat(jmxSecret.getMetadata().getLabels(), hasEntry(entry.getKey(), entry.getValue()));
    }
}
Also used : KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) Secret(io.fabric8.kubernetes.api.model.Secret) KafkaJmxOptionsBuilder(io.strimzi.api.kafka.model.KafkaJmxOptionsBuilder) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KafkaJmxAuthenticationPasswordBuilder(io.strimzi.api.kafka.model.KafkaJmxAuthenticationPasswordBuilder) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 99 with KafkaMirrorMaker2

use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.

the class KafkaMirrorMaker2Cluster method fromCrd.

/**
 * Creates instance of KafkaMirrorMaker2Cluster from CRD definition.
 *
 * @param reconciliation    The reconciliation
 * @param kafkaMirrorMaker2 The Custom Resource based on which the cluster model should be created.
 * @param versions The image versions for MirrorMaker 2.0 clusters.
 * @return The MirrorMaker 2.0 cluster model.
 */
public static KafkaMirrorMaker2Cluster fromCrd(Reconciliation reconciliation, KafkaMirrorMaker2 kafkaMirrorMaker2, KafkaVersion.Lookup versions) {
    KafkaMirrorMaker2Cluster cluster = new KafkaMirrorMaker2Cluster(reconciliation, kafkaMirrorMaker2);
    KafkaMirrorMaker2Spec spec = kafkaMirrorMaker2.getSpec();
    cluster.setOwnerReference(kafkaMirrorMaker2);
    cluster.setImage(versions.kafkaMirrorMaker2Version(spec.getImage(), spec.getVersion()));
    List<KafkaMirrorMaker2ClusterSpec> clustersList = ModelUtils.asListOrEmptyList(spec.getClusters());
    cluster.setClusters(clustersList);
    KafkaMirrorMaker2ClusterSpec connectCluster = new KafkaMirrorMaker2ClusterSpecBuilder().build();
    String connectClusterAlias = spec.getConnectCluster();
    if (connectClusterAlias != null) {
        connectCluster = clustersList.stream().filter(clustersListItem -> spec.getConnectCluster().equals(clustersListItem.getAlias())).findFirst().orElseThrow(() -> new InvalidResourceException("connectCluster with alias " + connectClusterAlias + " cannot be found in the list of clusters at spec.clusters"));
    }
    cluster.setConfiguration(new KafkaMirrorMaker2Configuration(reconciliation, connectCluster.getConfig().entrySet()));
    KafkaMirrorMaker2Cluster mm2 = fromSpec(reconciliation, buildKafkaConnectSpec(spec, connectCluster), versions, cluster);
    mm2.templatePodLabels = Util.mergeLabelsOrAnnotations(mm2.templatePodLabels, DEFAULT_POD_LABELS);
    return mm2;
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) GenericSecretSource(io.strimzi.api.kafka.model.GenericSecretSource) HashMap(java.util.HashMap) KafkaClientAuthenticationPlain(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationPlain) Supplier(java.util.function.Supplier) KafkaConnectSpecBuilder(io.strimzi.api.kafka.model.KafkaConnectSpecBuilder) KafkaClientAuthenticationOAuth(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationOAuth) Map(java.util.Map) KafkaClientAuthenticationTls(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTls) Volume(io.fabric8.kubernetes.api.model.Volume) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) KafkaMirrorMaker2ClusterSpec(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpec) KafkaMirrorMaker2Spec(io.strimzi.api.kafka.model.KafkaMirrorMaker2Spec) KafkaClientAuthenticationScram(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationScram) ClientTls(io.strimzi.api.kafka.model.ClientTls) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PasswordSecretSource(io.strimzi.api.kafka.model.PasswordSecretSource) KafkaMirrorMaker2Resources(io.strimzi.api.kafka.model.KafkaMirrorMaker2Resources) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) KafkaMirrorMaker2ClusterSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpecBuilder) Entry(java.util.Map.Entry) KafkaConnectSpec(io.strimzi.api.kafka.model.KafkaConnectSpec) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) KafkaMirrorMaker2Spec(io.strimzi.api.kafka.model.KafkaMirrorMaker2Spec) KafkaMirrorMaker2ClusterSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpecBuilder) KafkaMirrorMaker2ClusterSpec(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpec)

Example 100 with KafkaMirrorMaker2

use of io.strimzi.api.kafka.model.KafkaMirrorMaker2 in project strimzi by strimzi.

the class KafkaMirrorMaker2ClusterTest method testGenerateDeploymentWithTlsSameSecret.

@ParallelTest
public void testGenerateDeploymentWithTlsSameSecret() {
    KafkaMirrorMaker2ClusterSpec targetClusterWithTlsAuth = new KafkaMirrorMaker2ClusterSpecBuilder(this.targetCluster).editOrNewTls().addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("cert.crt").build()).endTls().withAuthentication(new KafkaClientAuthenticationTlsBuilder().withNewCertificateAndKey().withSecretName("my-secret").withCertificate("user.crt").withKey("user.key").endCertificateAndKey().build()).build();
    KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource).editSpec().withClusters(targetClusterWithTlsAuth).endSpec().build();
    KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null);
    // 3 = 1 volume from logging/metrics + 2 from above cert mounted for connect and for connectors
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().size(), is(4));
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(2).getName(), is("my-secret"));
}
Also used : KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) KafkaMirrorMaker2ClusterSpecBuilder(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpecBuilder) KafkaMirrorMaker2ClusterSpec(io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpec) KafkaClientAuthenticationTlsBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTlsBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

KafkaMirrorMaker2 (io.strimzi.api.kafka.model.KafkaMirrorMaker2)148 KafkaMirrorMaker2Builder (io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder)108 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)106 KafkaMirrorMaker2ClusterSpec (io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpec)94 ParallelTest (io.strimzi.test.annotations.ParallelTest)94 KafkaMirrorMaker2ClusterSpecBuilder (io.strimzi.api.kafka.model.KafkaMirrorMaker2ClusterSpecBuilder)88 KafkaMirrorMaker2Resources (io.strimzi.api.kafka.model.KafkaMirrorMaker2Resources)72 Reconciliation (io.strimzi.operator.common.Reconciliation)72 List (java.util.List)72 Collections (java.util.Collections)70 HashMap (java.util.HashMap)70 Map (java.util.Map)68 NetworkPolicy (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicy)66 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)64 PodDisruptionBudget (io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget)64 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)64 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)64 OrderedProperties (io.strimzi.operator.common.model.OrderedProperties)64 TestUtils (io.strimzi.test.TestUtils)64 Collections.emptyList (java.util.Collections.emptyList)64