Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
envVar helper function to be less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
bergman committed Apr 28, 2017
1 parent 3d8d142 commit 2b2c318
Showing 1 changed file with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.hash.Hashing;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.spotify.styx.ServiceAccountKeyManager;
Expand Down Expand Up @@ -69,6 +68,7 @@
import java.io.IOException;
import java.net.ProtocolException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -250,10 +250,9 @@ static Pod createPod(WorkflowInstance workflowInstance, RunSpec runSpec) {
.withReadOnly(true)
.build())
// TODO: do we need set this env as default value?
.addToEnv(new EnvVarBuilder()
.withName("GOOGLE_APPLICATION_CREDENTIALS")
.withValue(STYX_MANAGED_WORKFLOW_SA_SECRET_MOUNT_PATH + STYX_WORKFLOW_SA_JSON_KEY)
.build());
.addToEnv(
envVar("GOOGLE_APPLICATION_CREDENTIALS",
STYX_MANAGED_WORKFLOW_SA_SECRET_MOUNT_PATH + STYX_WORKFLOW_SA_JSON_KEY));
}

if (runSpec.secret().isPresent()) {
Expand All @@ -276,44 +275,23 @@ static Pod createPod(WorkflowInstance workflowInstance, RunSpec runSpec) {
return spec.endSpec().build();
}

private static EnvVar envVar(String name, String value) {
return new EnvVarBuilder().withName(name).withValue(value).build();
}

private static List<EnvVar> buildEnv(WorkflowInstance workflowInstance,
RunSpec runSpec, String podName) {
// inject environment variables
final List<EnvVar> env = Lists.newArrayList();
env.add(new EnvVarBuilder()
.withName(COMPONENT_ID)
.withValue(workflowInstance.workflowId().componentId())
.build());
// TODO: for backward compatibility, delete later
env.add(new EnvVarBuilder()
.withName(ENDPOINT_ID)
.withValue(workflowInstance.workflowId().id())
.build());
env.add(new EnvVarBuilder()
.withName(WORKFLOW_ID)
.withValue(workflowInstance.workflowId().id())
.build());
env.add(new EnvVarBuilder()
.withName(PARAMETER)
.withValue(workflowInstance.parameter())
.build());
env.add(new EnvVarBuilder()
.withName(EXECUTION_ID)
.withValue(podName)
.build());
env.add(new EnvVarBuilder()
.withName(TERMINATION_LOG)
.withValue("/dev/termination-log")
.build());
env.add(new EnvVarBuilder()
.withName(TRIGGER_ID)
.withValue(runSpec.trigger().map(TriggerUtil::triggerId).orElse(null))
.build());
env.add(new EnvVarBuilder()
.withName(TRIGGER_TYPE)
.withValue(runSpec.trigger().map(TriggerUtil::triggerType).orElse(null))
.build());
return env;
return Arrays.asList(
envVar(COMPONENT_ID, workflowInstance.workflowId().componentId()),
// TODO: for backward compatibility, delete later
envVar(ENDPOINT_ID, workflowInstance.workflowId().id()),
envVar(WORKFLOW_ID, workflowInstance.workflowId().id()),
envVar(PARAMETER, workflowInstance.parameter()),
envVar(EXECUTION_ID, podName),
envVar(TERMINATION_LOG, "/dev/termination-log"),
envVar(TRIGGER_ID, runSpec.trigger().map(TriggerUtil::triggerId).orElse(null)),
envVar(TRIGGER_TYPE, runSpec.trigger().map(TriggerUtil::triggerType).orElse(null))
);
}

@Override
Expand Down

0 comments on commit 2b2c318

Please sign in to comment.