ProxySettingsProvisioner implements ConfigurationProvisioner { @Override @Traced public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException { TracingTags.WORKSPACE_ID.set(identity::getWorkspaceId); if (!proxyEnvVars.isEmpty()) { k8sEnv .getPodsData() .entrySet() .stream() .filter(entry -> !entry.getKey().equals(JWT_PROXY_POD_NAME)) .flatMap( entry -> Stream.concat( entry.getValue().getSpec().getContainers().stream(), entry.getValue().getSpec().getInitContainers().stream())) .forEach( container -> proxyEnvVars.forEach((k, v) -> container.getEnv().add(new EnvVar(k, v, null)))); } } @Inject  ProxySettingsProvisioner(
      @Named("che.workspace.https_proxy") String httpsProxy,
      @Named("che.workspace.http_proxy") String httpProxy,
      @Named("che.workspace.no_proxy") String noProxy); @Override @Traced void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity);  }
@Test public void shouldApplyProxySettingsToAllContainers() throws Exception { Map<String, Pod> pods = new HashMap<>(); Pod pod1 = pods.put("pod1", buildPod("pod1", buildContainers(2))); pods.put("pod2", buildPod("pod2", buildContainers(3))); KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build(); provisioner.provision(k8sEnv, runtimeId); assertTrue( k8sEnv .getPodsData() .values() .stream() .flatMap(pod -> pod.getSpec().getContainers().stream()) .allMatch( container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) && container .getEnv() .contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) && container .getEnv() .contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null)))); }
@Test public void shouldNotApplyProxySettingsToJWTProxyContainer() throws Exception { Map<String, Pod> pods = new HashMap<>(); pods.put(JWT_PROXY_POD_NAME, buildPod(JWT_PROXY_POD_NAME, buildContainers(2))); KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build(); provisioner.provision(k8sEnv, runtimeId); assertTrue( k8sEnv .getPodsData() .values() .stream() .filter(pod -> pod.getMetadata().getName().equals(JWT_PROXY_POD_NAME)) .flatMap(pod -> pod.getSpec().getContainers().stream()) .noneMatch( container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) || container .getEnv() .contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) || container .getEnv() .contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null)))); }
@Test public void shouldApplyProxySettingsToInitContainers() throws Exception { Map<String, Pod> pods = new HashMap<>(); Pod pod1 = buildPod("pod1", buildContainers(3)); pod1.getSpec().setInitContainers(Arrays.asList(buildContainers(2))); pods.put("pod1", pod1); KubernetesEnvironment k8sEnv = KubernetesEnvironment.builder().setPods(pods).build(); provisioner.provision(k8sEnv, runtimeId); assertTrue( k8sEnv .getPodsData() .values() .stream() .flatMap( pod -> Stream.concat( pod.getSpec().getContainers().stream(), pod.getSpec().getInitContainers().stream())) .allMatch( container -> container.getEnv().contains(new EnvVar(HTTP_PROXY, HTTP_PROXY_VALUE, null)) && container .getEnv() .contains(new EnvVar(HTTPS_PROXY, HTTPS_PROXY_VALUE, null)) && container .getEnv() .contains(new EnvVar(NO_PROXY, NO_PROXY_VALUE, null)))); }