use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaBridgeClusterTest method testCorsConfiguration.
@ParallelTest
public void testCorsConfiguration() {
KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().editHttp().withNewCors().withAllowedOrigins("https://strimzi.io", "https://cncf.io").withAllowedMethods("GET", "POST", "PUT", "DELETE", "PATCH").endCors().endHttp().endSpec().build();
KafkaBridgeCluster kb = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
Deployment deployment = kb.generateDeployment(new HashMap<>(), true, null, null);
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
assertThat(AbstractModel.containerEnvVars(container).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_CORS_ENABLED), is("true"));
assertThat(AbstractModel.containerEnvVars(container).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_CORS_ALLOWED_ORIGINS), is("https://strimzi.io,https://cncf.io"));
assertThat(AbstractModel.containerEnvVars(container).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_CORS_ALLOWED_METHODS), is("GET,POST,PUT,DELETE,PATCH"));
}
use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaBridgeClusterTest method testGenerateDeploymentWithOAuthWithRefreshToken.
@ParallelTest
public void testGenerateDeploymentWithOAuthWithRefreshToken() {
KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withAuthentication(new KafkaClientAuthenticationOAuthBuilder().withClientId("my-client-id").withTokenEndpointUri("http://my-oauth-server").withNewRefreshToken().withSecretName("my-token-secret").withKey("my-token-key").endRefreshToken().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_REFRESH_TOKEN.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getName(), is("my-token-secret"));
assertThat(cont.getEnv().stream().filter(var -> KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_OAUTH_REFRESH_TOKEN.equals(var.getName())).findFirst().orElseThrow().getValueFrom().getSecretKeyRef().getKey(), is("my-token-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\"", ClientConfig.OAUTH_CLIENT_ID, "my-client-id", ClientConfig.OAUTH_TOKEN_ENDPOINT_URI, "http://my-oauth-server")));
}
use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaBridgeClusterTest method testJvmOptions.
@ParallelTest
public void testJvmOptions() {
KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withJvmOptions(new JvmOptionsBuilder().withXms("128m").withXmx("256m").withXx(Collections.singletonMap("InitiatingHeapOccupancyPercent", "36")).withJavaSystemProperties(new SystemPropertyBuilder().withName("myProperty1").withValue("myValue1").build(), new SystemPropertyBuilder().withName("myProperty2").withValue("myValue2").build()).build()).endSpec().build();
KafkaBridgeCluster kb = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
EnvVar systemProps = kb.getEnvVars().stream().filter(envVar -> AbstractModel.ENV_VAR_STRIMZI_JAVA_SYSTEM_PROPERTIES.equals(envVar.getName())).findFirst().orElse(null);
assertThat(systemProps, is(notNullValue()));
assertThat(systemProps.getValue(), containsString("-DmyProperty1=myValue1"));
assertThat(systemProps.getValue(), containsString("-DmyProperty2=myValue2"));
EnvVar javaOpts = kb.getEnvVars().stream().filter(envVar -> AbstractModel.ENV_VAR_STRIMZI_JAVA_OPTS.equals(envVar.getName())).findFirst().orElse(null);
assertThat(javaOpts, is(notNullValue()));
assertThat(javaOpts.getValue(), containsString("-Xms128m"));
assertThat(javaOpts.getValue(), containsString("-Xmx256m"));
assertThat(javaOpts.getValue(), containsString("-XX:InitiatingHeapOccupancyPercent=36"));
}
use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaBridgeClusterTest method testKafkaBridgeContainerEnvVars.
@ParallelTest
public void testKafkaBridgeContainerEnvVars() {
ContainerEnvVar envVar1 = new ContainerEnvVar();
String testEnvOneKey = "TEST_ENV_1";
String testEnvOneValue = "test.env.one";
envVar1.setName(testEnvOneKey);
envVar1.setValue(testEnvOneValue);
ContainerEnvVar envVar2 = new ContainerEnvVar();
String testEnvTwoKey = "TEST_ENV_2";
String testEnvTwoValue = "test.env.two";
envVar2.setName(testEnvTwoKey);
envVar2.setValue(testEnvTwoValue);
List<ContainerEnvVar> testEnvs = new ArrayList<>();
testEnvs.add(envVar1);
testEnvs.add(envVar2);
ContainerTemplate kafkaBridgeContainer = new ContainerTemplate();
kafkaBridgeContainer.setEnv(testEnvs);
KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withNewTemplate().withBridgeContainer(kafkaBridgeContainer).endTemplate().endSpec().build();
List<EnvVar> kafkaEnvVars = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS).getEnvVars();
assertThat("Failed to correctly set container environment variable: " + testEnvOneKey, kafkaEnvVars.stream().filter(env -> testEnvOneKey.equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals(testEnvOneValue), is(true));
assertThat("Failed to correctly set container environment variable: " + testEnvTwoKey, kafkaEnvVars.stream().filter(env -> testEnvTwoKey.equals(env.getName())).map(EnvVar::getValue).findFirst().orElse("").equals(testEnvTwoValue), is(true));
}
use of io.strimzi.api.kafka.model.KafkaBridgeBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaBridgeClusterTest method testDifferentHttpPort.
@ParallelTest
public void testDifferentHttpPort() {
KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().withNewHttp(1874).endSpec().build();
KafkaBridgeCluster kb = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
// Check ports in container
Deployment dep = kb.generateDeployment(emptyMap(), true, null, null);
Container cont = dep.getSpec().getTemplate().getSpec().getContainers().get(0);
assertThat(cont.getLivenessProbe().getHttpGet().getPort(), is(new IntOrString(KafkaBridgeCluster.REST_API_PORT_NAME)));
assertThat(cont.getReadinessProbe().getHttpGet().getPort(), is(new IntOrString(KafkaBridgeCluster.REST_API_PORT_NAME)));
assertThat(cont.getPorts().get(0).getContainerPort(), is(Integer.valueOf(1874)));
assertThat(dep.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts().get(0).getName(), is(KafkaBridgeCluster.REST_API_PORT_NAME));
assertThat(dep.getSpec().getTemplate().getSpec().getContainers().get(0).getPorts().get(0).getProtocol(), is("TCP"));
// Check ports on Service
Service svc = kb.generateService();
assertThat(svc.getSpec().getType(), is("ClusterIP"));
assertThat(svc.getMetadata().getLabels(), is(expectedServiceLabels(kb.getName())));
assertThat(svc.getSpec().getSelector(), is(expectedSelectorLabels()));
assertThat(svc.getSpec().getPorts().get(0).getPort(), is(Integer.valueOf(1874)));
assertThat(svc.getSpec().getPorts().get(0).getName(), is(KafkaBridgeCluster.REST_API_PORT_NAME));
assertThat(svc.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
assertThat(svc.getMetadata().getAnnotations(), is(kbc.getDiscoveryAnnotation(1874)));
checkOwnerReference(kbc.createOwnerReference(), svc);
}
Aggregations