|
| 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 | +} |
0 commit comments