-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Removing dependency on usr, accout, profile db entries #398
Merged
ibuziuk
merged 2 commits into
eclipse-che:main
from
ibuziuk:usr-account-profile-deprecation
Jan 12, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2012-2021 Red Hat, Inc. | ||
* Copyright (c) 2012-2022 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/ | ||
|
@@ -41,10 +41,8 @@ | |
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import javax.inject.Named; | ||
import org.eclipse.che.api.core.NotFoundException; | ||
import org.eclipse.che.api.core.ServerException; | ||
import org.eclipse.che.api.core.ValidationException; | ||
import org.eclipse.che.api.core.model.user.User; | ||
import org.eclipse.che.api.core.model.workspace.Workspace; | ||
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; | ||
import org.eclipse.che.api.user.server.PreferenceManager; | ||
|
@@ -275,30 +273,21 @@ private KubernetesNamespaceMeta asNamespaceMeta(Namespace namespace) { | |
* the context. | ||
* | ||
* @param identity the identity of the workspace runtime | ||
* @param userName the user name | ||
* @return true if the namespace can be created, false if the namespace is expected to already | ||
* exist | ||
* @throws InfrastructureException on failure | ||
*/ | ||
protected boolean canCreateNamespace(RuntimeIdentity identity) throws InfrastructureException { | ||
protected boolean canCreateNamespace(RuntimeIdentity identity, String userName) | ||
throws InfrastructureException { | ||
if (!namespaceCreationAllowed) { | ||
return false; | ||
} | ||
|
||
// we need to make sure that the provided namespace is indeed the one provided by our | ||
// configuration | ||
User owner; | ||
try { | ||
owner = userManager.getById(identity.getOwnerId()); | ||
} catch (NotFoundException | ServerException e) { | ||
throw new InfrastructureException( | ||
"Failed to resolve workspace owner. Cause: " + e.getMessage(), e); | ||
} | ||
|
||
String requiredNamespace = identity.getInfrastructureNamespace(); | ||
|
||
NamespaceResolutionContext resolutionContext = | ||
new NamespaceResolutionContext( | ||
identity.getWorkspaceId(), identity.getOwnerId(), owner.getName()); | ||
new NamespaceResolutionContext(identity.getWorkspaceId(), identity.getOwnerId(), userName); | ||
|
||
String resolvedDefaultNamespace = evaluateNamespaceName(resolutionContext); | ||
|
||
|
@@ -320,14 +309,14 @@ public KubernetesNamespace getOrCreate(RuntimeIdentity identity) throws Infrastr | |
KubernetesNamespace namespace = get(identity); | ||
|
||
var subject = EnvironmentContext.getCurrent().getSubject(); | ||
var userName = subject.getUserName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment to |
||
NamespaceResolutionContext resolutionCtx = | ||
new NamespaceResolutionContext( | ||
identity.getWorkspaceId(), subject.getUserId(), subject.getUserName()); | ||
new NamespaceResolutionContext(identity.getWorkspaceId(), subject.getUserId(), userName); | ||
Map<String, String> namespaceAnnotationsEvaluated = | ||
evaluateAnnotationPlaceholders(resolutionCtx); | ||
|
||
namespace.prepare( | ||
canCreateNamespace(identity), | ||
canCreateNamespace(identity, userName), | ||
labelNamespaces ? namespaceLabels : emptyMap(), | ||
annotateNamespaces ? namespaceAnnotationsEvaluated : emptyMap()); | ||
|
||
|
@@ -515,9 +504,6 @@ private String evalDefaultNamespace(NamespaceResolutionContext resolutionCtx) | |
"Evaluated the namespace for workspace {} using the namespace default to {}", | ||
resolutionCtx.getWorkspaceId(), | ||
namespace); | ||
|
||
recordEvaluatedNamespaceName(namespace, resolutionCtx); | ||
|
||
return namespace; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ | |
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator; | ||
|
||
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.AbstractWorkspaceServiceAccount.GIT_USERDATA_CONFIGMAP_NAME; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
|
@@ -25,9 +23,6 @@ | |
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.eclipse.che.api.core.NotFoundException; | ||
import org.eclipse.che.api.core.ServerException; | ||
import org.eclipse.che.api.core.model.user.User; | ||
import org.eclipse.che.api.factory.server.scm.GitUserData; | ||
import org.eclipse.che.api.factory.server.scm.GitUserDataFetcher; | ||
import org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException; | ||
|
@@ -95,19 +90,6 @@ public void createUserdataConfigmapWhenDoesNotExist() | |
.get()); | ||
} | ||
|
||
@Test | ||
public void doNothingWhenGitUserDataAndCheUserAreNull() | ||
throws InfrastructureException, ServerException, NotFoundException { | ||
// when | ||
when(userManager.getById(anyString())).thenThrow(new NotFoundException("not found")); | ||
configurator.configure(namespaceResolutionContext, TEST_NAMESPACE_NAME); | ||
|
||
// then - don't create the configmap | ||
var configMaps = | ||
serverMock.getClient().configMaps().inNamespace(TEST_NAMESPACE_NAME).list().getItems(); | ||
Assert.assertEquals(configMaps.size(), 0); | ||
} | ||
|
||
@Test | ||
public void doNothingWhenSecretAlreadyExists() | ||
throws InfrastructureException, InterruptedException, ScmCommunicationException, | ||
|
@@ -151,30 +133,4 @@ public void doNothingWhenSecretAlreadyExists() | |
Assert.assertEquals(configMaps.size(), 1); | ||
Assert.assertEquals(configMaps.get(0).getMetadata().getAnnotations().get("already"), "created"); | ||
} | ||
|
||
@Test | ||
public void createUserdataConfigmapFromCheUserData() | ||
throws InfrastructureException, ServerException, NotFoundException, InterruptedException { | ||
// given | ||
User user = mock(User.class); | ||
when(user.getName()).thenReturn("test name"); | ||
when(user.getEmail()).thenReturn("[email protected]"); | ||
when(userManager.getById(anyString())).thenReturn(user); | ||
|
||
// when | ||
configurator.configure(namespaceResolutionContext, TEST_NAMESPACE_NAME); | ||
|
||
// then create a secret | ||
Assert.assertEquals(serverMock.getLastRequest().getMethod(), "POST"); | ||
ConfigMap configMap = | ||
serverMock | ||
.getClient() | ||
.configMaps() | ||
.inNamespace(TEST_NAMESPACE_NAME) | ||
.withName(GIT_USERDATA_CONFIGMAP_NAME) | ||
.get(); | ||
Assert.assertNotNull(configMap); | ||
Assert.assertTrue(configMap.getData().get("gitconfig").contains("test name")); | ||
Assert.assertTrue(configMap.getData().get("gitconfig").contains("[email protected]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I look at
canCreateNamespace
andgetOrCreate
I would considerSince RuntimeIdentity has already ownerId I think second option is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also thought about that, but this would require quite a few changes in the obsolete classes like PluginBrokerManager which are planned to be removed completely in Phase 2 of the db removal procedure. The goal of this PR is to make all the stored data in Postgres irrelevant. In the future PR, major cleanup / refactoring is going to happen when the whole DAO layer will be removed completely (currently targeted for 7.61)