use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.
the class ImageEnricher method mergeEnvVariables.
private void mergeEnvVariables(Container container) {
List<EnvVar> env = container.getEnv();
if (env == null) {
env = new LinkedList<>();
container.setEnv(env);
}
ResourceConfig resource = getContext().getResources();
Map<String, String> userEnv = resource != null ? resource.getEnv() : null;
if (userEnv != null) {
for (Map.Entry<String, String> entry : userEnv.entrySet()) {
EnvVar existingVariable = KubernetesResourceUtil.setEnvVarNoOverride(env, entry.getKey(), entry.getValue());
if (existingVariable != null) {
String actualValue = existingVariable.getValue();
if (actualValue == null) {
actualValue = "retrieved using the downward API";
}
log.warn("Environment variable %s will not be overridden: trying to set the value %s, but its actual value will be %s", entry.getKey(), entry.getValue(), actualValue);
}
}
}
}
use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.
the class MergeResourceTest method envVarToMap.
private Map<String, String> envVarToMap(List<EnvVar> envVars) {
Map<String, String> answer = new HashMap<>();
if (envVars != null) {
for (EnvVar envVar : envVars) {
String value = envVar.getValue();
if (value != null && !value.isEmpty()) {
String name = envVar.getName();
answer.put(name, value);
}
}
}
return answer;
}
use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.
the class DebugEnricher method enableDebugging.
private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) {
if (template != null) {
PodSpec podSpec = template.getSpec();
if (podSpec != null) {
List<Container> containers = podSpec.getContainers();
if (containers.size() > 0) {
Container container = containers.get(0);
List<EnvVar> env = container.getEnv();
if (env == null) {
env = new ArrayList<>();
}
String remoteDebugPort = KubernetesResourceUtil.getEnvVar(env, ENV_VAR_JAVA_DEBUG_PORT, ENV_VAR_JAVA_DEBUG_PORT_DEFAULT);
boolean enabled = false;
if (KubernetesResourceUtil.setEnvVar(env, ENV_VAR_JAVA_DEBUG, "true")) {
container.setEnv(env);
enabled = true;
}
List<ContainerPort> ports = container.getPorts();
if (ports == null) {
ports = new ArrayList<>();
}
if (KubernetesResourceUtil.addPort(ports, remoteDebugPort, "debug", log)) {
container.setPorts(ports);
enabled = true;
}
if (enabled) {
log.info("Enabling debug on " + getKind(entity) + " " + KubernetesHelper.getName(entity) + " due to the property: " + ENABLE_DEBUG_MAVEN_PROPERTY);
return true;
}
}
}
}
return false;
}
use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method removeEnvVar.
public static boolean removeEnvVar(List<EnvVar> envVarList, String name) {
boolean removed = false;
for (Iterator<EnvVar> it = envVarList.iterator(); it.hasNext(); ) {
EnvVar envVar = it.next();
String envVarName = envVar.getName();
if (io.fabric8.utils.Objects.equal(name, envVarName)) {
it.remove();
removed = true;
}
}
return removed;
}
use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method setEnvVar.
public static boolean setEnvVar(List<EnvVar> envVarList, String name, String value) {
for (EnvVar envVar : envVarList) {
String envVarName = envVar.getName();
if (io.fabric8.utils.Objects.equal(name, envVarName)) {
String oldValue = envVar.getValue();
if (io.fabric8.utils.Objects.equal(value, oldValue)) {
return false;
} else {
envVar.setValue(value);
return true;
}
}
}
EnvVar env = new EnvVarBuilder().withName(name).withValue(value).build();
envVarList.add(env);
return true;
}
Aggregations