use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi 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);
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);
return new UserOperatorConfig(namespace, reconciliationInterval, kafkaBootstrapServers, labels, caCertSecretName, caKeySecretName, clusterCaCertSecretName, euoKeySecretName, caNamespace, secretPrefix, aclsAdminApiSupported, clientsCaValidityDays, clientsCaRenewalDays, scramPasswordLength);
}
use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi 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;
}
use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.
the class FeatureGatesTest method testNonExistingGate.
@ParallelTest
public void testNonExistingGate() {
InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> new FeatureGates("+RandomGate"));
assertThat(e.getMessage(), containsString("Unknown feature gate RandomGate found in the configuration"));
}
use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.
the class FeatureGatesTest method testMissingSign.
@ParallelTest
public void testMissingSign() {
InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> new FeatureGates("ControlPlaneListener"));
assertThat(e.getMessage(), containsString("ControlPlaneListener is not a valid feature gate configuration"));
}
use of io.strimzi.operator.common.InvalidConfigurationException in project strimzi by strimzi.
the class FeatureGatesTest method testDuplicateFeatureGateWithDifferentValue.
@ParallelTest
public void testDuplicateFeatureGateWithDifferentValue() {
InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> new FeatureGates("+ControlPlaneListener,-ControlPlaneListener"));
assertThat(e.getMessage(), containsString("Feature gate ControlPlaneListener is configured multiple times"));
}
Aggregations