use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class PVCSubPathHelper method execute.
private void execute(RuntimeIdentity identity, String workspaceId, String namespace, String pvcName, String[] commandBase, Map<String, String> startOptions, boolean watchFailureEvents, String... arguments) {
final String jobName = commandBase[0];
final String podName = jobName + '-' + workspaceId;
final String[] command = buildCommand(commandBase, arguments);
final Pod pod = newPod(podName, pvcName, command);
securityContextProvisioner.provision(pod.getSpec());
nodeSelectorProvisioner.provision(pod.getSpec());
tolerationsProvisioner.provision(pod.getSpec());
KubernetesDeployments deployments = null;
try {
KubernetesNamespace ns = factory.access(workspaceId, namespace);
if (!checkPVCExistsAndNotTerminating(ns, pvcName)) {
return;
}
deployments = ns.deployments();
deployments.create(pod);
watchLogsIfDebugEnabled(deployments, pod, identity, startOptions);
PodStatus finishedStatus = waitPodStatus(podName, deployments, watchFailureEvents);
if (POD_PHASE_FAILED.equals(finishedStatus.getPhase())) {
String logs = deployments.getPodLogs(podName);
LOG.error("Job command '{}' execution is failed. Logs: {}", Arrays.toString(command), // Force logs onto one line
Strings.nullToEmpty(logs).replace("\n", " \\n"));
}
} catch (InfrastructureException ex) {
LOG.error("Unable to perform '{}' command for the workspace '{}' cause: '{}'", Arrays.toString(command), workspaceId, ex.getMessage());
deployments.stopWatch(true);
} finally {
if (deployments != null) {
deployments.stopWatch();
try {
deployments.delete(podName);
} catch (InfrastructureException ignored) {
}
}
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class GatewayTlsProvisioner method useSecureProtocolForGatewayConfigMap.
private void useSecureProtocolForGatewayConfigMap(ConfigMap configMap) throws InfrastructureException {
Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(configMap.getMetadata().getAnnotations()).servers();
if (servers.isEmpty()) {
return;
}
if (servers.size() != 1) {
throw new InfrastructureException("Expected exactly 1 server in Gateway configuration ConfigMap '" + configMap.getMetadata().getName() + "'. This is a bug, please report.");
}
Entry<String, ServerConfigImpl> serverConfigEntry = servers.entrySet().iterator().next();
ServerConfigImpl serverConfig = serverConfigEntry.getValue();
serverConfig.setProtocol(getSecureProtocol(serverConfig.getProtocol()));
configMap.getMetadata().getAnnotations().putAll(Annotations.newSerializer().server(serverConfigEntry.getKey(), serverConfig).annotations());
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class AsyncStorageProvisioner method provision.
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
if (!parseBoolean(k8sEnv.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
return;
}
if (!COMMON_STRATEGY.equals(pvcStrategy)) {
String message = format("Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s", pvcStrategy);
LOG.warn(message);
k8sEnv.addWarning(new WarningImpl(4200, message));
throw new InfrastructureException(message);
}
if (!isEphemeral(k8sEnv.getAttributes())) {
String message = format("Workspace configuration not valid: Asynchronous storage available only if '%s' attribute set to false", PERSIST_VOLUMES_ATTRIBUTE);
LOG.warn(message);
k8sEnv.addWarning(new WarningImpl(4200, message));
throw new InfrastructureException(message);
}
String namespace = identity.getInfrastructureNamespace();
String userId = identity.getOwnerId();
KubernetesClient k8sClient = kubernetesClientFactory.create(identity.getWorkspaceId());
String configMapName = namespace + ASYNC_STORAGE_CONFIG;
createPvcIfNotExist(k8sClient, namespace, userId);
createConfigMapIfNotExist(k8sClient, namespace, configMapName, userId, k8sEnv);
createAsyncStoragePodIfNotExist(k8sClient, namespace, configMapName, userId);
createStorageServiceIfNotExist(k8sClient, namespace, userId);
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class GitCredentialStorageFileSecretApplier method applySecret.
@Override
public void applySecret(KubernetesEnvironment env, RuntimeIdentity runtimeIdentity, Secret secret) throws InfrastructureException {
super.applySecret(env, runtimeIdentity, secret);
final String secretMountPath = secret.getMetadata().getAnnotations().get(ANNOTATION_MOUNT_PATH);
Set<String> keys = secret.getData().keySet();
if (keys.size() != 1) {
throw new InfrastructureException(format("Invalid git credential secret data. It should contain only 1 data item but it have %d", keys.size()));
}
Path gitSecretFilePath = Paths.get(secretMountPath, keys.iterator().next());
ConfigMap gitConfigMap = env.getConfigMaps().get(GitConfigProvisioner.GIT_CONFIG_MAP_NAME);
if (gitConfigMap != null) {
Map<String, String> gitConfigMapData = gitConfigMap.getData();
String gitConfig = gitConfigMapData.get(GitConfigProvisioner.GIT_CONFIG);
if (gitConfig != null) {
if (gitConfig.contains("helper = store --file") && gitConfig.contains("[credential]")) {
throw new InfrastructureException(format("Multiple git credential secrets for user %s found in namespace %s. That may be caused by reinstalling product without user namespaces cleanup or using multiple instances of product with the same namespace namings template.", secret.getMetadata().getAnnotations().get(ANNOTATION_USER_NAME), secret.getMetadata().getNamespace()));
}
HashMap<String, String> newGitConfigMapData = new HashMap<>(gitConfigMapData);
newGitConfigMapData.put(GitConfigProvisioner.GIT_CONFIG, gitConfig + String.format(GIT_CREDENTIALS_FILE_STORE_PATTERN, gitSecretFilePath.toString()));
gitConfigMap.setData(newGitConfigMapData);
}
}
}
use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.
the class OpenShiftProjectTest method testOpenShiftProjectCleaningUpIfExceptionsOccurs.
@Test
public void testOpenShiftProjectCleaningUpIfExceptionsOccurs() throws Exception {
doThrow(new InfrastructureException("err1.")).when(services).delete();
doThrow(new InfrastructureException("err2.")).when(deployments).delete();
InfrastructureException error = null;
// when
try {
openShiftProject.cleanUp();
} catch (InfrastructureException e) {
error = e;
}
// then
assertNotNull(error);
String message = error.getMessage();
assertEquals(message, "Error(s) occurs while cleaning up the namespace. err1. err2.");
verify(routes).delete();
}
Aggregations