diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java index b421479a9ed..ef0e58a02b3 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java @@ -65,8 +65,9 @@ import static oracle.kubernetes.operator.ProcessingConstants.DOMAIN_VALIDATION_ERRORS; import static oracle.kubernetes.operator.helpers.KubernetesUtils.getDomainUidLabel; import static oracle.kubernetes.operator.helpers.NamespaceHelper.getOperatorNamespace; -import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME; +import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME; +import static oracle.kubernetes.operator.helpers.StepContextConstants.OLD_FLUENTD_CONFIGMAP_NAME; public class ConfigMapHelper { @@ -796,7 +797,9 @@ protected List getIntrospectorOrFluentdConfigMapNames(V1ConfigMapList li private boolean isIntrospectorOrFluentdConfigMapName(String name) { return name.startsWith(IntrospectorConfigMapConstants.getIntrospectorConfigMapNamePrefix(domainUid)) - || FLUENTD_CONFIGMAP_NAME.equals(name); + || (domainUid + FLUENTD_CONFIGMAP_NAME_SUFFIX).equals(name) + // Match old, undecorated name of config map to clean-up + || OLD_FLUENTD_CONFIGMAP_NAME.equals(name); } @Nonnull @@ -946,8 +949,10 @@ public static Step readIntrospectionVersionStep(String ns, String domainUid) { public static Step createOrReplaceFluentdConfigMapStep(DomainPresenceInfo info, Step next) { FluentdSpecification fluentdSpecification = info.getDomain().getFluentdSpecification(); if (fluentdSpecification != null) { - return new CallBuilder().readConfigMapAsync(FLUENTD_CONFIGMAP_NAME, info.getNamespace(), - info.getDomainUid(), new ReadFluentdConfigMapResponseStep(info, next)); + return new CallBuilder().readConfigMapAsync( + info.getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX, + info.getNamespace(), + info.getDomainUid(), new ReadFluentdConfigMapResponseStep(info, next)); } else { return next; } @@ -1021,9 +1026,11 @@ private static Step replaceFluentdConfigMap(DomainPresenceInfo info, Step next) FluentdSpecification fluentdSpecification = info.getDomain().getFluentdSpecification(); if (fluentdSpecification != null) { return new CallBuilder() - .replaceConfigMapAsync(FLUENTD_CONFIGMAP_NAME, info.getNamespace(), - FluentdHelper.getFluentdConfigMap(info), - new ReplaceFluentdConfigMapResponseStep(next)); + .replaceConfigMapAsync( + info.getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX, + info.getNamespace(), + FluentdHelper.getFluentdConfigMap(info), + new ReplaceFluentdConfigMapResponseStep(next)); } else { return next; } diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/FluentdHelper.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/FluentdHelper.java index 06bfc1f0216..bcac7684a59 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/FluentdHelper.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/FluentdHelper.java @@ -1,4 +1,4 @@ -// Copyright (c) 2018, 2022, Oracle and/or its affiliates. +// Copyright (c) 2018, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.kubernetes.operator.helpers; @@ -20,7 +20,7 @@ import oracle.kubernetes.weblogic.domain.model.Domain; import oracle.kubernetes.weblogic.domain.model.FluentdSpecification; -import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME; +import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_VOLUME; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONTAINER_NAME; @@ -173,7 +173,7 @@ public static V1ConfigMap getFluentdConfigMap(DomainPresenceInfo info) { data.put(FLUENTD_CONFIG_DATA_NAME, fluentdConfBuilder.toString()); V1ObjectMeta meta = new V1ObjectMeta() - .name(FLUENTD_CONFIGMAP_NAME) + .name(domainUid + FLUENTD_CONFIGMAP_NAME_SUFFIX) .labels(labels) .namespace(namespace); diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/JobStepContext.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/JobStepContext.java index b130220c799..b454699592a 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/JobStepContext.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/JobStepContext.java @@ -1,4 +1,4 @@ -// Copyright (c) 2018, 2022, Oracle and/or its affiliates. +// Copyright (c) 2018, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.kubernetes.operator.helpers; @@ -645,9 +645,11 @@ protected List getContainers() { protected List getFluentdVolumes() { List volumes = new ArrayList<>(); Optional.ofNullable(getDomain()) - .map(Domain::getFluentdSpecification) - .ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME) - .configMap(new V1ConfigMapVolumeSource().name(FLUENTD_CONFIGMAP_NAME).defaultMode(420)))); + .map(Domain::getFluentdSpecification) + .ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME) + .configMap(new V1ConfigMapVolumeSource() + .name(getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX) + .defaultMode(420)))); return volumes; } diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java index e36faee7eb0..3e9d09cc00a 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java @@ -1,4 +1,4 @@ -// Copyright (c) 2017, 2022, Oracle and/or its affiliates. +// Copyright (c) 2017, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.kubernetes.operator.helpers; @@ -613,7 +613,8 @@ private boolean isLegacyPod(V1Pod currentPod) { private boolean canAdjustHashToMatch(V1Pod currentPod, String requiredHash) { return requiredHash.equals(adjustedHash(currentPod, this::addLegacyPrometheusAnnotationsFrom_3_0)) - || requiredHash.equals(adjustedHash(currentPod, this::addLegacyPrometheusAnnotationsFrom_3_1)); + || requiredHash.equals(adjustedHash(currentPod, this::addLegacyPrometheusAnnotationsFrom_3_1)) + || requiredHash.equals(adjustedHash(currentPod, this::restoreFluentdVolume)); } private boolean hasLabel(V1Pod pod, String key) { @@ -639,6 +640,14 @@ private void addLegacyPrometheusAnnotationsFrom_3_1(V1Pod pod) { AnnotationHelper.annotateForPrometheus(pod.getMetadata(), "/wls-exporter", getMetricsPort()); } + private void restoreFluentdVolume(V1Pod recipe) { + Optional.ofNullable(recipe.getSpec().getVolumes()) + .ifPresent(volumes -> volumes.stream().filter(volume -> FLUENTD_CONFIGMAP_VOLUME.equals(volume.getName())) + .forEach(volume -> { + Optional.ofNullable(volume.getConfigMap()).ifPresent(cms -> cms.setName(OLD_FLUENTD_CONFIGMAP_NAME)); + })); + } + private Integer getMetricsPort() { return getListenPort() != null ? getListenPort() : getSslListenPort(); } @@ -948,9 +957,11 @@ protected List getContainers() { protected List getFluentdVolumes() { List volumes = new ArrayList<>(); Optional.ofNullable(getDomain()) - .map(Domain::getFluentdSpecification) - .ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME) - .configMap(new V1ConfigMapVolumeSource().name(FLUENTD_CONFIGMAP_NAME).defaultMode(420)))); + .map(Domain::getFluentdSpecification) + .ifPresent(c -> volumes.add(new V1Volume().name(FLUENTD_CONFIGMAP_VOLUME) + .configMap(new V1ConfigMapVolumeSource() + .name(getDomainUid() + FLUENTD_CONFIGMAP_NAME_SUFFIX) + .defaultMode(420)))); return volumes; } diff --git a/operator/src/main/java/oracle/kubernetes/operator/helpers/StepContextConstants.java b/operator/src/main/java/oracle/kubernetes/operator/helpers/StepContextConstants.java index 11f03364949..ddca496754c 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/helpers/StepContextConstants.java +++ b/operator/src/main/java/oracle/kubernetes/operator/helpers/StepContextConstants.java @@ -1,4 +1,4 @@ -// Copyright (c) 2018, 2022, Oracle and/or its affiliates. +// Copyright (c) 2018, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.kubernetes.operator.helpers; @@ -13,7 +13,8 @@ public interface StepContextConstants { String INTROSPECTOR_VOLUME = "weblogic-domain-introspect-cm-volume"; String RUNTIME_ENCRYPTION_SECRET_VOLUME = "weblogic-domain-runtime-encryption-volume"; String FLUENTD_CONFIGMAP_VOLUME = "weblogic-fluentd-configmap-volume"; - String FLUENTD_CONFIGMAP_NAME = "weblogic-fluentd-configmap"; + String OLD_FLUENTD_CONFIGMAP_NAME = "weblogic-fluentd-configmap"; + String FLUENTD_CONFIGMAP_NAME_SUFFIX = "-" + OLD_FLUENTD_CONFIGMAP_NAME; String FLUENTD_CONTAINER_NAME = "fluentd"; String FLUENTD_CONFIG_DATA_NAME = "fluentd.conf"; String SECRETS_MOUNT_PATH = "/weblogic-operator/secrets"; diff --git a/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java b/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java index f4981191257..65b222efab7 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java +++ b/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2022, Oracle and/or its affiliates. +// Copyright (c) 2019, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.kubernetes.operator; @@ -103,7 +103,7 @@ import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.JOB; import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.POD; import static oracle.kubernetes.operator.helpers.KubernetesTestSupport.SERVICE; -import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME; +import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME; import static oracle.kubernetes.operator.logging.MessageKeys.INTROSPECTOR_FLUENTD_CONTAINER_TERMINATED; import static oracle.kubernetes.operator.logging.MessageKeys.NOT_STARTING_DOMAINUID_THREAD; @@ -858,7 +858,7 @@ void whenFluentdSpecified_verifyConfigMap() { processor.createMakeRightOperation(new DomainPresenceInfo(newDomain)).execute(); Domain updatedDomain = testSupport.getResourceWithName(DOMAIN, UID); - V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, FLUENTD_CONFIGMAP_NAME); + V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, UID + FLUENTD_CONFIGMAP_NAME_SUFFIX); assertThat(Optional.ofNullable(fluentdConfigMap) .map(V1ConfigMap::getData) @@ -875,7 +875,7 @@ void whenFluentdSpecifiedWithConfig_verifyConfigMap() { processor.createMakeRightOperation(new DomainPresenceInfo(newDomain)).execute(); - V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, FLUENTD_CONFIGMAP_NAME); + V1ConfigMap fluentdConfigMap = testSupport.getResourceWithName(CONFIG_MAP, UID + FLUENTD_CONFIGMAP_NAME_SUFFIX); assertThat(Optional.ofNullable(fluentdConfigMap) .map(V1ConfigMap::getData) diff --git a/operator/src/test/java/oracle/kubernetes/operator/helpers/JobHelperTest.java b/operator/src/test/java/oracle/kubernetes/operator/helpers/JobHelperTest.java index ec43091c10a..71f31a4f48b 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/helpers/JobHelperTest.java +++ b/operator/src/test/java/oracle/kubernetes/operator/helpers/JobHelperTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2022, Oracle and/or its affiliates. +// Copyright (c) 2019, 2023, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package oracle.kubernetes.operator.helpers; @@ -84,7 +84,7 @@ import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createSecretKeyRefEnvVar; import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createSecurityContext; import static oracle.kubernetes.operator.helpers.PodHelperTestBase.createToleration; -import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME; +import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIGMAP_NAME_SUFFIX; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONFIG_DATA_NAME; import static oracle.kubernetes.operator.helpers.StepContextConstants.FLUENTD_CONTAINER_NAME; import static oracle.kubernetes.operator.logging.MessageKeys.FLUENTD_CONFIGMAP_CREATED; @@ -434,7 +434,7 @@ void whenFluendConfigmapExists_replaceIt() { Map data = new HashMap<>(); data.put(FLUENTD_CONFIG_DATA_NAME, ""); V1ObjectMeta metaData = new V1ObjectMeta() - .name(FLUENTD_CONFIGMAP_NAME) + .name(UID + FLUENTD_CONFIGMAP_NAME_SUFFIX) .namespace(domainPresenceInfo.getNamespace()); V1ConfigMap configMap = new V1ConfigMap() .metadata(metaData)