diff --git a/infrastructures/kubernetes/pom.xml b/infrastructures/kubernetes/pom.xml
index 095e79f0a0a..32d0c49fb88 100644
--- a/infrastructures/kubernetes/pom.xml
+++ b/infrastructures/kubernetes/pom.xml
@@ -127,6 +127,10 @@
org.eclipse.che.core
che-core-api-system
+
+ org.eclipse.che.core
+ che-core-api-user
+
org.eclipse.che.core
che-core-api-workspace
diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesEnvironmentProvisioner.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesEnvironmentProvisioner.java
index bfe7f4be8e4..df94c6f39b3 100644
--- a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesEnvironmentProvisioner.java
+++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/KubernetesEnvironmentProvisioner.java
@@ -21,6 +21,7 @@
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.CertificateProvisioner;
+import org.eclipse.che.workspace.infrastructure.kubernetes.provision.GitUserProfileProvisioner;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.ImagePullSecretProvisioner;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.IngressTlsProvisioner;
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.InstallerServersPortProvisioner;
@@ -73,6 +74,7 @@ class KubernetesEnvironmentProvisionerImpl
private final ServiceAccountProvisioner serviceAccountProvisioner;
private final CertificateProvisioner certificateProvisioner;
private final VcsSshKeysProvisioner vcsSshKeysProvisioner;
+ private final GitUserProfileProvisioner gitUserProfileProvisioner;
@Inject
public KubernetesEnvironmentProvisionerImpl(
@@ -92,7 +94,8 @@ public KubernetesEnvironmentProvisionerImpl(
ProxySettingsProvisioner proxySettingsProvisioner,
ServiceAccountProvisioner serviceAccountProvisioner,
CertificateProvisioner certificateProvisioner,
- VcsSshKeysProvisioner vcsSshKeysProvisioner) {
+ VcsSshKeysProvisioner vcsSshKeysProvisioner,
+ GitUserProfileProvisioner gitUserProfileProvisioner) {
this.pvcEnabled = pvcEnabled;
this.volumesStrategy = volumesStrategy;
this.uniqueNamesProvisioner = uniqueNamesProvisioner;
@@ -110,6 +113,7 @@ public KubernetesEnvironmentProvisionerImpl(
this.serviceAccountProvisioner = serviceAccountProvisioner;
this.certificateProvisioner = certificateProvisioner;
this.vcsSshKeysProvisioner = vcsSshKeysProvisioner;
+ this.gitUserProfileProvisioner = gitUserProfileProvisioner;
}
@Traced
@@ -149,6 +153,7 @@ public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity)
serviceAccountProvisioner.provision(k8sEnv, identity);
certificateProvisioner.provision(k8sEnv, identity);
vcsSshKeysProvisioner.provision(k8sEnv, identity);
+ gitUserProfileProvisioner.provision(k8sEnv, identity);
LOG.debug("Provisioning Kubernetes environment done for workspace '{}'", workspaceId);
}
}
diff --git a/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/GitUserProfileProvisioner.java b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/GitUserProfileProvisioner.java
new file mode 100644
index 00000000000..90a31d287f6
--- /dev/null
+++ b/infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/GitUserProfileProvisioner.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2012-2018 Red Hat, Inc.
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ */
+package org.eclipse.che.workspace.infrastructure.kubernetes.provision;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static java.util.Collections.singletonMap;
+import static java.util.Optional.empty;
+import static java.util.Optional.of;
+import static java.util.Optional.ofNullable;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
+import io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder;
+import io.fabric8.kubernetes.api.model.Container;
+import io.fabric8.kubernetes.api.model.PodSpec;
+import io.fabric8.kubernetes.api.model.VolumeBuilder;
+import io.fabric8.kubernetes.api.model.VolumeMount;
+import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.eclipse.che.api.core.ServerException;
+import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
+import org.eclipse.che.api.user.server.PreferenceManager;
+import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
+import org.eclipse.che.commons.env.EnvironmentContext;
+import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
+
+@Singleton
+public class GitUserProfileProvisioner implements ConfigurationProvisioner {
+
+ private final String GIT_CONFIG_MAP_NAME_SUFFIX = "-gitconfig";
+
+ private static final String GIT_BASE_CONFIG_PATH = "/etc/";
+ private static final String GIT_CONFIG = "gitconfig";
+ private static final String GIT_CONFIG_PATH = GIT_BASE_CONFIG_PATH + GIT_CONFIG;
+ private static final String PREFERENCES_KEY_FILTER = "theia-user-preferences";
+ private static final String GIT_USER_NAME_PROPERTY = "git.user.name";
+ private static final String GIT_USER_EMAIL_PROPERTY = "git.user.email";
+ private static final String CONFIG_MAP_VOLUME_NAME = "gitconfigvolume";
+
+ private PreferenceManager preferenceManager;
+
+ @Inject
+ public GitUserProfileProvisioner(PreferenceManager preferenceManager) {
+ this.preferenceManager = preferenceManager;
+ }
+
+ @Override
+ public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity)
+ throws InfrastructureException {
+ getPreferenceValue(PREFERENCES_KEY_FILTER)
+ .ifPresent(
+ preferenceJsonValue -> {
+ Map theiaPreferences = getMapFromJsonObject(preferenceJsonValue);
+
+ getGlobalGitConfigFileContent(
+ theiaPreferences.get(GIT_USER_NAME_PROPERTY),
+ theiaPreferences.get(GIT_USER_EMAIL_PROPERTY))
+ .ifPresent(
+ gitConfigFileContent -> {
+ String gitConfigMapName =
+ identity.getWorkspaceId() + GIT_CONFIG_MAP_NAME_SUFFIX;
+
+ doProvisionGlobalGitConfig(gitConfigMapName, gitConfigFileContent, k8sEnv);
+ });
+ });
+ }
+
+ private Map getMapFromJsonObject(String json) {
+ Type stringMapType = new TypeToken