Skip to content

Commit 47b9ea2

Browse files
authored
Merge pull request #687 from oracle/pod_change_detection
Test for changes to numerous Pod settings
2 parents 52e8719 + 9046a78 commit 47b9ea2

File tree

7 files changed

+556
-289
lines changed

7 files changed

+556
-289
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator.helpers;
6+
7+
import io.kubernetes.client.models.V1ObjectMeta;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.Objects;
11+
import org.apache.commons.collections.MapUtils;
12+
13+
class KubernetesUtils {
14+
15+
/**
16+
* Returns true if the two maps of values match. A null map is considered to match an empty map.
17+
*
18+
* @param first the first map to compare
19+
* @param second the second map to compare
20+
* @return true if the maps match.
21+
*/
22+
static <K, V> boolean mapEquals(Map<K, V> first, Map<K, V> second) {
23+
return Objects.equals(first, second) || (MapUtils.isEmpty(first) && MapUtils.isEmpty(second));
24+
}
25+
26+
/**
27+
* Returns true if the labels on the current artifact metadata match those on the build version.
28+
* This excludes any weblogic-specific labels, as identified by the existence of the weblogic.
29+
* prefix.
30+
*
31+
* @param build the desired version of the metadata
32+
* @param current the current version of the metadata
33+
* @return true if the labels match
34+
*/
35+
static boolean areLabelsValid(V1ObjectMeta build, V1ObjectMeta current) {
36+
return mapEquals(getCustomerLabels(current), getCustomerLabels(build));
37+
}
38+
39+
private static Map<String, String> getCustomerLabels(V1ObjectMeta metadata) {
40+
Map<String, String> result = new HashMap<>();
41+
for (Map.Entry<String, String> entry : metadata.getLabels().entrySet())
42+
if (!isOperatorLabel(entry)) result.put(entry.getKey(), entry.getValue());
43+
return result;
44+
}
45+
46+
private static boolean isOperatorLabel(Map.Entry<String, String> label) {
47+
return label.getKey().startsWith("weblogic.");
48+
}
49+
50+
/**
51+
* Returns true if the annotations on the current artifact metadata match those on the build
52+
* version.
53+
*
54+
* @param build the desired version of the metadata
55+
* @param current the current version of the metadata
56+
* @return true if the annotations match
57+
*/
58+
static boolean areAnnotationsValid(V1ObjectMeta build, V1ObjectMeta current) {
59+
return mapEquals(current.getAnnotations(), build.getAnnotations());
60+
}
61+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator.helpers;
6+
7+
import static oracle.kubernetes.operator.KubernetesConstants.DOMAIN_CONFIG_MAP_NAME;
8+
import static oracle.kubernetes.operator.KubernetesConstants.DOMAIN_DEBUG_CONFIG_MAP_SUFFIX;
9+
import static oracle.kubernetes.operator.KubernetesConstants.INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX;
10+
import static oracle.kubernetes.operator.helpers.StepContextConstants.ALL_READ_AND_EXECUTE;
11+
import static oracle.kubernetes.operator.helpers.StepContextConstants.DEBUG_CM_MOUNTS_PATH;
12+
import static oracle.kubernetes.operator.helpers.StepContextConstants.DEBUG_CM_VOLUME;
13+
import static oracle.kubernetes.operator.helpers.StepContextConstants.SCRIPTS_MOUNTS_PATH;
14+
import static oracle.kubernetes.operator.helpers.StepContextConstants.SCRIPTS_VOLUME;
15+
import static oracle.kubernetes.operator.helpers.StepContextConstants.SIT_CONFIG_MAP_VOLUME_SUFFIX;
16+
17+
import io.kubernetes.client.models.V1ConfigMapVolumeSource;
18+
import io.kubernetes.client.models.V1Volume;
19+
import io.kubernetes.client.models.V1VolumeMount;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
class PodDefaults {
24+
static final String K8S_SERVICE_ACCOUNT_MOUNT_PATH =
25+
"/var/run/secrets/kubernetes.io/serviceaccount";
26+
27+
static List<V1Volume> getStandardVolumes(String domainUID) {
28+
List<V1Volume> volumes = new ArrayList<>();
29+
volumes.add(createScriptsVolume());
30+
volumes.add(createDebugCMVolume(domainUID));
31+
volumes.add(createSitConfigVolume(domainUID));
32+
return volumes;
33+
}
34+
35+
private static V1Volume createScriptsVolume() {
36+
return createVolume(SCRIPTS_VOLUME, DOMAIN_CONFIG_MAP_NAME);
37+
}
38+
39+
private static V1Volume createVolume(String volumeName, String configMapName) {
40+
return new V1Volume()
41+
.name(volumeName)
42+
.configMap(
43+
new V1ConfigMapVolumeSource().name(configMapName).defaultMode(ALL_READ_AND_EXECUTE));
44+
}
45+
46+
private static V1Volume createDebugCMVolume(String domainUID) {
47+
V1Volume volume = createVolume(DEBUG_CM_VOLUME, domainUID + DOMAIN_DEBUG_CONFIG_MAP_SUFFIX);
48+
volume.getConfigMap().setOptional(true);
49+
return volume;
50+
}
51+
52+
private static V1Volume createSitConfigVolume(String domainUID) {
53+
return createVolume(getSitConfigMapVolumeName(domainUID), getConfigMapName(domainUID));
54+
}
55+
56+
private static String getSitConfigMapVolumeName(String domainUID) {
57+
return domainUID + SIT_CONFIG_MAP_VOLUME_SUFFIX;
58+
}
59+
60+
private static String getConfigMapName(String domainUID) {
61+
return domainUID + INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX;
62+
}
63+
64+
static List<V1VolumeMount> getStandardVolumeMounts(String domainUID) {
65+
List<V1VolumeMount> mounts = new ArrayList<>();
66+
mounts.add(createScriptsVolumeMount());
67+
mounts.add(createDebugCMVolumeMount());
68+
mounts.add(createSitConfigVolumeMount(domainUID));
69+
return mounts;
70+
}
71+
72+
private static V1VolumeMount createScriptsVolumeMount() {
73+
return readOnlyVolumeMount(SCRIPTS_VOLUME, SCRIPTS_MOUNTS_PATH);
74+
}
75+
76+
private static V1VolumeMount createDebugCMVolumeMount() {
77+
return readOnlyVolumeMount(DEBUG_CM_VOLUME, DEBUG_CM_MOUNTS_PATH);
78+
}
79+
80+
private static V1VolumeMount createSitConfigVolumeMount(String domainUID) {
81+
return volumeMount(getSitConfigMapVolumeName(domainUID), "/weblogic-operator/introspector");
82+
}
83+
84+
private static V1VolumeMount readOnlyVolumeMount(String volumeName, String mountPath) {
85+
return volumeMount(volumeName, mountPath).readOnly(true);
86+
}
87+
88+
private static V1VolumeMount volumeMount(String volumeName, String mountPath) {
89+
return new V1VolumeMount().name(volumeName).mountPath(mountPath);
90+
}
91+
}

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

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,11 @@
44

55
package oracle.kubernetes.operator.helpers;
66

7-
import io.kubernetes.client.models.V1DeleteOptions;
8-
import io.kubernetes.client.models.V1EnvVar;
9-
import io.kubernetes.client.models.V1ObjectMeta;
10-
import io.kubernetes.client.models.V1Pod;
11-
import io.kubernetes.client.models.V1PodSpec;
12-
import io.kubernetes.client.models.V1Volume;
13-
import io.kubernetes.client.models.V1VolumeMount;
7+
import io.kubernetes.client.models.*;
148
import java.util.ArrayList;
159
import java.util.List;
1610
import java.util.Map;
17-
import oracle.kubernetes.operator.DomainStatusUpdater;
18-
import oracle.kubernetes.operator.LabelConstants;
19-
import oracle.kubernetes.operator.PodAwaiterStepFactory;
20-
import oracle.kubernetes.operator.ProcessingConstants;
21-
import oracle.kubernetes.operator.TuningParameters;
11+
import oracle.kubernetes.operator.*;
2212
import oracle.kubernetes.operator.logging.MessageKeys;
2313
import oracle.kubernetes.operator.steps.DefaultResponseStep;
2414
import oracle.kubernetes.operator.wlsconfig.WlsServerConfig;
@@ -28,7 +18,6 @@
2818
import oracle.kubernetes.operator.work.Step;
2919
import oracle.kubernetes.weblogic.domain.v2.ServerSpec;
3020

31-
@SuppressWarnings("deprecation")
3221
public class PodHelper {
3322

3423
private PodHelper() {}
@@ -97,16 +86,6 @@ List<V1EnvVar> getEnvironmentVariables(TuningParameters tuningParameters) {
9786
return vars;
9887
}
9988

100-
@Override
101-
protected List<V1Volume> getAdditionalVolumes() {
102-
return getServerSpec().getAdditionalVolumes();
103-
}
104-
105-
@Override
106-
protected List<V1VolumeMount> getAdditionalVolumeMounts() {
107-
return getServerSpec().getAdditionalVolumeMounts();
108-
}
109-
11089
@Override
11190
protected Map<String, String> getPodLabels() {
11291
return getServerSpec().getPodLabels();
@@ -265,8 +244,7 @@ private String getClusterName() {
265244

266245
@Override
267246
protected List<String> getContainerCommand() {
268-
List<String> command = new ArrayList<>(super.getContainerCommand());
269-
return command;
247+
return new ArrayList<>(super.getContainerCommand());
270248
}
271249

272250
@Override
@@ -282,16 +260,6 @@ List<V1EnvVar> getEnvironmentVariables(TuningParameters tuningParameters) {
282260
doSubstitution(vars);
283261
return vars;
284262
}
285-
286-
@Override
287-
protected List<V1Volume> getAdditionalVolumes() {
288-
return getServerSpec().getAdditionalVolumes();
289-
}
290-
291-
@Override
292-
protected List<V1VolumeMount> getAdditionalVolumeMounts() {
293-
return getServerSpec().getAdditionalVolumeMounts();
294-
}
295263
}
296264

297265
static class ManagedPodStep extends Step {

0 commit comments

Comments
 (0)