Search in sources :

Example 96 with GenericKafkaListener

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.

the class ListenersValidatorTest method testValidateTimeoutsOauth.

@ParallelTest
public void testValidateTimeoutsOauth() {
    KafkaListenerAuthenticationOAuthBuilder authBuilder = new KafkaListenerAuthenticationOAuthBuilder().withConnectTimeoutSeconds(0);
    GenericKafkaListenerBuilder listenerBuilder = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(authBuilder.build());
    List<GenericKafkaListener> listeners = asList(listenerBuilder.withAuth(authBuilder.build()).build());
    Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
    assertThat(exception.getMessage(), allOf(containsString("listener listener1: 'connectTimeoutSeconds' needs to be a positive integer (set to: 0)")));
    // set valid connectTimeoutSeconds
    authBuilder.withConnectTimeoutSeconds(1);
    List<GenericKafkaListener> listeners2 = asList(listenerBuilder.withAuth(authBuilder.build()).build());
    exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners2));
    assertThat(exception.getMessage(), allOf(not(containsString("listener listener1: 'connectTimeoutSeconds' needs to be a positive integer"))));
    // 
    // Repeat for readTimeoutSeconds
    // 
    authBuilder.withConnectTimeoutSeconds(null).withReadTimeoutSeconds(0);
    List<GenericKafkaListener> listeners3 = asList(listenerBuilder.withAuth(authBuilder.build()).build());
    exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners3));
    assertThat(exception.getMessage(), allOf(containsString("listener listener1: 'readTimeoutSeconds' needs to be a positive integer (set to: 0)")));
    // set valid readTimeoutSeconds
    authBuilder.withReadTimeoutSeconds(1);
    List<GenericKafkaListener> listeners4 = asList(listenerBuilder.withAuth(authBuilder.build()).build());
    exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners4));
    assertThat(exception.getMessage(), allOf(not(containsString("listener listener1: 'readTimeoutSeconds' needs to be a positive integer"))));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 97 with GenericKafkaListener

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.

the class ListenersValidatorTest method testValidateOauth.

@ParallelTest
public void testValidateOauth() {
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(new KafkaListenerAuthenticationOAuthBuilder().build()).build();
    List<GenericKafkaListener> listeners = asList(listener1);
    Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
    assertThat(exception.getMessage(), allOf(containsString("listener listener1: Introspection endpoint URI or JWKS endpoint URI has to be specified"), containsString("listener listener1: Valid Issuer URI has to be specified or 'checkIssuer' set to 'false'")));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 98 with GenericKafkaListener

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.

the class ListenersValidatorTest method testRouteListener.

@ParallelTest
public void testRouteListener() {
    String name = "route";
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName(name).withPort(9092).withType(KafkaListenerType.ROUTE).withTls(true).withNewConfiguration().withIngressClass("my-ingress").withUseServiceDnsDomain(true).withExternalTrafficPolicy(ExternalTrafficPolicy.LOCAL).withIpFamilyPolicy(IpFamilyPolicy.REQUIRE_DUAL_STACK).withIpFamilies(IpFamily.IPV4, IpFamily.IPV6).withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).withLoadBalancerSourceRanges(asList("10.0.0.0/8", "130.211.204.1/32")).withFinalizers(asList("service.kubernetes.io/load-balancer-cleanup")).withNewBootstrap().withAlternativeNames(asList("my-name-1", "my-name-2")).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).withLabels(Collections.singletonMap("label", "label-value")).build()).endConfiguration().build();
    List<GenericKafkaListener> listeners = asList(listener1);
    List<String> expectedErrors = asList("listener " + name + " cannot configure ingressClass because it is not Ingress based listener", "listener " + name + " cannot configure useServiceDnsDomain because it is not internal listener", "listener " + name + " cannot configure externalTrafficPolicy because it is not LoadBalancer or NodePort based listener", "listener " + name + " cannot configure loadBalancerSourceRanges because it is not LoadBalancer based listener", "listener " + name + " cannot configure finalizers because it is not LoadBalancer based listener", "listener " + name + " cannot configure preferredAddressType because it is not NodePort based listener", "listener " + name + " cannot configure bootstrap.loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure bootstrap.nodePort because it is not NodePort based listener", "listener " + name + " cannot configure brokers[].loadBalancerIP because it is not LoadBalancer based listener", "listener " + name + " cannot configure brokers[].nodePort because it is not NodePort based listener");
    assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder(expectedErrors.toArray()));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 99 with GenericKafkaListener

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.

the class ListenersValidatorTest method testIngressListenerHostNames.

@ParallelTest
public void testIngressListenerHostNames() {
    GenericKafkaListener listener = new GenericKafkaListenerBuilder().withName("ingress").withPort(9092).withType(KafkaListenerType.INGRESS).withTls(true).build();
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a configuration with host names which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBrokers((List<GenericKafkaListenerConfigurationBroker>) null).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a bootstrap host name which is required for Ingress based listeners", "listener ingress is missing a broker configuration with host names which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBootstrap(new GenericKafkaListenerConfigurationBootstrapBuilder().build()).withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).build()).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a bootstrap host name which is required for Ingress based listeners", "listener ingress is missing a broker host name for broker with ID 0 which is required for Ingress based listeners", "listener ingress is missing a broker host name for broker with ID 1 which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBootstrap(new GenericKafkaListenerConfigurationBootstrapBuilder().withHost("bootstrap-host").build()).withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("host-1").build()).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), containsInAnyOrder("listener ingress is missing a broker host name for broker with ID 0 which is required for Ingress based listeners"));
    listener.setConfiguration(new GenericKafkaListenerConfigurationBuilder().withBootstrap(new GenericKafkaListenerConfigurationBootstrapBuilder().withHost("bootstrap-host").build()).withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withHost("host-0").build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withHost("host-1").build()).build());
    assertThat(ListenersValidator.validateAndGetErrorMessages(2, asList(listener)), hasSize(0));
}
Also used : GenericKafkaListenerConfigurationBootstrapBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBootstrapBuilder) GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerConfigurationBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBuilder) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) GenericKafkaListenerConfigurationBroker(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 100 with GenericKafkaListener

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener in project strimzi by strimzi.

the class ListenersValidatorTest method testValidateAudienceOauth.

@ParallelTest
public void testValidateAudienceOauth() {
    KafkaListenerAuthenticationOAuthBuilder authBuilder = new KafkaListenerAuthenticationOAuthBuilder().withCheckAudience(true);
    GenericKafkaListenerBuilder listenerBuilder = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(authBuilder.build());
    GenericKafkaListener listener = listenerBuilder.withAuth(authBuilder.build()).build();
    List<GenericKafkaListener> listeners = asList(listener);
    Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
    assertThat(exception.getMessage(), allOf(containsString("listener listener1: 'clientId' has to be configured when 'checkAudience' is 'true'")));
    // set clientId
    authBuilder.withClientId("kafka");
    listener = listenerBuilder.withAuth(authBuilder.build()).build();
    List<GenericKafkaListener> listeners2 = asList(listener);
    exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners2));
    assertThat(exception.getMessage(), allOf(not(containsString("listener listener1: 'clientId' has to be configured when 'checkAudience' is 'true'"))));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)160 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)116 ParallelTest (io.strimzi.test.annotations.ParallelTest)102 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)50 ArrayList (java.util.ArrayList)38 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)18 Matchers.containsString (org.hamcrest.Matchers.containsString)16 KafkaListenerAuthenticationOAuth (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuth)12 KafkaListenerAuthenticationOAuthBuilder (io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder)12 Kafka (io.strimzi.api.kafka.model.Kafka)10 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 HTTPIngressPathBuilder (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPathBuilder)8 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)8 IngressTLSBuilder (io.fabric8.kubernetes.api.model.networking.v1.IngressTLSBuilder)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 NetworkPolicyIngressRule (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRule)6 NetworkPolicyIngressRuleBuilder (io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyIngressRuleBuilder)6 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)6