Skip to content

Decorate Fluentd ConfigMap with domainUID #3883

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

Merged
merged 1 commit into from
Jan 24, 2023
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 @@ -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 {

Expand Down Expand Up @@ -796,7 +797,9 @@ protected List<String> 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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -645,9 +645,11 @@ protected List<V1Container> getContainers() {
protected List<V1Volume> getFluentdVolumes() {
List<V1Volume> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -948,9 +957,11 @@ protected List<V1Container> getContainers() {
protected List<V1Volume> getFluentdVolumes() {
List<V1Volume> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -434,7 +434,7 @@ void whenFluendConfigmapExists_replaceIt() {
Map<String, String> data = new HashMap<>();
data.put(FLUENTD_CONFIG_DATA_NAME, "<fakedata/>");
V1ObjectMeta metaData = new V1ObjectMeta()
.name(FLUENTD_CONFIGMAP_NAME)
.name(UID + FLUENTD_CONFIGMAP_NAME_SUFFIX)
.namespace(domainPresenceInfo.getNamespace());
V1ConfigMap configMap = new V1ConfigMap()
.metadata(metaData)
Expand Down