Search in sources :

Example 21 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi-kafka-operator 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 22 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi-kafka-operator 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 23 with InvalidConfigurationException

use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi-kafka-operator 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 24 with InvalidConfigurationException

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

the class ClusterOperatorConfig method parseLabels.

/**
 * Parse labels from String into the Labels format.
 *
 * @param vars              Map with configuration variables
 * @param configurationKey  Key containing the string with labels
 * @return                  Labels object with the Labels or null if no labels are configured
 */
private static Labels parseLabels(Map<String, String> vars, String configurationKey) {
    String labelsString = vars.get(configurationKey);
    Labels labels = null;
    if (labelsString != null) {
        try {
            labels = Labels.fromString(labelsString);
        } catch (Exception e) {
            throw new InvalidConfigurationException("Failed to parse labels from " + configurationKey, e);
        }
    }
    return labels;
}
Also used : Labels(io.strimzi.operator.common.model.Labels) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) NoImageException(io.strimzi.operator.cluster.model.NoImageException) UnsupportedVersionException(io.strimzi.operator.cluster.model.UnsupportedVersionException) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException)

Example 25 with InvalidConfigurationException

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

the class UserOperatorConfig method fromMap.

/**
 * Loads configuration parameters from a related map
 *
 * @param map   map from which loading configuration parameters
 * @return  Cluster Operator configuration instance
 */
@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity" })
public static UserOperatorConfig fromMap(Map<String, String> map) {
    String namespace = map.get(UserOperatorConfig.STRIMZI_NAMESPACE);
    if (namespace == null || namespace.isEmpty()) {
        throw new InvalidConfigurationException(UserOperatorConfig.STRIMZI_NAMESPACE + " cannot be null");
    }
    long reconciliationInterval = DEFAULT_FULL_RECONCILIATION_INTERVAL_MS;
    String reconciliationIntervalEnvVar = map.get(UserOperatorConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS);
    if (reconciliationIntervalEnvVar != null) {
        reconciliationInterval = Long.parseLong(reconciliationIntervalEnvVar);
    }
    int scramPasswordLength = DEFAULT_SCRAM_SHA_PASSWORD_LENGTH;
    String scramPasswordLengthEnvVar = map.get(UserOperatorConfig.STRIMZI_SCRAM_SHA_PASSWORD_LENGTH);
    if (scramPasswordLengthEnvVar != null) {
        scramPasswordLength = Integer.parseInt(scramPasswordLengthEnvVar);
    }
    String kafkaBootstrapServers = DEFAULT_KAFKA_BOOTSTRAP_SERVERS;
    String kafkaBootstrapServersEnvVar = map.get(UserOperatorConfig.STRIMZI_KAFKA_BOOTSTRAP_SERVERS);
    if (kafkaBootstrapServersEnvVar != null && !kafkaBootstrapServersEnvVar.isEmpty()) {
        kafkaBootstrapServers = kafkaBootstrapServersEnvVar;
    }
    Labels labels;
    try {
        labels = Labels.fromString(map.get(STRIMZI_LABELS));
    } catch (Exception e) {
        throw new InvalidConfigurationException("Failed to parse labels from " + STRIMZI_LABELS, e);
    }
    String caCertSecretName = map.get(UserOperatorConfig.STRIMZI_CA_CERT_SECRET_NAME);
    if (caCertSecretName == null || caCertSecretName.isEmpty()) {
        throw new InvalidConfigurationException(UserOperatorConfig.STRIMZI_CA_CERT_SECRET_NAME + " cannot be null");
    }
    String caKeySecretName = map.get(UserOperatorConfig.STRIMZI_CA_KEY_SECRET_NAME);
    if (caKeySecretName == null || caKeySecretName.isEmpty()) {
        throw new InvalidConfigurationException(UserOperatorConfig.STRIMZI_CA_KEY_SECRET_NAME + " cannot be null");
    }
    String clusterCaCertSecretName = map.get(UserOperatorConfig.STRIMZI_CLUSTER_CA_CERT_SECRET_NAME);
    String euoKeySecretName = map.get(UserOperatorConfig.STRIMZI_EO_KEY_SECRET_NAME);
    String caNamespace = map.get(UserOperatorConfig.STRIMZI_CA_NAMESPACE);
    if (caNamespace == null || caNamespace.isEmpty()) {
        caNamespace = namespace;
    }
    String secretPrefix = map.get(UserOperatorConfig.STRIMZI_SECRET_PREFIX);
    if (secretPrefix == null || secretPrefix.isEmpty()) {
        secretPrefix = DEFAULT_SECRET_PREFIX;
    }
    boolean aclsAdminApiSupported = getBooleanProperty(map, UserOperatorConfig.STRIMZI_ACLS_ADMIN_API_SUPPORTED, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
    boolean kraftEnabled = getBooleanProperty(map, UserOperatorConfig.STRIMZI_KRAFT_ENABLED, UserOperatorConfig.DEFAULT_STRIMZI_KRAFT_ENABLED);
    int clientsCaValidityDays = getIntProperty(map, UserOperatorConfig.STRIMZI_CLIENTS_CA_VALIDITY, CertificateAuthority.DEFAULT_CERTS_VALIDITY_DAYS);
    int clientsCaRenewalDays = getIntProperty(map, UserOperatorConfig.STRIMZI_CLIENTS_CA_RENEWAL, CertificateAuthority.DEFAULT_CERTS_RENEWAL_DAYS);
    List<String> maintenanceWindows = parseMaintenanceTimeWindows(map.get(UserOperatorConfig.STRIMZI_MAINTENANCE_TIME_WINDOWS));
    return new UserOperatorConfig(namespace, reconciliationInterval, kafkaBootstrapServers, labels, caCertSecretName, caKeySecretName, clusterCaCertSecretName, euoKeySecretName, caNamespace, secretPrefix, aclsAdminApiSupported, kraftEnabled, clientsCaValidityDays, clientsCaRenewalDays, scramPasswordLength, maintenanceWindows);
}
Also used : Labels(io.strimzi.operator.common.model.Labels) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException)

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