use of io.fabric8.kubernetes.api.model.ConfigMapKeySelector in project kubernetes by ballerinax.
the class KnativeUtils method populateEnvVar.
/**
* Get a list of environment variables.
*
* @param envMap Map of Environment variables
* @return List of env vars
*/
public static List<EnvVar> populateEnvVar(Map<String, EnvVarValueModel> envMap) {
List<EnvVar> envVars = new ArrayList<>();
if (envMap == null) {
return envVars;
}
envMap.forEach((k, v) -> {
EnvVar envVar = null;
if (v.getValue() != null) {
envVar = new EnvVarBuilder().withName(k).withValue(v.getValue()).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.FieldRef) {
EnvVarValueModel.FieldRef fieldRefModel = (EnvVarValueModel.FieldRef) v.getValueFrom();
ObjectFieldSelector fieldRef = new ObjectFieldSelectorBuilder().withFieldPath(fieldRefModel.getFieldPath()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withFieldRef(fieldRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.SecretKeyRef) {
EnvVarValueModel.SecretKeyRef secretKeyRefModel = (EnvVarValueModel.SecretKeyRef) v.getValueFrom();
SecretKeySelector secretRef = new SecretKeySelectorBuilder().withName(secretKeyRefModel.getName()).withKey(secretKeyRefModel.getKey()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withSecretKeyRef(secretRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.ResourceFieldRef) {
EnvVarValueModel.ResourceFieldRef resourceFieldRefModel = (EnvVarValueModel.ResourceFieldRef) v.getValueFrom();
ResourceFieldSelector resourceFieldRef = new ResourceFieldSelectorBuilder().withContainerName(resourceFieldRefModel.getContainerName()).withResource(resourceFieldRefModel.getResource()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withResourceFieldRef(resourceFieldRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.ConfigMapKeyValue) {
EnvVarValueModel.ConfigMapKeyValue configMapKeyValue = (EnvVarValueModel.ConfigMapKeyValue) v.getValueFrom();
ConfigMapKeySelector configMapKey = new ConfigMapKeySelectorBuilder().withKey(configMapKeyValue.getKey()).withName(configMapKeyValue.getName()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withConfigMapKeyRef(configMapKey).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
}
if (envVar != null) {
envVars.add(envVar);
}
});
return envVars;
}
use of io.fabric8.kubernetes.api.model.ConfigMapKeySelector in project kubernetes by ballerinax.
the class KubernetesUtils method populateEnvVar.
/**
* Get a list of environment variables.
*
* @param envMap Map of Environment variables
* @return List of env vars
*/
public static List<EnvVar> populateEnvVar(Map<String, EnvVarValueModel> envMap) {
List<EnvVar> envVars = new ArrayList<>();
if (envMap == null) {
return envVars;
}
envMap.forEach((k, v) -> {
EnvVar envVar = null;
if (v.getValue() != null) {
envVar = new EnvVarBuilder().withName(k).withValue(v.getValue()).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.FieldRef) {
EnvVarValueModel.FieldRef fieldRefModel = (EnvVarValueModel.FieldRef) v.getValueFrom();
ObjectFieldSelector fieldRef = new ObjectFieldSelectorBuilder().withFieldPath(fieldRefModel.getFieldPath()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withFieldRef(fieldRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.SecretKeyRef) {
EnvVarValueModel.SecretKeyRef secretKeyRefModel = (EnvVarValueModel.SecretKeyRef) v.getValueFrom();
SecretKeySelector secretRef = new SecretKeySelectorBuilder().withName(secretKeyRefModel.getName()).withKey(secretKeyRefModel.getKey()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withSecretKeyRef(secretRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.ResourceFieldRef) {
EnvVarValueModel.ResourceFieldRef resourceFieldRefModel = (EnvVarValueModel.ResourceFieldRef) v.getValueFrom();
ResourceFieldSelector resourceFieldRef = new ResourceFieldSelectorBuilder().withContainerName(resourceFieldRefModel.getContainerName()).withResource(resourceFieldRefModel.getResource()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withResourceFieldRef(resourceFieldRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.ConfigMapKeyValue) {
EnvVarValueModel.ConfigMapKeyValue configMapKeyValue = (EnvVarValueModel.ConfigMapKeyValue) v.getValueFrom();
ConfigMapKeySelector configMapKey = new ConfigMapKeySelectorBuilder().withKey(configMapKeyValue.getKey()).withName(configMapKeyValue.getName()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withConfigMapKeyRef(configMapKey).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
}
if (envVar != null) {
envVars.add(envVar);
}
});
return envVars;
}
Aggregations