Skip to content

Commit

Permalink
Refactoring around bridge ConfigMap naming and volume mounts (#11075)
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Patierno <[email protected]>
  • Loading branch information
ppatierno authored Jan 25, 2025
1 parent 0afa532 commit 515daa4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public static String serviceName(String clusterName) {
}

/**
* Returns the name of the Kafka Bridge metrics and log {@code ConfigMap} for a {@code KafkaBridge} cluster of the given name.
* Returns the name of the Kafka Bridge {@code ConfigMap} for a {@code KafkaBridge} cluster of the given name.
* Such {@code ConfigMap} contains metrics, logging and overall bridge configuration parameters.
* @param clusterName The {@code metadata.name} of the {@code KafkaBridge} resource.
* @return The name of the corresponding Kafka Bridge metrics and log {@code ConfigMap}.
* @return The name of the corresponding Kafka Bridge {@code ConfigMap}.
*/
public static String metricsAndLogConfigMapName(String clusterName) {
public static String configMapName(String clusterName) {
return clusterName + "-bridge-config";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public class KafkaBridgeCluster extends AbstractModel implements SupportsLogging
protected static final String TLS_CERTS_BASE_VOLUME_MOUNT = "/opt/strimzi/bridge-certs/";
protected static final String PASSWORD_VOLUME_MOUNT = "/opt/strimzi/bridge-password/";
protected static final String ENV_VAR_KAFKA_INIT_INIT_FOLDER_KEY = "INIT_FOLDER";
private static final String LOG_AND_METRICS_CONFIG_VOLUME_NAME = "kafka-metrics-and-logging";
private static final String LOG_AND_METRICS_CONFIG_VOLUME_MOUNT = "/opt/strimzi/custom-config/";
private static final String KAFKA_BRIDGE_CONFIG_VOLUME_NAME = "kafka-bridge-configurations";
private static final String KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT = "/opt/strimzi/custom-config/";

// Cluster Operator environment variables for custom discovery labels and annotations
protected static final String CO_ENV_VAR_CUSTOM_SERVICE_LABELS = "STRIMZI_CUSTOM_KAFKA_BRIDGE_SERVICE_LABELS";
Expand Down Expand Up @@ -281,7 +281,7 @@ protected List<ContainerPort> getContainerPortList() {
protected List<Volume> getVolumes(boolean isOpenShift) {
List<Volume> volumeList = new ArrayList<>(2);
volumeList.add(VolumeUtils.createTempDirVolume(templatePod));
volumeList.add(VolumeUtils.createConfigMapVolume(LOG_AND_METRICS_CONFIG_VOLUME_NAME, KafkaBridgeResources.metricsAndLogConfigMapName(cluster)));
volumeList.add(VolumeUtils.createConfigMapVolume(KAFKA_BRIDGE_CONFIG_VOLUME_NAME, KafkaBridgeResources.configMapName(cluster)));

if (tls != null) {
CertUtils.createTrustedCertificatesVolumes(volumeList, tls.getTrustedCertificates(), isOpenShift);
Expand All @@ -302,7 +302,7 @@ protected List<VolumeMount> getVolumeMounts() {
List<VolumeMount> volumeMountList = new ArrayList<>(2);

volumeMountList.add(VolumeUtils.createTempDirVolumeMount());
volumeMountList.add(VolumeUtils.createVolumeMount(LOG_AND_METRICS_CONFIG_VOLUME_NAME, LOG_AND_METRICS_CONFIG_VOLUME_MOUNT));
volumeMountList.add(VolumeUtils.createVolumeMount(KAFKA_BRIDGE_CONFIG_VOLUME_NAME, KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT));

if (tls != null) {
CertUtils.createTrustedCertificatesVolumeMounts(volumeMountList, tls.getTrustedCertificates(), TLS_CERTS_BASE_VOLUME_MOUNT);
Expand Down Expand Up @@ -575,7 +575,7 @@ public ConfigMap generateBridgeConfigMap(MetricsAndLogging metricsAndLogging) {

return ConfigMapUtils
.createConfigMap(
KafkaBridgeResources.metricsAndLogConfigMapName(cluster),
KafkaBridgeResources.configMapName(cluster),
namespace,
labels,
ownerReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected Future<KafkaBridgeStatus> createOrUpdate(Reconciliation reconciliation
.compose(metricsAndLogging -> {
ConfigMap configMap = bridge.generateBridgeConfigMap(metricsAndLogging);
podAnnotations.put(KafkaBridgeCluster.ANNO_STRIMZI_IO_CONFIGURATION_HASH, Util.hashStub(configMap.getData().get(KafkaBridgeCluster.BRIDGE_CONFIGURATION_FILENAME)));
return configMapOperations.reconcile(reconciliation, namespace, KafkaBridgeResources.metricsAndLogConfigMapName(reconciliation.name()), configMap);
return configMapOperations.reconcile(reconciliation, namespace, KafkaBridgeResources.configMapName(reconciliation.name()), configMap);
})
.compose(i -> isPodDisruptionBudgetGeneration ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, bridge.getComponentName(), bridge.generatePodDisruptionBudget()) : Future.succeededFuture())
.compose(i -> VertxUtil.authTlsHash(secretOperations, namespace, auth, trustedCertificates))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void testCustomAndUpdatedValues() {
updatedPeriodSeconds, successThreshold, updatedFailureThreshold);
VerificationUtils.verifyContainerEnvVariables(Environment.TEST_SUITE_NAMESPACE, KafkaBridgeResources.componentName(bridgeName), KafkaBridgeResources.componentName(bridgeName), envVarUpdated);

ConfigMap configMap = kubeClient().namespace(Environment.TEST_SUITE_NAMESPACE).getConfigMap(KafkaBridgeResources.metricsAndLogConfigMapName(bridgeName));
ConfigMap configMap = kubeClient().namespace(Environment.TEST_SUITE_NAMESPACE).getConfigMap(KafkaBridgeResources.configMapName(bridgeName));
String bridgeConfiguration = configMap.getData().get("application.properties");
Map<String, Object> config = StUtils.loadProperties(bridgeConfiguration);
Map<String, Object> producerConfigMap = config.entrySet().stream().filter(e -> e.getKey().startsWith("kafka.producer.")).collect(Collectors.toMap(e -> e.getKey().replace("kafka.producer.", ""), Map.Entry::getValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void testBridgeLogSetting() {

final String bridgeDepName = KafkaBridgeResources.componentName(testStorage.getClusterName());
final Map<String, String> bridgePods = DeploymentUtils.depSnapshot(Environment.TEST_SUITE_NAMESPACE, bridgeDepName);
final String bridgeMap = KafkaBridgeResources.metricsAndLogConfigMapName(testStorage.getClusterName());
final String bridgeMap = KafkaBridgeResources.configMapName(testStorage.getClusterName());
final LabelSelector labelSelector = KafkaBridgeResource.getLabelSelector(bridgeDepName, KafkaMirrorMaker2Resources.componentName(bridgeDepName));

LOGGER.info("Checking if Bridge has log level set properly");
Expand Down

0 comments on commit 515daa4

Please sign in to comment.