Skip to content

Commit ad54670

Browse files
authored
Merge pull request #42 from PizzaFactory/prp-update-to-the-upstream
[Scheduled] Update to the upstream
2 parents aa5793b + 56964a4 commit ad54670

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

infrastructures/infrastructure-factory/src/main/java/org/eclipse/che/api/factory/server/scm/kubernetes/KubernetesGitCredentialManager.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import static java.lang.String.format;
1515
import static java.nio.charset.StandardCharsets.UTF_8;
1616
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.KubernetesSecretAnnotationNames.ANNOTATION_AUTOMOUNT;
17+
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.KubernetesSecretAnnotationNames.ANNOTATION_DEV_WORKSPACE_MOUNT_PATH;
1718
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.KubernetesSecretAnnotationNames.ANNOTATION_GIT_CREDENTIALS;
1819
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.KubernetesSecretAnnotationNames.ANNOTATION_MOUNT_AS;
1920
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.KubernetesSecretAnnotationNames.ANNOTATION_MOUNT_PATH;
21+
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.KubernetesSecretAnnotationNames.DEV_WORKSPACE_PREFIX;
2022

2123
import com.google.common.collect.ImmutableMap;
2224
import io.fabric8.kubernetes.api.model.ObjectMeta;
@@ -54,22 +56,29 @@ public class KubernetesGitCredentialManager implements GitCredentialManager {
5456
public static final String ANNOTATION_SCM_URL = "che.eclipse.org/scm-url";
5557
public static final String ANNOTATION_SCM_USERNAME = "che.eclipse.org/scm-username";
5658
public static final String ANNOTATION_CHE_USERID = "che.eclipse.org/che-userid";
59+
public static final String CREDENTIALS_MOUNT_PATH = "/home/theia/.git-credentials";
60+
public static final String LABEL_DEV_WORKSPACE_CREDENTIAL =
61+
DEV_WORKSPACE_PREFIX + "/git-credential";
5762

58-
private static final Map<String, String> LABELS =
63+
// Labels that that are use to search for already existing secret.
64+
private static final Map<String, String> SEARCH_LABELS =
5965
ImmutableMap.of(
6066
"app.kubernetes.io/part-of", "che.eclipse.org",
6167
"app.kubernetes.io/component", "workspace-secret");
68+
// Labels that will be added to newly created secret.
69+
private static final Map<String, String> NEW_SECRET_LABELS =
70+
ImmutableMap.<String, String>builder()
71+
.putAll(SEARCH_LABELS)
72+
.put(LABEL_DEV_WORKSPACE_CREDENTIAL, "true")
73+
.build();
6274

6375
static final Map<String, String> DEFAULT_SECRET_ANNOTATIONS =
6476
ImmutableMap.of(
65-
ANNOTATION_AUTOMOUNT,
66-
"true",
67-
ANNOTATION_MOUNT_PATH,
68-
"/home/theia/.git-credentials",
69-
ANNOTATION_MOUNT_AS,
70-
"file",
71-
ANNOTATION_GIT_CREDENTIALS,
72-
"true");
77+
ANNOTATION_AUTOMOUNT, "true",
78+
ANNOTATION_MOUNT_PATH, CREDENTIALS_MOUNT_PATH,
79+
ANNOTATION_MOUNT_AS, "file",
80+
ANNOTATION_GIT_CREDENTIALS, "true",
81+
ANNOTATION_DEV_WORKSPACE_MOUNT_PATH, CREDENTIALS_MOUNT_PATH);
7382

7483
private final KubernetesNamespaceFactory namespaceFactory;
7584
private final KubernetesClientFactory clientFactory;
@@ -93,7 +102,7 @@ public void createOrReplace(PersonalAccessToken personalAccessToken)
93102
client
94103
.secrets()
95104
.inNamespace(namespace)
96-
.withLabels(LABELS)
105+
.withLabels(SEARCH_LABELS)
97106
.list()
98107
.getItems()
99108
.stream()
@@ -128,7 +137,7 @@ public void createOrReplace(PersonalAccessToken personalAccessToken)
128137
new ObjectMetaBuilder()
129138
.withName(NameGenerator.generate(NAME_PATTERN, 5))
130139
.withAnnotations(annotations)
131-
.withLabels(LABELS)
140+
.withLabels(NEW_SECRET_LABELS)
132141
.build();
133142
return new SecretBuilder().withMetadata(meta).build();
134143
});

infrastructures/kubernetes/src/main/java/org/eclipse/che/workspace/infrastructure/kubernetes/provision/secret/KubernetesSecretAnnotationNames.java

+7
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ public class KubernetesSecretAnnotationNames {
4242
/** For 'env' type secrets defines the environment variable name template to mount secret with */
4343
public static final String ANNOTATION_ENV_NAME_TEMPLATE = ANNOTATION_PREFIX + "/%s_" + "env-name";
4444

45+
/** Common prefix for annotations associated with devworkspaces */
46+
public static final String DEV_WORKSPACE_PREFIX = "controller.devfile.io";
47+
48+
/** For 'file' type secrets defines the path where ih should be mount */
49+
public static final String ANNOTATION_DEV_WORKSPACE_MOUNT_PATH =
50+
DEV_WORKSPACE_PREFIX + "/" + "mount-path";
51+
4552
private KubernetesSecretAnnotationNames() {}
4653
}

wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
package org.eclipse.che.api.factory.server.urlfactory;
1313

1414
import static com.google.common.base.Strings.isNullOrEmpty;
15-
import static java.lang.String.format;
1615
import static org.eclipse.che.api.factory.server.DevfileToApiExceptionMapper.toApiException;
1716
import static org.eclipse.che.api.factory.shared.Constants.CURRENT_VERSION;
1817
import static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_API_VERSION;
@@ -168,16 +167,11 @@ private FactoryMetaDto createFactory(
168167
.withDevfile(DtoConverter.asDto(devfile))
169168
.withSource(location.filename().isPresent() ? location.filename().get() : null);
170169

171-
} else if (devWorskspacesEnabled) {
170+
} else {
172171
return newDto(FactoryDevfileV2Dto.class)
173172
.withV(CURRENT_VERSION)
174173
.withDevfile(devfileParser.convertYamlToMap(devfileJson))
175174
.withSource(location.filename().isPresent() ? location.filename().get() : null);
176-
} else {
177-
throw new DevfileException(
178-
format(
179-
"Devfile of version %s cannot be used in current deployment, because of DevWorkspaces feature is disabled. Only '1.0.0' version devfiles are supported for such installations.",
180-
devfileVersionDetector.devfileVersion(devfileJson)));
181175
}
182176
}
183177

wsmaster/che-core-api-factory/src/test/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilderTest.java

+12-14
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.Map;
3939
import java.util.Optional;
4040
import org.eclipse.che.api.core.ApiException;
41-
import org.eclipse.che.api.core.BadRequestException;
4241
import org.eclipse.che.api.core.ServerException;
4342
import org.eclipse.che.api.core.UnauthorizedException;
4443
import org.eclipse.che.api.core.rest.shared.dto.ExtendedError;
@@ -299,31 +298,30 @@ public void setDevfileFilename(String devfileName) {
299298
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
300299
}
301300

302-
@Test(
303-
expectedExceptions = BadRequestException.class,
304-
expectedExceptionsMessageRegExp =
305-
"Error occurred during creation a workspace from devfile located at `http://foo-location/`. Cause: Devfile of version 2.0.1 cannot be used in current deployment, because of DevWorkspaces feature is disabled. Only '1.0.0' version devfiles are supported for such installations.")
306-
public void testShouldThrowExceptionOnDevfileV2WithDevworkspacesDisabled()
307-
throws ApiException, DevfileException {
301+
@Test
302+
public void testShouldReturnV2WithDevworkspacesDisabled() throws ApiException, DevfileException {
308303
String myLocation = "http://foo-location/";
309304
Map<String, Object> devfileAsMap = Map.of("hello", "there", "how", "are", "you", "?");
310305

311306
JsonNode devfile = new ObjectNode(JsonNodeFactory.instance);
312307
when(devfileParser.parseYamlRaw(anyString())).thenReturn(devfile);
313308
when(devfileParser.convertYamlToMap(devfile)).thenReturn(devfileAsMap);
314309
when(devfileVersionDetector.devfileMajorVersion(devfile)).thenReturn(2);
315-
when(devfileVersionDetector.devfileVersion(devfile)).thenReturn("2.0.1");
316310

317311
URLFactoryBuilder localUrlFactoryBuilder =
318312
new URLFactoryBuilder(
319313
defaultEditor, defaultPlugin, false, devfileParser, devfileVersionDetector);
320314

321-
localUrlFactoryBuilder
322-
.createFactoryFromDevfile(
323-
new DefaultFactoryUrl().withDevfileFileLocation(myLocation),
324-
s -> myLocation + ".list",
325-
emptyMap())
326-
.get();
315+
FactoryMetaDto factory =
316+
localUrlFactoryBuilder
317+
.createFactoryFromDevfile(
318+
new DefaultFactoryUrl().withDevfileFileLocation(myLocation),
319+
s -> myLocation + ".list",
320+
emptyMap())
321+
.get();
322+
assertNotNull(factory);
323+
assertTrue(factory instanceof FactoryDevfileV2Dto);
324+
assertEquals(((FactoryDevfileV2Dto) factory).getDevfile(), devfileAsMap);
327325
}
328326

329327
@DataProvider

0 commit comments

Comments
 (0)