ClusterOperatorConfig { public static ClusterOperatorConfig fromMap(Map<String, String> map) { warningsForRemovedEndVars(map); KafkaVersion.Lookup lookup = parseKafkaVersions(map.get(STRIMZI_KAFKA_IMAGES), map.get(STRIMZI_KAFKA_CONNECT_IMAGES), map.get(STRIMZI_KAFKA_CONNECT_S2I_IMAGES), map.get(STRIMZI_KAFKA_MIRROR_MAKER_IMAGES), map.get(STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES)); return fromMap(map, lookup); } ClusterOperatorConfig(Set<String> namespaces, long reconciliationIntervalMs, long operationTimeoutMs, boolean createClusterRoles, KafkaVersion.Lookup versions, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets); static ClusterOperatorConfig fromMap(Map<String, String> map); static ClusterOperatorConfig fromMap(Map<String, String> map, KafkaVersion.Lookup lookup); Set<String> getNamespaces(); long getReconciliationIntervalMs(); long getOperationTimeoutMs(); boolean isCreateClusterRoles(); KafkaVersion.Lookup versions(); ImagePullPolicy getImagePullPolicy(); List<LocalObjectReference> getImagePullSecrets(); @Override String toString(); static final String STRIMZI_NAMESPACE; static final String STRIMZI_FULL_RECONCILIATION_INTERVAL_MS; static final String STRIMZI_OPERATION_TIMEOUT_MS; static final String STRIMZI_CREATE_CLUSTER_ROLES; static final String STRIMZI_IMAGE_PULL_POLICY; static final String STRIMZI_IMAGE_PULL_SECRETS; static final String STRIMZI_KAFKA_IMAGES; static final String STRIMZI_KAFKA_CONNECT_IMAGES; static final String STRIMZI_KAFKA_CONNECT_S2I_IMAGES; static final String STRIMZI_KAFKA_MIRROR_MAKER_IMAGES; static final String STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES; static final String STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE; static final String STRIMZI_DEFAULT_TLS_SIDECAR_KAFKA_IMAGE; static final String STRIMZI_DEFAULT_TLS_SIDECAR_CRUISE_CONTROL_IMAGE; static final String STRIMZI_DEFAULT_KAFKA_EXPORTER_IMAGE; static final String STRIMZI_DEFAULT_TOPIC_OPERATOR_IMAGE; static final String STRIMZI_DEFAULT_USER_OPERATOR_IMAGE; static final String STRIMZI_DEFAULT_KAFKA_INIT_IMAGE; static final String STRIMZI_DEFAULT_KAFKA_BRIDGE_IMAGE; static final String STRIMZI_DEFAULT_CRUISE_CONTROL_IMAGE; static final long DEFAULT_FULL_RECONCILIATION_INTERVAL_MS; static final long DEFAULT_OPERATION_TIMEOUT_MS; static final boolean DEFAULT_CREATE_CLUSTER_ROLES; }
@Test public void testAnyNamespaceInList() { assertThrows(InvalidConfigurationException.class, () -> { Map<String, String> envVars = new HashMap<>(ClusterOperatorConfigTest.envVars); envVars.put(ClusterOperatorConfig.STRIMZI_NAMESPACE, "foo,*,bar,baz"); ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(envVars, KafkaVersionTestUtils.getKafkaVersionLookup()); }); }
@Test public void testInvalidImagePullPolicyThrowsInvalidConfigurationException() { Map<String, String> envVars = new HashMap<>(ClusterOperatorConfigTest.envVars); envVars.put(ClusterOperatorConfig.STRIMZI_IMAGE_PULL_POLICY, "Sometimes"); assertThrows(InvalidConfigurationException.class, () -> { ClusterOperatorConfig.fromMap(envVars, KafkaVersionTestUtils.getKafkaVersionLookup()); }); }
@Test public void testImagePullSecretsThrowsWithInvalidCharacter() { Map<String, String> envVars = new HashMap<>(ClusterOperatorConfigTest.envVars); envVars.put(ClusterOperatorConfig.STRIMZI_IMAGE_PULL_SECRETS, "secret1, secret2 , secret_3 "); assertThrows(InvalidConfigurationException.class, () -> { ClusterOperatorConfig.fromMap(envVars, KafkaVersionTestUtils.getKafkaVersionLookup()); }); }
@Test public void testImagePullSecretsThrowsWithUpperCaseCharacter() { Map<String, String> envVars = new HashMap<>(ClusterOperatorConfigTest.envVars); envVars.put(ClusterOperatorConfig.STRIMZI_IMAGE_PULL_SECRETS, "Secret"); assertThrows(InvalidConfigurationException.class, () -> { ClusterOperatorConfig.fromMap(envVars, KafkaVersionTestUtils.getKafkaVersionLookup()); }); }
@Test public void testConfigParsingWithAllVersionEnvVars() { 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_CONNECT_S2I_IMAGES, KafkaVersionTestUtils.getKafkaConnectS2iImagesEnvVarString()); envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMakerImagesEnvVarString()); envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString()); assertDoesNotThrow(() -> ClusterOperatorConfig.fromMap(envVars)); }
@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_CONNECT_S2I_IMAGES, KafkaVersionTestUtils.getKafkaConnectS2iImagesEnvVarString()); 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())); } }