Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide if option is custom or not in a single place #10643

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/

package io.strimzi.operator.cluster.model;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -288,7 +287,7 @@ public Set<String> unknownConfigsWithValues(KafkaVersion kafkaVersion) {
Map<String, ConfigModel> configModel = readConfigModel(kafkaVersion);
Set<String> result = new HashSet<>();
for (Map.Entry<String, String> e :this.asOrderedProperties().asMap().entrySet()) {
if (!configModel.containsKey(e.getKey())) {
if (isCustomConfigurationOption(e.getKey(), configModel)) {
result.add(e.getKey() + "=" + e.getValue());
}
}
Expand Down Expand Up @@ -317,6 +316,21 @@ public Set<String> controllerConfigsWithValues() {
* @return True if the configuration is empty. False otherwise.
*/
public boolean isEmpty() {
return this.asOrderedProperties().asMap().size() == 0;
return this.asOrderedProperties().asMap().isEmpty();
}

/**
* Checks if the Kafka configuration option is part of the Kafka configuration or is a custom option not recognized
* by Kafka broker configuration APIs. Custom options can be for example options used by plugins etc. But right now,
* also the options prefixed with the listener prefix as considered custom by this method as well (which is correct
* for the time being as we anyway do a rolling update when they change).
*
* @param optionName Name of the option to check
* @param configModel Configuration model for given Kafka version
*
* @return True if entry is custom (not default). False otherwise.
*/
public static boolean isCustomConfigurationOption(String optionName, Map<String, ConfigModel> configModel) {
return !configModel.containsKey(optionName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private Collection<AlterConfigOp> diff(NodeRef brokerNodeRef, String desired,

private void updateOrAdd(String propertyName, Map<String, ConfigModel> configModel, Map<String, String> desiredMap, Collection<AlterConfigOp> updatedCE, boolean nodeIsController) {
if (!isIgnorableProperty(propertyName, nodeIsController)) {
if (isCustomEntry(propertyName, configModel)) {
if (KafkaConfiguration.isCustomConfigurationOption(propertyName, configModel)) {
LOGGER.traceCr(reconciliation, "custom property {} has been updated/added {}", propertyName, desiredMap.get(propertyName));
} else {
LOGGER.traceCr(reconciliation, "property {} has been updated/added {}", propertyName, desiredMap.get(propertyName));
Expand All @@ -214,7 +214,7 @@ private void updateOrAdd(String propertyName, Map<String, ConfigModel> configMod
}

private void removeProperty(Map<String, ConfigModel> configModel, Collection<AlterConfigOp> updatedCE, String pathValueWithoutSlash, ConfigEntry entry, boolean nodeIsController) {
if (isCustomEntry(entry.name(), configModel)) {
if (KafkaConfiguration.isCustomConfigurationOption(entry.name(), configModel)) {
// we are deleting custom option
LOGGER.traceCr(reconciliation, "removing custom property {}", entry.name());
} else if (entry.isDefault()) {
Expand Down Expand Up @@ -242,15 +242,4 @@ private void removeProperty(Map<String, ConfigModel> configModel, Collection<Alt
public boolean isEmpty() {
return brokerConfigDiff.isEmpty();
}

/**
* For some reason not all default entries have set ConfigEntry.ConfigSource.DEFAULT_CONFIG so we need to compare
* @param entryName tested ConfigEntry
* @param configModel configModel
* @return true if entry is custom (not default)
*/
private static boolean isCustomEntry(String entryName, Map<String, ConfigModel> configModel) {
return !configModel.containsKey(entryName);
}

}
Loading