Search in sources :

Example 21 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaBridgeClusterTest method testGenerateDeploymentWithOAuthWithMissingClientSecret.

@ParallelTest
public void testGenerateDeploymentWithOAuthWithMissingClientSecret() {
    assertThrows(InvalidResourceException.class, () -> {
        KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withAuthentication(new KafkaClientAuthenticationOAuthBuilder().withClientId("my-client-id").withTokenEndpointUri("http://my-oauth-server").build()).endSpec().build();
        KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    });
}
Also used : KafkaClientAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationOAuthBuilder) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 22 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaBridgeClusterTest method testGenerateDeploymentWithScramSha512Auth.

@ParallelTest
public void testGenerateDeploymentWithScramSha512Auth() {
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withNewKafkaClientAuthenticationScramSha512().withUsername("user1").withNewPasswordSecret().withSecretName("user1-secret").withPassword("password").endPasswordSecret().endKafkaClientAuthenticationScramSha512().endSpec().build();
    KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kbc.generateDeployment(emptyMap(), true, null, null);
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(2).getName(), is("user1-secret"));
    List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers();
    assertThat(containers.get(0).getVolumeMounts().get(2).getMountPath(), is(KafkaBridgeCluster.PASSWORD_VOLUME_MOUNT + "user1-secret"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_SASL_PASSWORD_FILE), is("user1-secret/password"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_SASL_USERNAME), is("user1"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_SASL_MECHANISM), is("scram-sha-512"));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 23 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaBridgeClusterTest method testImagePullSecretsBoth.

@ParallelTest
public void testImagePullSecretsBoth() {
    LocalObjectReference secret1 = new LocalObjectReference("some-pull-secret");
    LocalObjectReference secret2 = new LocalObjectReference("some-other-pull-secret");
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withNewTemplate().withNewPod().withImagePullSecrets(secret2).endPod().endTemplate().endSpec().build();
    KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kbc.generateDeployment(emptyMap(), true, null, singletonList(secret1));
    assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().size(), is(1));
    assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().contains(secret1), is(false));
    assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().contains(secret2), is(true));
}
Also used : KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 24 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaBridgeClusterTest method testProbeConfiguration.

@ParallelTest
public void testProbeConfiguration() {
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withNewLivenessProbe().withInitialDelaySeconds(20).withPeriodSeconds(21).withTimeoutSeconds(22).endLivenessProbe().withNewReadinessProbe().withInitialDelaySeconds(30).withPeriodSeconds(31).withTimeoutSeconds(32).endReadinessProbe().endSpec().build();
    KafkaBridgeCluster kb = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kb.generateDeployment(new HashMap<String, String>(), true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(cont.getLivenessProbe().getInitialDelaySeconds(), is(Integer.valueOf(20)));
    assertThat(cont.getLivenessProbe().getPeriodSeconds(), is(Integer.valueOf(21)));
    assertThat(cont.getLivenessProbe().getTimeoutSeconds(), is(Integer.valueOf(22)));
    assertThat(cont.getReadinessProbe().getInitialDelaySeconds(), is(Integer.valueOf(30)));
    assertThat(cont.getReadinessProbe().getPeriodSeconds(), is(Integer.valueOf(31)));
    assertThat(cont.getReadinessProbe().getTimeoutSeconds(), is(Integer.valueOf(32)));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 25 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.

the class KafkaBridgeClusterTest method testGenerateDeploymentWithOAuthWithTls.

@ParallelTest
public void testGenerateDeploymentWithOAuthWithTls() {
    CertSecretSource cert1 = new CertSecretSourceBuilder().withSecretName("first-certificate").withCertificate("ca.crt").build();
    CertSecretSource cert2 = new CertSecretSourceBuilder().withSecretName("second-certificate").withCertificate("tls.crt").build();
    CertSecretSource cert3 = new CertSecretSourceBuilder().withSecretName("first-certificate").withCertificate("ca2.crt").build();
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withAuthentication(new KafkaClientAuthenticationOAuthBuilder().withClientId("my-client-id").withTokenEndpointUri("http://my-oauth-server").withNewClientSecret().withSecretName("my-secret-secret").withKey("my-secret-key").endClientSecret().withDisableTlsHostnameVerification(true).withTlsTrustedCertificates(cert1, cert2, cert3).build()).endSpec().build();
    KafkaBridgeCluster kb = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kb.generateDeployment(emptyMap(), true, null, null);
    Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(cont.getEnv().stream().filter(var -> KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_SASL_MECHANISM.equals(var.getName())).findFirst().orElseThrow().getValue(), is("oauth"));
    assertThat(cont.getEnv().stream().filter(var -> KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_OAUTH_CLIENT_SECRET.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getName(), is("my-secret-secret"));
    assertThat(cont.getEnv().stream().filter(var -> KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_OAUTH_CLIENT_SECRET.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getKey(), is("my-secret-key"));
    assertThat(cont.getEnv().stream().filter(var -> KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_OAUTH_CONFIG.equals(var.getName())).findFirst().orElseThrow().getValue().trim(), is(String.format("%s=\"%s\" %s=\"%s\" %s=\"%s\"", ClientConfig.OAUTH_CLIENT_ID, "my-client-id", ClientConfig.OAUTH_TOKEN_ENDPOINT_URI, "http://my-oauth-server", ServerConfig.OAUTH_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM, "")));
    // Volume mounts
    assertThat(cont.getVolumeMounts().stream().filter(mount -> "oauth-certs-0".equals(mount.getName())).findFirst().orElseThrow().getMountPath(), is(KafkaBridgeCluster.OAUTH_TLS_CERTS_BASE_VOLUME_MOUNT + "/first-certificate-0"));
    assertThat(cont.getVolumeMounts().stream().filter(mount -> "oauth-certs-1".equals(mount.getName())).findFirst().orElseThrow().getMountPath(), is(KafkaBridgeCluster.OAUTH_TLS_CERTS_BASE_VOLUME_MOUNT + "/second-certificate-1"));
    assertThat(cont.getVolumeMounts().stream().filter(mount -> "oauth-certs-2".equals(mount.getName())).findFirst().orElseThrow().getMountPath(), is(KafkaBridgeCluster.OAUTH_TLS_CERTS_BASE_VOLUME_MOUNT + "/first-certificate-2"));
    // Volumes
    List<KeyToPath> cert1Items = dep.getSpec().getTemplate().getSpec().getVolumes().stream().filter(vol -> "oauth-certs-0".equals(vol.getName())).findFirst().orElseThrow().getSecret().getItems();
    assertThat(cert1Items.size(), is(1));
    assertThat(cert1Items.get(0).getKey(), is("ca.crt"));
    assertThat(cert1Items.get(0).getPath(), is("tls.crt"));
    List<KeyToPath> cert2Items = dep.getSpec().getTemplate().getSpec().getVolumes().stream().filter(vol -> "oauth-certs-1".equals(vol.getName())).findFirst().orElseThrow().getSecret().getItems();
    assertThat(cert2Items.size(), is(1));
    assertThat(cert2Items.get(0).getKey(), is("tls.crt"));
    assertThat(cert2Items.get(0).getPath(), is("tls.crt"));
    List<KeyToPath> cert3Items = dep.getSpec().getTemplate().getSpec().getVolumes().stream().filter(vol -> "oauth-certs-2".equals(vol.getName())).findFirst().orElseThrow().getSecret().getItems();
    assertThat(cert3Items.size(), is(1));
    assertThat(cert3Items.get(0).getKey(), is("ca2.crt"));
    assertThat(cert3Items.get(0).getPath(), is("tls.crt"));
}
Also used : KafkaClientAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationOAuthBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) ClientConfig(io.strimzi.kafka.oauth.client.ClientConfig) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) JvmOptionsBuilder(io.strimzi.api.kafka.model.JvmOptionsBuilder) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) JaegerTracing(io.strimzi.api.kafka.model.tracing.JaegerTracing) Map(java.util.Map) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) Affinity(io.fabric8.kubernetes.api.model.Affinity) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) IpFamilyPolicy(io.strimzi.api.kafka.model.template.IpFamilyPolicy) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) ParallelTest(io.strimzi.test.annotations.ParallelTest) Collections.emptyList(java.util.Collections.emptyList) KafkaClientAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationOAuthBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KafkaBridgeHttpConfig(io.strimzi.api.kafka.model.KafkaBridgeHttpConfig) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) List(java.util.List) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) Labels(io.strimzi.operator.common.model.Labels) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ContainerTemplate(io.strimzi.api.kafka.model.template.ContainerTemplate) Container(io.fabric8.kubernetes.api.model.Container) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) KafkaClientAuthenticationTlsBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTlsBuilder) IpFamily(io.strimzi.api.kafka.model.template.IpFamily) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) ArrayList(java.util.ArrayList) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) DeploymentStrategy(io.strimzi.api.kafka.model.template.DeploymentStrategy) TestUtils(io.strimzi.test.TestUtils) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Collections.singletonMap(java.util.Collections.singletonMap) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) KafkaBridgeResources(io.strimzi.api.kafka.model.KafkaBridgeResources) Collections.emptyMap(java.util.Collections.emptyMap) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) Toleration(io.fabric8.kubernetes.api.model.Toleration) ServerConfig(io.strimzi.kafka.oauth.server.ServerConfig) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) SystemPropertyBuilder(io.strimzi.api.kafka.model.SystemPropertyBuilder) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) KeyToPath(io.fabric8.kubernetes.api.model.KeyToPath) Container(io.fabric8.kubernetes.api.model.Container) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

KafkaBridge (io.strimzi.api.kafka.model.KafkaBridge)66 KafkaBridgeBuilder (io.strimzi.api.kafka.model.KafkaBridgeBuilder)66 ParallelTest (io.strimzi.test.annotations.ParallelTest)62 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)54 Container (io.fabric8.kubernetes.api.model.Container)34 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)26 PodDisruptionBudget (io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget)22 Service (io.fabric8.kubernetes.api.model.Service)20 CertSecretSourceBuilder (io.strimzi.api.kafka.model.CertSecretSourceBuilder)20 HashMap (java.util.HashMap)20 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)20 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)18 Quantity (io.fabric8.kubernetes.api.model.Quantity)18 KafkaClientAuthenticationOAuthBuilder (io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationOAuthBuilder)18 KafkaClientAuthenticationTlsBuilder (io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationTlsBuilder)18 Affinity (io.fabric8.kubernetes.api.model.Affinity)16 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)16 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)16 LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)16 NodeSelectorTermBuilder (io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder)16