Skip to content

Commit 0b46b46

Browse files
authored
Decorate Fluentd ConfigMap with domainUID (#3879)
1 parent 34103ba commit 0b46b46

File tree

7 files changed

+42
-24
lines changed

7 files changed

+42
-24
lines changed

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

Lines changed: 9 additions & 5 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;
@@ -62,8 +62,9 @@
6262
import static oracle.kubernetes.operator.ProcessingConstants.DOMAIN_VALIDATION_ERRORS;
6363
import static oracle.kubernetes.operator.helpers.KubernetesUtils.getDomainUidLabel;
6464
import static oracle.kubernetes.operator.helpers.NamespaceHelper.getOperatorNamespace;
65-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
65+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
6666
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
67+
import static oracle.kubernetes.operator.helpers.StepContextConstants.OLD_FLUENTD_CONFIGMAP_NAME;
6768

6869
public class ConfigMapHelper {
6970

@@ -790,7 +791,9 @@ protected List<String> getIntrospectorOrFluentdConfigMapNames(V1ConfigMapList li
790791

791792
private boolean isIntrospectorOrFluentdConfigMapName(String name) {
792793
return name.startsWith(IntrospectorConfigMapConstants.getIntrospectorConfigMapNamePrefix(domainUid))
793-
|| FLUENTD_CONFIGMAP_NAME.equals(name);
794+
|| (domainUid + FLUENTD_CONFIGMAP_NAME_SUFFIX).equals(name)
795+
// Match old, undecorated name of config map to clean-up
796+
|| OLD_FLUENTD_CONFIGMAP_NAME.equals(name);
794797
}
795798

796799
@Nonnull
@@ -977,7 +980,7 @@ private boolean hasNoFluentdSpecification(Packet packet) {
977980

978981
private Step createNextStep(DomainPresenceInfo info) {
979982
return new CallBuilder().readConfigMapAsync(
980-
FLUENTD_CONFIGMAP_NAME,
983+
info.getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX,
981984
info.getNamespace(),
982985
info.getDomainUid(),
983986
new ReadFluentdConfigMapResponseStep(getNext()));
@@ -1046,7 +1049,8 @@ private static Step createFluentdConfigMap(DomainPresenceInfo info, Step next) {
10461049

10471050
private static Step replaceFluentdConfigMap(DomainPresenceInfo info, Step next) {
10481051
return new CallBuilder()
1049-
.replaceConfigMapAsync(FLUENTD_CONFIGMAP_NAME,
1052+
.replaceConfigMapAsync(
1053+
info.getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX,
10501054
info.getNamespace(),
10511055
FluentdHelper.getFluentdConfigMap(info),
10521056
new ReplaceFluentdConfigMapResponseStep(next));

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;
@@ -21,7 +21,7 @@
2121
import oracle.kubernetes.weblogic.domain.model.DomainResource;
2222
import oracle.kubernetes.weblogic.domain.model.FluentdSpecification;
2323

24-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
24+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
2525
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_VOLUME;
2626
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
2727
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONTAINER_NAME;
@@ -185,7 +185,7 @@ public static V1ConfigMap getFluentdConfigMap(DomainPresenceInfo info) {
185185
data.put(FLUENTD_CONFIG_DATA_NAME, fluentdConfBuilder.toString());
186186

187187
V1ObjectMeta meta = new V1ObjectMeta()
188-
.name(FLUENTD_CONFIGMAP_NAME)
188+
.name(domainUid + FLUENTD_CONFIGMAP_NAME_SUFFIX)
189189
.labels(labels)
190190
.namespace(namespace);
191191

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;
@@ -558,9 +558,11 @@ protected List<V1Container> getContainers() {
558558
protected List<V1Volume> getFluentdVolumes() {
559559
List<V1Volume> volumes = new ArrayList<>();
560560
Optional.ofNullable(getDomain())
561-
.map(DomainResource::getFluentdSpecification)
562-
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
563-
.configMap(new V1ConfigMapVolumeSource().name(FLUENTD_CONFIGMAP_NAME).defaultMode(420))));
561+
.map(DomainResource::getFluentdSpecification)
562+
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
563+
.configMap(new V1ConfigMapVolumeSource()
564+
.name(getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX)
565+
.defaultMode(420))));
564566
return volumes;
565567
}
566568

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,11 @@ protected List<V1Container> getContainers() {
777777
protected List<V1Volume> getFluentdVolumes() {
778778
List<V1Volume> volumes = new ArrayList<>();
779779
Optional.ofNullable(getDomain())
780-
.map(DomainResource::getFluentdSpecification)
781-
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
782-
.configMap(new V1ConfigMapVolumeSource().name(FLUENTD_CONFIGMAP_NAME).defaultMode(420))));
780+
.map(DomainResource::getFluentdSpecification)
781+
.ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME)
782+
.configMap(new V1ConfigMapVolumeSource()
783+
.name(getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX)
784+
.defaultMode(420))));
783785
return volumes;
784786
}
785787

@@ -1329,6 +1331,14 @@ private void restoreLogHomeLayoutEnvVar(V1Pod recipe, V1Pod currentPod) {
13291331
}));
13301332
}
13311333

1334+
private void restoreFluentdVolume(V1Pod recipe, V1Pod currentPod) {
1335+
Optional.ofNullable(recipe.getSpec().getVolumes())
1336+
.ifPresent(volumes -> volumes.stream().filter(volume -> FLUENTD_CONFIGMAP_VOLUME.equals(volume.getName()))
1337+
.forEach(volume -> {
1338+
Optional.ofNullable(volume.getConfigMap()).ifPresent(cms -> cms.setName(OLD_FLUENTD_CONFIGMAP_NAME));
1339+
}));
1340+
}
1341+
13321342
private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod, String requiredHash) {
13331343
// start with list of adjustment methods
13341344
// generate stream of combinations
@@ -1339,7 +1349,8 @@ private boolean canAdjustRecentOperatorMajorVersion3HashToMatch(V1Pod currentPod
13391349
this::convertAuxImagesInitContainerVolumeAndMounts,
13401350
this::restoreLegacyIstioPortsConfig,
13411351
this::restoreAffinityContent,
1342-
this::restoreLogHomeLayoutEnvVar);
1352+
this::restoreLogHomeLayoutEnvVar,
1353+
this::restoreFluentdVolume);
13431354
return Combinations.of(adjustments)
13441355
.map(adjustment -> adjustedHash(currentPod, adjustment))
13451356
.anyMatch(requiredHash::equals);

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, 2021, 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;
@@ -12,7 +12,8 @@ public interface StepContextConstants {
1212
String INTROSPECTOR_VOLUME = "weblogic-domain-introspect-cm-volume";
1313
String RUNTIME_ENCRYPTION_SECRET_VOLUME = "weblogic-domain-runtime-encryption-volume";
1414
String FLUENTD_CONFIGMAP_VOLUME = "weblogic-fluentd-configmap-volume";
15-
String FLUENTD_CONFIGMAP_NAME = "weblogic-fluentd-configmap";
15+
String OLD_FLUENTD_CONFIGMAP_NAME = "weblogic-fluentd-configmap";
16+
String FLUENTD_CONFIGMAP_NAME_SUFFIX = "-" + OLD_FLUENTD_CONFIGMAP_NAME;
1617
String FLUENTD_CONTAINER_NAME = "fluentd";
1718
String FLUENTD_CONFIG_DATA_NAME = "fluentd.conf";
1819
String SECRETS_MOUNT_PATH = "/weblogic-operator/secrets";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.SERVICE;
149149
import static oracle.kubernetes.operator.helpers.SecretHelper.PASSWORD_KEY;
150150
import static oracle.kubernetes.operator.helpers.SecretHelper.USERNAME_KEY;
151-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
151+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
152152
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
153153
import static oracle.kubernetes.operator.http.client.HttpAsyncTestSupport.OK_RESPONSE;
154154
import static oracle.kubernetes.operator.http.client.HttpAsyncTestSupport.createExpectedRequest;
@@ -1387,7 +1387,7 @@ void whenFluentdSpecified_verifyConfigMap() {
13871387

13881388
processor.createMakeRightOperation(newInfo).execute();
13891389

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

13921392
assertThat(Optional.ofNullable(fluentdConfigMap)
13931393
.map(V1ConfigMap::getData)
@@ -1405,7 +1405,7 @@ void whenFluentdSpecifiedWithConfig_verifyConfigMap() {
14051405

14061406
processor.createMakeRightOperation(newInfo).execute();
14071407

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

14101410
assertThat(Optional.ofNullable(fluentdConfigMap)
14111411
.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;
@@ -97,7 +97,7 @@
9797
import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createSecretKeyRefEnvVar;
9898
import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createSecurityContext;
9999
import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createToleration;
100-
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME;
100+
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX;
101101
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME;
102102
import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONTAINER_NAME;
103103
import static oracle.kubernetes.operator.tuning.TuningParameters.INTROSPECTOR_JOB_ACTIVE_DEADLINE_SECONDS;
@@ -458,7 +458,7 @@ void whenFluendConfigmapExists_replaceIt() {
458458
Map<String, String> data = new HashMap<>();
459459
data.put(FLUENTD_CONFIG_DATA_NAME, "<fakedata/>");
460460
V1ObjectMeta metaData = new V1ObjectMeta()
461-
.name(FLUENTD_CONFIGMAP_NAME)
461+
.name(UID + FLUENTD_CONFIGMAP_NAME_SUFFIX)
462462
.namespace(domainPresenceInfo.getNamespace());
463463
V1ConfigMap configMap = new V1ConfigMap()
464464
.metadata(metaData)

0 commit comments

Comments
 (0)