EnvVarsConverter implements ConfigurationProvisioner { @Override @Traced public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException { TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId); for (PodData pod : k8sEnv.getPodsData().values()) { for (Container container : pod.getSpec().getContainers()) { String machineName = Names.machineName(pod, container); InternalMachineConfig machineConf = k8sEnv.getMachines().get(machineName); Map<String, EnvVar> envVars = machineConf .getEnv() .entrySet() .stream() .map(e -> new EnvVar(e.getKey(), e.getValue(), null)) .collect(toMap(EnvVar::getName, identity())); container.getEnv().forEach(v -> envVars.putIfAbsent(v.getName(), v)); List<EnvVar> sorted = topoSort.sort(envVars.values()); container.setEnv(sorted); } } }  @Override @Traced void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity);  }
@Test public void shouldProvisionEnvironmentVariablesSorted() throws InfrastructureException { List<EnvVar> preExistingEnvironment = new ArrayList<>(); preExistingEnvironment.add(new EnvVar(PRE_EXISTING_VAR, PRE_EXISTING_VAR_VALUE, null)); testContainer.setEnv(preExistingEnvironment); machine.getEnv().put(PRE_EXISTING_VAR, PRE_EXISTING_VAR_NEW_VALUE); machine.getEnv().put(A_VAR, A_VAL); machine.getEnv().put(B_VAR, B_VAL); machine.getEnv().put(C_VAR, C_VAL); EnvVarsConverter converter = new EnvVarsConverter(); converter.provision(environment, identity); EnvVar expectedA = new EnvVar(A_VAR, A_VAL, null); EnvVar expectedB = new EnvVar(B_VAR, B_VAL, null); EnvVar expectedC = new EnvVar(C_VAR, C_VAL, null); EnvVar expectedPreExisting = new EnvVar(PRE_EXISTING_VAR, PRE_EXISTING_VAR_NEW_VALUE, null); List<EnvVar> expectedOrder = asList(expectedB, expectedC, expectedA, expectedPreExisting); assertEquals(4, testContainer.getEnv().size()); assertEquals(expectedOrder, testContainer.getEnv()); }