Search in sources :

Example 16 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.

the class FeatureGatesTest method testDuplicateFeatureGateWithSameValue.

@ParallelTest
public void testDuplicateFeatureGateWithSameValue() {
    InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> new FeatureGates("+ControlPlaneListener,+ControlPlaneListener"));
    assertThat(e.getMessage(), containsString("Feature gate ControlPlaneListener is configured multiple times"));
}
Also used : InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 17 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.

the class FeatureGatesTest method testKraftAndPodSetsDependenciesNotFulfilled.

@ParallelTest
public void testKraftAndPodSetsDependenciesNotFulfilled() {
    InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> new FeatureGates("+UseKRaft,-UseStrimziPodSets"));
    assertThat(e.getMessage(), containsString("The UseKRaft feature gate can be enabled only when the UseStrimziPodSets feature gate is enabled as well."));
}
Also used : InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 18 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.

the class ClusterOperatorConfig method parseKafkaVersions.

private static KafkaVersion.Lookup parseKafkaVersions(String kafkaImages, String connectImages, String mirrorMakerImages, String mirrorMaker2Images) {
    KafkaVersion.Lookup lookup = new KafkaVersion.Lookup(Util.parseMap(kafkaImages), Util.parseMap(connectImages), Util.parseMap(mirrorMakerImages), Util.parseMap(mirrorMaker2Images));
    String image = "";
    String envVar = "";
    try {
        image = "Kafka";
        envVar = STRIMZI_KAFKA_IMAGES;
        lookup.validateKafkaImages(lookup.supportedVersions());
        image = "Kafka Connect";
        envVar = STRIMZI_KAFKA_CONNECT_IMAGES;
        lookup.validateKafkaConnectImages(lookup.supportedVersions());
        image = "Kafka Mirror Maker";
        envVar = STRIMZI_KAFKA_MIRROR_MAKER_IMAGES;
        lookup.validateKafkaMirrorMakerImages(lookup.supportedVersions());
        image = "Kafka Mirror Maker 2";
        envVar = STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES;
        lookup.validateKafkaMirrorMaker2Images(lookup.supportedVersionsForFeature("kafkaMirrorMaker2"));
    } catch (NoImageException | UnsupportedVersionException e) {
        throw new InvalidConfigurationException("Failed to parse default container image configuration for " + image + " from environment variable " + envVar, e);
    }
    return lookup;
}
Also used : KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) NoImageException(io.strimzi.operator.cluster.model.NoImageException) UnsupportedVersionException(io.strimzi.operator.cluster.model.UnsupportedVersionException) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException)

Example 19 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.

the class Session method adminClientProperties.

Properties adminClientProperties() {
    Properties kafkaClientProps = new Properties();
    kafkaClientProps.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, config.get(Config.KAFKA_BOOTSTRAP_SERVERS));
    kafkaClientProps.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, config.get(Config.APPLICATION_ID));
    String securityProtocol = config.get(Config.SECURITY_PROTOCOL);
    boolean tlsEnabled = Boolean.parseBoolean(config.get(Config.TLS_ENABLED));
    if (tlsEnabled && !securityProtocol.isEmpty()) {
        if (!securityProtocol.equals("SSL") && !securityProtocol.equals("SASL_SSL")) {
            throw new InvalidConfigurationException("TLS is enabled but the security protocol does not match SSL or SASL_SSL");
        }
    }
    if (!securityProtocol.isEmpty()) {
        kafkaClientProps.setProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, securityProtocol);
    } else if (tlsEnabled) {
        kafkaClientProps.setProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "SSL");
    } else {
        kafkaClientProps.setProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "PLAINTEXT");
    }
    if (securityProtocol.equals("SASL_SSL") || securityProtocol.equals("SSL") || tlsEnabled) {
        kafkaClientProps.setProperty(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, config.get(Config.TLS_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM));
        if (!config.get(Config.TLS_TRUSTSTORE_LOCATION).isEmpty()) {
            kafkaClientProps.setProperty(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, config.get(Config.TLS_TRUSTSTORE_LOCATION));
        }
        if (!config.get(Config.TLS_TRUSTSTORE_PASSWORD).isEmpty()) {
            if (config.get(Config.TLS_TRUSTSTORE_LOCATION).isEmpty()) {
                throw new InvalidConfigurationException("TLS_TRUSTSTORE_PASSWORD was supplied but TLS_TRUSTSTORE_LOCATION was not supplied");
            }
            kafkaClientProps.setProperty(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, config.get(Config.TLS_TRUSTSTORE_PASSWORD));
        }
        if (!config.get(Config.TLS_KEYSTORE_LOCATION).isEmpty() && !config.get(Config.TLS_KEYSTORE_PASSWORD).isEmpty()) {
            kafkaClientProps.setProperty(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, config.get(Config.TLS_KEYSTORE_LOCATION));
            kafkaClientProps.setProperty(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, config.get(Config.TLS_KEYSTORE_PASSWORD));
        }
    }
    if (Boolean.parseBoolean(config.get(Config.SASL_ENABLED))) {
        setSaslConfigs(kafkaClientProps);
    }
    return kafkaClientProps;
}
Also used : Properties(java.util.Properties) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException)

Example 20 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi-kafka-operator by strimzi.

the class ClusterOperatorConfigTest method testConfigParsingWithMissingEnvVar.

@Test
public void testConfigParsingWithMissingEnvVar() {
    Map<String, String> envVars = new HashMap<>(5);
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMakerImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString());
    for (Map.Entry<String, String> envVar : envVars.entrySet()) {
        Map<String, String> editedEnvVars = new HashMap<>(envVars);
        editedEnvVars.remove(envVar.getKey());
        InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> ClusterOperatorConfig.fromMap(editedEnvVars));
        assertThat(e.getMessage(), containsString(envVar.getKey()));
    }
}
Also used : HashMap(java.util.HashMap) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidConfigurationException (io.strimzi.operator.common.InvalidConfigurationException)26 ParallelTest (io.strimzi.test.annotations.ParallelTest)10 HashMap (java.util.HashMap)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 Test (org.junit.jupiter.api.Test)8 NoImageException (io.strimzi.operator.cluster.model.NoImageException)4 UnsupportedVersionException (io.strimzi.operator.cluster.model.UnsupportedVersionException)4 Labels (io.strimzi.operator.common.model.Labels)4 KafkaVersion (io.strimzi.operator.cluster.model.KafkaVersion)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2