Search in sources :

Example 1 with ObjectFieldSelector

use of io.fabric8.kubernetes.api.model.ObjectFieldSelector 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;
}
Also used : ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) ArrayList(java.util.ArrayList) EnvVarValueModel(org.ballerinax.kubernetes.models.knative.EnvVarValueModel) ObjectFieldSelectorBuilder(io.fabric8.kubernetes.api.model.ObjectFieldSelectorBuilder) ResourceFieldSelectorBuilder(io.fabric8.kubernetes.api.model.ResourceFieldSelectorBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) SecretKeySelector(io.fabric8.kubernetes.api.model.SecretKeySelector) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ResourceFieldSelector(io.fabric8.kubernetes.api.model.ResourceFieldSelector) SecretKeySelectorBuilder(io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector)

Example 2 with ObjectFieldSelector

use of io.fabric8.kubernetes.api.model.ObjectFieldSelector 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;
}
Also used : ConfigMapKeySelectorBuilder(io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder) ArrayList(java.util.ArrayList) EnvVarValueModel(org.ballerinax.kubernetes.models.EnvVarValueModel) ObjectFieldSelectorBuilder(io.fabric8.kubernetes.api.model.ObjectFieldSelectorBuilder) ResourceFieldSelectorBuilder(io.fabric8.kubernetes.api.model.ResourceFieldSelectorBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) SecretKeySelector(io.fabric8.kubernetes.api.model.SecretKeySelector) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ResourceFieldSelector(io.fabric8.kubernetes.api.model.ResourceFieldSelector) SecretKeySelectorBuilder(io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) ConfigMapKeySelector(io.fabric8.kubernetes.api.model.ConfigMapKeySelector)

Aggregations

ConfigMapKeySelector (io.fabric8.kubernetes.api.model.ConfigMapKeySelector)2 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)2 EnvVarSource (io.fabric8.kubernetes.api.model.EnvVarSource)2 EnvVarSourceBuilder (io.fabric8.kubernetes.api.model.EnvVarSourceBuilder)2 ObjectFieldSelector (io.fabric8.kubernetes.api.model.ObjectFieldSelector)2 ObjectFieldSelectorBuilder (io.fabric8.kubernetes.api.model.ObjectFieldSelectorBuilder)2 ResourceFieldSelector (io.fabric8.kubernetes.api.model.ResourceFieldSelector)2 ResourceFieldSelectorBuilder (io.fabric8.kubernetes.api.model.ResourceFieldSelectorBuilder)2 SecretKeySelector (io.fabric8.kubernetes.api.model.SecretKeySelector)2 SecretKeySelectorBuilder (io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder)2 ArrayList (java.util.ArrayList)2 EnvVarValueModel (org.ballerinax.kubernetes.models.EnvVarValueModel)1 EnvVarValueModel (org.ballerinax.kubernetes.models.knative.EnvVarValueModel)1