Java Code Examples for io.fabric8.kubernetes.api.model.EnvVar#setValue()

The following examples show how to use io.fabric8.kubernetes.api.model.EnvVar#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesHelper.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean setEnvVar(List<EnvVar> envVarList, String name, String value) {
    for (EnvVar envVar : envVarList) {
        String envVarName = envVar.getName();
        if (Objects.equals(name, envVarName)) {
            String oldValue = envVar.getValue();
            if (Objects.equals(value, oldValue)) {
                return false;
            } else {
                envVar.setValue(value);
                return true;
            }
        }
    }
    EnvVar env = new EnvVarBuilder().withName(name).withValue(value).build();
    envVarList.add(env);
    return true;
}
 
Example 2
Source File: EnvVars.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void apply(List<EnvVar> targetEnv, Env env) {
  Optional<EnvVar> existingOpt =
      targetEnv.stream().filter(e -> e.getName().equals(env.getName())).findAny();
  if (existingOpt.isPresent()) {
    EnvVar envVar = existingOpt.get();
    envVar.setValue(env.getValue());
    envVar.setValueFrom(null);
  } else {
    targetEnv.add(new EnvVar(env.getName(), env.getValue(), null));
  }
}
 
Example 3
Source File: KubernetesResource.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
private static DeploymentBuilder defaultCLusterOperator(String namespace, long operationTimeout, long reconciliationInterval) {

        Deployment clusterOperator = getDeploymentFromYaml(PATH_TO_CO_CONFIG);

        // Get env from config file
        List<EnvVar> envVars = clusterOperator.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
        // Get default CO image
        String coImage = clusterOperator.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();

        // Update images
        for (EnvVar envVar : envVars) {
            switch (envVar.getName()) {
                case "STRIMZI_LOG_LEVEL":
                    envVar.setValue(Environment.STRIMZI_LOG_LEVEL);
                    break;
                case "STRIMZI_NAMESPACE":
                    envVar.setValue(namespace);
                    envVar.setValueFrom(null);
                    break;
                case "STRIMZI_FULL_RECONCILIATION_INTERVAL_MS":
                    envVar.setValue(Long.toString(reconciliationInterval));
                    break;
                case "STRIMZI_OPERATION_TIMEOUT_MS":
                    envVar.setValue(Long.toString(operationTimeout));
                    break;
                default:
                    if (envVar.getName().contains("KAFKA_BRIDGE_IMAGE")) {
                        envVar.setValue(Environment.useLatestReleasedBridge() ? envVar.getValue() : Environment.BRIDGE_IMAGE);
                    } else if (envVar.getName().contains("STRIMZI_DEFAULT")) {
                        envVar.setValue(StUtils.changeOrgAndTag(envVar.getValue()));
                    } else if (envVar.getName().contains("IMAGES")) {
                        envVar.setValue(StUtils.changeOrgAndTagInImageMap(envVar.getValue()));
                    }
            }
        }

        envVars.add(new EnvVar("STRIMZI_IMAGE_PULL_POLICY", Environment.COMPONENTS_IMAGE_PULL_POLICY, null));
        // Apply updated env variables
        clusterOperator.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars);

        return new DeploymentBuilder(clusterOperator)
            .editSpec()
                .withNewSelector()
                    .addToMatchLabels("name", Constants.STRIMZI_DEPLOYMENT_NAME)
                .endSelector()
                .editTemplate()
                    .editSpec()
                        .editFirstContainer()
                            .withImage(StUtils.changeOrgAndTag(coImage))
                            .withImagePullPolicy(Environment.OPERATOR_IMAGE_PULL_POLICY)
                        .endContainer()
                    .endSpec()
                .endTemplate()
            .endSpec();
    }
 
Example 4
Source File: KubernetesIaasUtil.java    From attic-stratos with Apache License 2.0 3 votes vote down vote up
/**
 * Add name value pair to kubernetes environment variables.
 *
 * @param environmentVariables
 * @param name
 * @param value
 */
private static void addToEnvironmentVariables(List<EnvVar> environmentVariables, String name, String value) {
    EnvVar environmentVariable = new EnvVar();
    environmentVariable.setName(name);
    environmentVariable.setValue(value);
    environmentVariables.add(environmentVariable);
}