Skip to content
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 @@ -203,7 +203,7 @@ void recordCurrentMap(Packet packet, V1ConfigMap configMap) {

static synchronized Map<String, String> loadScriptsFromClasspath(String domainNamespace) {
Map<String, String> scripts = scriptReader.loadFilesFromClasspath();
LOGGER.fine(MessageKeys.SCRIPT_LOADED, domainNamespace);
LOGGER.finer(MessageKeys.SCRIPT_LOADED, domainNamespace);
return scripts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import io.kubernetes.client.openapi.models.V1DeleteOptions;
import io.kubernetes.client.openapi.models.V1EnvVar;
import io.kubernetes.client.openapi.models.V1EnvVarBuilder;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodCondition;
Expand Down Expand Up @@ -259,17 +260,20 @@ public static Step deletePodStep(String serverName, Step next) {
return new DeletePodStep(serverName, next);
}

static List<V1EnvVar> createCopy(List<V1EnvVar> envVars) {
/**
* Create a copy of the list of V1EnvVar environment variables.
*
* @param envVars list of environment variables to copy
* @return List containing a copy of the original list.
*/
public static List<V1EnvVar> createCopy(List<V1EnvVar> envVars) {
ArrayList<V1EnvVar> copy = new ArrayList<>();
if (envVars != null) {
for (V1EnvVar envVar : envVars) {
// note that a deep copy of valueFrom is not needed here as, unlike with value, the
// new V1EnvVarFrom objects would be created by the doDeepSubstitutions() method in
// StepContextBase class.
copy.add(new V1EnvVar()
.name(envVar.getName())
.value(envVar.getValue())
.valueFrom(envVar.getValueFrom()));
copy.add(new V1EnvVarBuilder(envVar).build());
}
}
return copy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.kubernetes.client.openapi.models.V1SecretVolumeSource;
import io.kubernetes.client.openapi.models.V1Volume;
import io.kubernetes.client.openapi.models.V1VolumeMount;
import io.kubernetes.client.util.Yaml;
import jakarta.json.Json;
import jakarta.json.JsonPatchBuilder;
import oracle.kubernetes.operator.DomainSourceType;
Expand Down Expand Up @@ -545,11 +546,11 @@ private boolean canUseCurrentPod(V1Pod currentPod) {

boolean useCurrent = hasCorrectPodHash(currentPod) && canUseNewDomainZip(currentPod);

if (!useCurrent && AnnotationHelper.getDebugString(currentPod).length() > 0) {
LOGGER.fine(
if (!useCurrent) {
LOGGER.finer(
MessageKeys.POD_DUMP,
AnnotationHelper.getDebugString(currentPod),
AnnotationHelper.getDebugString(getPodModel()));
Yaml.dump(currentPod),
Yaml.dump(getPodModel()));
}

return useCurrent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.kubernetes.client.openapi.models.V1Affinity;
import io.kubernetes.client.openapi.models.V1Capabilities;
import io.kubernetes.client.openapi.models.V1Container;
import io.kubernetes.client.openapi.models.V1ContainerBuilder;
import io.kubernetes.client.openapi.models.V1EnvVar;
import io.kubernetes.client.openapi.models.V1HostPathVolumeSource;
import io.kubernetes.client.openapi.models.V1NodeAffinity;
Expand All @@ -43,6 +44,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;

import static java.util.Collections.emptyList;
import static oracle.kubernetes.operator.helpers.PodHelper.createCopy;

class ServerPod extends KubernetesResource {

Expand Down Expand Up @@ -443,7 +445,7 @@ void fillInFrom(ServerPod serverPod1) {
addIfMissing(var);
}
for (V1Container c : serverPod1.getInitContainers()) {
addInitContainerIfMissing(c);
addInitContainerIfMissing(createWithEnvCopy(c));
}
for (V1Container c : serverPod1.getContainers()) {
addContainerIfMissing(c);
Expand Down Expand Up @@ -492,6 +494,10 @@ private void addAuxiliaryImage(ServerPod serverPod1) {
}
}

private V1Container createWithEnvCopy(V1Container c) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm nervous about this as it will be difficult to remember to keep this in sync if later versions of K8s add more fields to V1Container. Can you use new V1ContainerBuilder(V1Container)? We should probably update the copy of V1EnvVar too.

Copy link
Member Author

@ankedia ankedia Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use V1ContainerBuilder(V1Container) and V1EnvVarBuild(V1EnvVar) in c1cda3c. Please let me know if I missed something. Thanks.

return new V1ContainerBuilder(c).withEnv(createCopy(c.getEnv())).build();
}

private void addIfMissing(V1Volume var) {
if (!hasVolumeName(var.getName())) {
addAdditionalVolume(var);
Expand Down