Skip to content

Commit bbadea8

Browse files
committed
Path with changes in config-model-generator
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
1 parent d2c72f5 commit bbadea8

File tree

4 files changed

+15
-50
lines changed

4 files changed

+15
-50
lines changed

cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConfiguration.java

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,6 @@ public static Map<String, ConfigModel> readConfigModel(KafkaVersion kafkaVersion
152152
}
153153
}
154154

155-
/**
156-
* Gets the custom config model used for plugins directly imported to Strimzi.
157-
* This will ensure that we are able to do dynamic changes instead of rolling update.
158-
*
159-
* @return The custom config model containing available configuration of plugins
160-
*/
161-
public static Map<String, ConfigModel> readCustomConfigModel() {
162-
String name = "/custom-plugin-config-model.json";
163-
164-
try {
165-
try (InputStream in = KafkaConfiguration.class.getResourceAsStream(name)) {
166-
if (in != null) {
167-
ConfigModels configModels = new ObjectMapper().readValue(in, ConfigModels.class);
168-
return configModels.getConfigs();
169-
} else {
170-
// The configuration model does not exist
171-
throw new RuntimeException("Configuration model " + name + " was not found");
172-
}
173-
}
174-
} catch (IOException e) {
175-
throw new RuntimeException("Error reading from classpath resource " + name, e);
176-
}
177-
}
178-
179155
/**
180156
* Return the config properties with their values in this KafkaConfiguration which are not known broker configs.
181157
* These might be consumed by broker plugins.
@@ -184,11 +160,9 @@ public static Map<String, ConfigModel> readCustomConfigModel() {
184160
*/
185161
public Set<String> unknownConfigsWithValues(KafkaVersion kafkaVersion) {
186162
Map<String, ConfigModel> configModel = readConfigModel(kafkaVersion);
187-
Map<String, ConfigModel> customConfigModel = readCustomConfigModel();
188-
189163
Set<String> result = new HashSet<>();
190164
for (Map.Entry<String, String> e :this.asOrderedProperties().asMap().entrySet()) {
191-
if (isCustomConfigurationOption(e.getKey(), configModel) && isCustomConfigurationOption(e.getKey(), customConfigModel)) {
165+
if (isCustomConfigurationOption(e.getKey(), configModel)) {
192166
result.add(e.getKey() + "=" + e.getValue());
193167
}
194168
}
@@ -228,12 +202,6 @@ public static boolean isCustomConfigurationOption(String optionName, Map<String,
228202
* @return True if the property uses the Double type. False otherwise.
229203
*/
230204
public static boolean isDouble(String optionName, Map<String, ConfigModel> configModel) {
231-
ConfigModel optionConfigModel = configModel.get(optionName);
232-
233-
if (optionConfigModel == null) {
234-
return false;
235-
}
236-
237-
return Type.DOUBLE.equals(optionConfigModel.getType());
205+
return Type.DOUBLE.equals(configModel.get(optionName).getType());
238206
}
239207
}

cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/resource/KafkaConfigurationDiff.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class KafkaConfigurationDiff extends AbstractJsonDiff {
4242
private final Reconciliation reconciliation;
4343
private final Collection<AlterConfigOp> nodeConfigDiff;
4444
private final Map<String, ConfigModel> configModel;
45-
private final Map<String, ConfigModel> customConfigModel;
4645
private final boolean isController;
4746
private final boolean isBroker;
4847

@@ -206,7 +205,6 @@ public class KafkaConfigurationDiff extends AbstractJsonDiff {
206205
protected KafkaConfigurationDiff(Reconciliation reconciliation, Config nodeConfigs, String desired, KafkaVersion kafkaVersion, NodeRef nodeRef, boolean isController, boolean isBroker) {
207206
this.reconciliation = reconciliation;
208207
this.configModel = KafkaConfiguration.readConfigModel(kafkaVersion);
209-
this.customConfigModel = KafkaConfiguration.readCustomConfigModel();
210208
this.isController = isController;
211209
this.isBroker = isBroker;
212210
this.nodeConfigDiff = diff(nodeRef, desired, nodeConfigs, configModel);
@@ -328,7 +326,7 @@ private Collection<AlterConfigOp> diff(NodeRef nodeRef, String desired,
328326

329327
private boolean updateOrAdd(String propertyName, Map<String, ConfigModel> configModel, Map<String, String> desiredMap, Map<String, String> currentMap, Collection<AlterConfigOp> updatedCE) {
330328
if (!isIgnorableProperty(propertyName)) {
331-
if (KafkaConfiguration.isCustomConfigurationOption(propertyName, configModel) && KafkaConfiguration.isCustomConfigurationOption(propertyName, customConfigModel)) {
329+
if (KafkaConfiguration.isCustomConfigurationOption(propertyName, configModel)) {
332330
LOGGER.traceCr(reconciliation, "custom property {} has been updated/added {}", propertyName, desiredMap.get(propertyName));
333331
} else if (KafkaConfiguration.isDouble(propertyName, configModel) && areDoublesEqual(propertyName, currentMap, desiredMap)) {
334332
// Double properties get special handling because Kafka might reformat them during serialization
@@ -345,7 +343,7 @@ private boolean updateOrAdd(String propertyName, Map<String, ConfigModel> config
345343
}
346344

347345
private boolean removeProperty(Map<String, ConfigModel> configModel, Collection<AlterConfigOp> updatedCE, String pathValueWithoutSlash, ConfigEntry entry) {
348-
if (KafkaConfiguration.isCustomConfigurationOption(entry.name(), configModel) && KafkaConfiguration.isCustomConfigurationOption(entry.name(), customConfigModel)) {
346+
if (KafkaConfiguration.isCustomConfigurationOption(entry.name(), configModel)) {
349347
// we are deleting custom option
350348
LOGGER.traceCr(reconciliation, "removing custom property {}", entry.name());
351349
} else if (entry.isDefault()) {
@@ -386,9 +384,6 @@ public boolean isEmpty() {
386384
* @return true if the entry matches the scope
387385
*/
388386
private boolean isScope(ConfigEntry entry, Scope scope) {
389-
if (customConfigModel.get(entry.name()) != null) {
390-
return customConfigModel.get(entry.name()).getScope().equals(scope);
391-
}
392387
return configModel.get(entry.name()).getScope().equals(scope);
393388
}
394389

cluster-operator/src/main/resources/custom-plugin-config-model.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

config-model-generator/src/main/java/io/strimzi/build/kafka/metadata/KafkaConfigModelGenerator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ private KafkaConfigModelGenerator() {
5959
public static void main(String[] args) throws Exception {
6060
String version = kafkaVersion();
6161
Map<String, ConfigModel> configs = configs(version);
62+
addCustomPluginConfig(configs);
63+
6264
ObjectMapper mapper = JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).build();
6365
ConfigModels root = new ConfigModels();
6466
root.setVersion(version);
@@ -133,6 +135,15 @@ private static Map<String, ConfigModel> configs(String version) throws NoSuchMet
133135
return result;
134136
}
135137

138+
private static void addCustomPluginConfig(Map<String, ConfigModel> configs) {
139+
String prometheusMetricAllowListName = "prometheus.metrics.reporter.allowlist";
140+
ConfigModel prometheusMetricConfigModel = new ConfigModel();
141+
prometheusMetricConfigModel.setScope(Scope.CLUSTER_WIDE);
142+
prometheusMetricConfigModel.setType(Type.LIST);
143+
144+
configs.put(prometheusMetricAllowListName, prometheusMetricConfigModel);
145+
}
146+
136147
private static Type parseType(String typeStr) {
137148
Type type;
138149
if ("boolean".equals(typeStr)) {

0 commit comments

Comments
 (0)