Search in sources :

Example 6 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi 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 7 with KafkaBridgeBuilder

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

the class KafkaBridgeClusterTest method testGenerateDeploymentWithOAuthWithClientSecret.

@ParallelTest
public void testGenerateDeploymentWithOAuthWithClientSecret() {
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withAuthentication(new KafkaClientAuthenticationOAuthBuilder().withClientId("my-client-id").withTokenEndpointUri("http://my-oauth-server").withAudience("kafka").withScope("all").withNewClientSecret().withSecretName("my-secret-secret").withKey("my-secret-key").endClientSecret().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\" %s=\"%s\"", ClientConfig.OAUTH_CLIENT_ID, "my-client-id", ClientConfig.OAUTH_TOKEN_ENDPOINT_URI, "http://my-oauth-server", ClientConfig.OAUTH_SCOPE, "all", ClientConfig.OAUTH_AUDIENCE, "kafka")));
}
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) 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 8 with KafkaBridgeBuilder

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

the class KafkaBridgeClusterTest method testGenerateDeploymentWithTls.

@ParallelTest
public void testGenerateDeploymentWithTls() {
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().editOrNewTls().addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("cert.crt").build()).addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-secret").withCertificate("new-cert.crt").build()).addToTrustedCertificates(new CertSecretSourceBuilder().withSecretName("my-another-secret").withCertificate("another-cert.crt").build()).endTls().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("my-secret"));
    assertThat(dep.getSpec().getTemplate().getSpec().getVolumes().get(3).getName(), is("my-another-secret"));
    List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers();
    assertThat(containers.get(0).getVolumeMounts().get(2).getMountPath(), is(KafkaBridgeCluster.TLS_CERTS_BASE_VOLUME_MOUNT + "my-secret"));
    assertThat(containers.get(0).getVolumeMounts().get(3).getMountPath(), is(KafkaBridgeCluster.TLS_CERTS_BASE_VOLUME_MOUNT + "my-another-secret"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_TRUSTED_CERTS), is("my-secret/cert.crt;my-secret/new-cert.crt;my-another-secret/another-cert.crt"));
    assertThat(AbstractModel.containerEnvVars(containers.get(0)).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_TLS), is("true"));
}
Also used : 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) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 9 with KafkaBridgeBuilder

use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi 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 10 with KafkaBridgeBuilder

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

the class KafkaBridgeClusterTest method testImagePullSecrets.

@ParallelTest
public void testImagePullSecrets() {
    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(secret1, secret2).endPod().endTemplate().endSpec().build();
    KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment dep = kbc.generateDeployment(emptyMap(), true, null, null);
    assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().size(), is(2));
    assertThat(dep.getSpec().getTemplate().getSpec().getImagePullSecrets().contains(secret1), is(true));
    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)

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