Skip to content

Commit d378525

Browse files
authored
Decorate Fluentd ConfigMap with domainUID (#3883)
1 parent 62f33ef commit d378525

File tree

7 files changed

+49
-28
lines changed

7 files changed

+49
-28
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
import static oracle.kubernetes.operator.ProcessingConstants.DOMAIN_VALIDATION_ERRORS;
6666
import static oracle.kubernetes.operator.helpers.KubernetesUtils.getDomainUidLabel;
6767
import static oracle.kubernetes.operator.helpers.NamespaceHelper.getOperatorNamespace;
68-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
68+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
6969
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
70+
import static oracle.kubernetes.operator.helpers.StepContextConstants.OLD_FLUENTD_CONFIGMAP_NAME;
7071

7172
public class ConfigMapHelper {
7273

@@ -796,7 +797,9 @@ protected List<String> getIntrospectorOrFluentdConfigMapNames(V1ConfigMapList li
796797

797798
private boolean isIntrospectorOrFluentdConfigMapName(String name) {
798799
return name.startsWith(IntrospectorConfigMapConstants.getIntrospectorConfigMapNamePrefix(domainUid))
799-
|| FLUENTD_CONFIGMAP_NAME.equals(name);
800+
|| (domainUid + FLUENTD_CONFIGMAP_NAME_SUFFIX).equals(name)
801+
// Match old, undecorated name of config map to clean-up
802+
|| OLD_FLUENTD_CONFIGMAP_NAME.equals(name);
800803
}
801804

802805
@Nonnull
@@ -946,8 +949,10 @@ public static Step readIntrospectionVersionStep(String ns, String domainUid) {
946949
public static Step createOrReplaceFluentdConfigMapStep(DomainPresenceInfo info, Step next) {
947950
FluentdSpecification fluentdSpecification = info.getDomain().getFluentdSpecification();
948951
if (fluentdSpecification != null) {
949-
return new CallBuilder().readConfigMapAsync(FLUENTD_CONFIGMAP_NAME, info.getNamespace(),
950-
info.getDomainUid(), new ReadFluentdConfigMapResponseStep(info, next));
952+
return new CallBuilder().readConfigMapAsync(
953+
info.getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX,
954+
info.getNamespace(),
955+
info.getDomainUid(), new ReadFluentdConfigMapResponseStep(info, next));
951956
} else {
952957
return next;
953958
}
@@ -1021,9 +1026,11 @@ private static Step replaceFluentdConfigMap(DomainPresenceInfo info, Step next)
10211026
FluentdSpecification fluentdSpecification = info.getDomain().getFluentdSpecification();
10221027
if (fluentdSpecification != null) {
10231028
return new CallBuilder()
1024-
.replaceConfigMapAsync(FLUENTD_CONFIGMAP_NAME, info.getNamespace(),
1025-
FluentdHelper.getFluentdConfigMap(info),
1026-
new ReplaceFluentdConfigMapResponseStep(next));
1029+
.replaceConfigMapAsync(
1030+
info.getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX,
1031+
info.getNamespace(),
1032+
FluentdHelper.getFluentdConfigMap(info),
1033+
new ReplaceFluentdConfigMapResponseStep(next));
10271034
} else {
10281035
return next;
10291036
}

operator/src/main/java/oracle/kubernetes/operator/helpers/FluentdHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.helpers;
@@ -20,7 +20,7 @@
2020
import oracle.kubernetes.weblogic.domain.model.Domain;
2121
import oracle.kubernetes.weblogic.domain.model.FluentdSpecification;
2222

23-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
23+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
2424
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_VOLUME;
2525
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
2626
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONTAINER_NAME;
@@ -173,7 +173,7 @@ public static V1ConfigMap getFluentdConfigMap(DomainPresenceInfo info) {
173173
data.put(FLUENTD_CONFIG_DATA_NAME, fluentdConfBuilder.toString());
174174

175175
V1ObjectMeta meta = new V1ObjectMeta()
176-
.name(FLUENTD_CONFIGMAP_NAME)
176+
.name(domainUid + FLUENTD_CONFIGMAP_NAME_SUFFIX)
177177
.labels(labels)
178178
.namespace(namespace);
179179

operator/src/main/java/oracle/kubernetes/operator/helpers/JobStepContext.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.helpers;
@@ -645,9 +645,11 @@ protected List<V1Container> getContainers() {
645645
protected List<V1Volume> getFluentdVolumes() {
646646
List<V1Volume> volumes = new ArrayList<>();
647647
Optional.ofNullable(getDomain())
648-
.map(Domain::getFluentdSpecification)
649-
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
650-
.configMap(new V1ConfigMapVolumeSource().name(FLUENTD_CONFIGMAP_NAME).defaultMode(420))));
648+
.map(Domain::getFluentdSpecification)
649+
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
650+
.configMap(new V1ConfigMapVolumeSource()
651+
.name(getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX)
652+
.defaultMode(420))));
651653
return volumes;
652654
}
653655

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2017, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.helpers;
@@ -613,7 +613,8 @@ private boolean isLegacyPod(V1Pod currentPod) {
613613

614614
private boolean canAdjustHashToMatch(V1Pod currentPod, String requiredHash) {
615615
return requiredHash.equals(adjustedHash(currentPod, this::addLegacyPrometheusAnnotationsFrom_3_0))
616-
|| requiredHash.equals(adjustedHash(currentPod, this::addLegacyPrometheusAnnotationsFrom_3_1));
616+
|| requiredHash.equals(adjustedHash(currentPod, this::addLegacyPrometheusAnnotationsFrom_3_1))
617+
|| requiredHash.equals(adjustedHash(currentPod, this::restoreFluentdVolume));
617618
}
618619

619620
private boolean hasLabel(V1Pod pod, String key) {
@@ -639,6 +640,14 @@ private void addLegacyPrometheusAnnotationsFrom_3_1(V1Pod pod) {
639640
AnnotationHelper.annotateForPrometheus(pod.getMetadata(), "/wls-exporter", getMetricsPort());
640641
}
641642

643+
private void restoreFluentdVolume(V1Pod recipe) {
644+
Optional.ofNullable(recipe.getSpec().getVolumes())
645+
.ifPresent(volumes -> volumes.stream().filter(volume -> FLUENTD_CONFIGMAP_VOLUME.equals(volume.getName()))
646+
.forEach(volume -> {
647+
Optional.ofNullable(volume.getConfigMap()).ifPresent(cms -> cms.setName(OLD_FLUENTD_CONFIGMAP_NAME));
648+
}));
649+
}
650+
642651
private Integer getMetricsPort() {
643652
return getListenPort() != null ? getListenPort() : getSslListenPort();
644653
}
@@ -948,9 +957,11 @@ protected List<V1Container> getContainers() {
948957
protected List<V1Volume> getFluentdVolumes() {
949958
List<V1Volume> volumes = new ArrayList<>();
950959
Optional.ofNullable(getDomain())
951-
.map(Domain::getFluentdSpecification)
952-
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
953-
.configMap(new V1ConfigMapVolumeSource().name(FLUENTD_CONFIGMAP_NAME).defaultMode(420))));
960+
.map(Domain::getFluentdSpecification)
961+
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
962+
.configMap(new V1ConfigMapVolumeSource()
963+
.name(getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX)
964+
.defaultMode(420))));
954965
return volumes;
955966
}
956967

operator/src/main/java/oracle/kubernetes/operator/helpers/StepContextConstants.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.helpers;
@@ -13,7 +13,8 @@ public interface StepContextConstants {
1313
String INTROSPECTOR_VOLUME = "weblogic-domain-introspect-cm-volume";
1414
String RUNTIME_ENCRYPTION_SECRET_VOLUME = "weblogic-domain-runtime-encryption-volume";
1515
String FLUENTD_CONFIGMAP_VOLUME = "weblogic-fluentd-configmap-volume";
16-
String FLUENTD_CONFIGMAP_NAME = "weblogic-fluentd-configmap";
16+
String OLD_FLUENTD_CONFIGMAP_NAME = "weblogic-fluentd-configmap";
17+
String FLUENTD_CONFIGMAP_NAME_SUFFIX = "-" + OLD_FLUENTD_CONFIGMAP_NAME;
1718
String FLUENTD_CONTAINER_NAME = "fluentd";
1819
String FLUENTD_CONFIG_DATA_NAME = "fluentd.conf";
1920
String SECRETS_MOUNT_PATH = "/weblogic-operator/secrets";

operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator;
@@ -103,7 +103,7 @@
103103
import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.JOB;
104104
import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.POD;
105105
import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.SERVICE;
106-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
106+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
107107
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
108108
import static oracle.kubernetes.operator.logging.MessageKeys.INTROSPECTOR_FLUENTD_CONTAINER_TERMINATED;
109109
import static oracle.kubernetes.operator.logging.MessageKeys.NOT_STARTING_DOMAINUID_THREAD;
@@ -858,7 +858,7 @@ void whenFluentdSpecified_verifyConfigMap() {
858858
processor.createMakeRightOperation(new DomainPresenceInfo(newDomain)).execute();
859859

860860
Domain updatedDomain = testSupport.getResourceWithName(DOMAIN, UID);
861-
V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, FLUENTD_CONFIGMAP_NAME);
861+
V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, UID + FLUENTD_CONFIGMAP_NAME_SUFFIX);
862862

863863
assertThat(Optional.ofNullable(fluentdConfigMap)
864864
.map(V1ConfigMap::getData)
@@ -875,7 +875,7 @@ void whenFluentdSpecifiedWithConfig_verifyConfigMap() {
875875

876876
processor.createMakeRightOperation(new DomainPresenceInfo(newDomain)).execute();
877877

878-
V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, FLUENTD_CONFIGMAP_NAME);
878+
V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, UID + FLUENTD_CONFIGMAP_NAME_SUFFIX);
879879

880880
assertThat(Optional.ofNullable(fluentdConfigMap)
881881
.map(V1ConfigMap::getData)

operator/src/test/java/oracle/kubernetes/operator/helpers/JobHelperTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.helpers;
@@ -84,7 +84,7 @@
8484
import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createSecretKeyRefEnvVar;
8585
import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createSecurityContext;
8686
import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createToleration;
87-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
87+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
8888
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
8989
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONTAINER_NAME;
9090
import static oracle.kubernetes.operator.logging.MessageKeys.FLUENTD_CONFIGMAP_CREATED;
@@ -434,7 +434,7 @@ void whenFluendConfigmapExists_replaceIt() {
434434
Map<String, String> data = new HashMap<>();
435435
data.put(FLUENTD_CONFIG_DATA_NAME, "<fakedata/>");
436436
V1ObjectMeta metaData = new V1ObjectMeta()
437-
.name(FLUENTD_CONFIGMAP_NAME)
437+
.name(UID + FLUENTD_CONFIGMAP_NAME_SUFFIX)
438438
.namespace(domainPresenceInfo.getNamespace());
439439
V1ConfigMap configMap = new V1ConfigMap()
440440
.metadata(metaData)

0 commit comments

Comments
 (0)