use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.
the class CredentialsSecretConfiguratorTest method setUp.
@BeforeMethod
public void setUp() throws InfrastructureException {
configurator = new CredentialsSecretConfigurator(clientFactory);
serverMock = new KubernetesServer(true, true);
serverMock.before();
KubernetesClient client = spy(serverMock.getClient());
when(clientFactory.create()).thenReturn(client);
namespaceResolutionContext = new NamespaceResolutionContext(TEST_WORKSPACE_ID, TEST_USER_ID, TEST_USERNAME);
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.
the class UserPermissionConfiguratorTest method setUp.
@BeforeMethod
public void setUp() throws InfrastructureException {
configurator = new UserPermissionConfigurator(TEST_CLUSTER_ROLES, clientFactory);
serverMock = new KubernetesServer(true, true);
serverMock.before();
client = spy(serverMock.getClient());
lenient().when(clientFactory.create()).thenReturn(client);
namespaceResolutionContext = new NamespaceResolutionContext(TEST_WORKSPACE_ID, TEST_USER_ID, TEST_USERNAME);
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.
the class UserProfileConfiguratorTest method setUp.
@BeforeMethod
public void setUp() throws InfrastructureException, NotFoundException, ServerException {
context = new NamespaceResolutionContext(null, USER_ID, USER_NAME);
kubernetesServer = new KubernetesServer(true, true);
kubernetesServer.before();
when(userManager.getById(USER_ID)).thenReturn(new UserImpl(USER_ID, USER_EMAIL, USER_NAME));
when(clientFactory.create()).thenReturn(kubernetesServer.getClient());
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactory method getOrCreate.
public KubernetesNamespace getOrCreate(RuntimeIdentity identity) throws InfrastructureException {
KubernetesNamespace namespace = get(identity);
var subject = EnvironmentContext.getCurrent().getSubject();
NamespaceResolutionContext resolutionCtx = new NamespaceResolutionContext(identity.getWorkspaceId(), subject.getUserId(), subject.getUserName());
Map<String, String> namespaceAnnotationsEvaluated = evaluateAnnotationPlaceholders(resolutionCtx);
namespace.prepare(canCreateNamespace(identity), labelNamespaces ? namespaceLabels : emptyMap(), annotateNamespaces ? namespaceAnnotationsEvaluated : emptyMap());
configureNamespace(resolutionCtx, namespace.getName());
return namespace;
}
use of org.eclipse.che.api.workspace.server.spi.NamespaceResolutionContext in project devspaces-images by redhat-developer.
the class KubernetesNamespaceFactory method getNamespaceName.
/**
* Returns a namespace name where workspace is assigned to.
*/
protected String getNamespaceName(Workspace workspace) throws InfrastructureException {
String namespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
if (namespace == null) {
// it seems to be legacy workspace since the namespace is not stored in workspace attributes
// it's needed to evaluate that with current user and workspace id
NamespaceResolutionContext resolutionCtx = new NamespaceResolutionContext(workspace.getId(), EnvironmentContext.getCurrent().getSubject().getUserId(), EnvironmentContext.getCurrent().getSubject().getUserName());
namespace = evaluateNamespaceName(resolutionCtx);
LOG.warn("Workspace '{}' doesn't have an explicit namespace assigned." + " The legacy namespace resolution resolved it to '{}'.", workspace.getId(), namespace);
}
if (!NamespaceNameValidator.isValid(namespace)) {
// At a certain unfortunate past version of Che, we stored invalid namespace names.
// At this point in time, we're trying to work with an existing workspace that never could
// started OR has been running since before that unfortunate version. In both cases, going
// back to the default namespace name is the most safe bet we can make.
// but of course, our attempt will be futile if we're running in a context that doesn't know
// the current user.
Subject subj = EnvironmentContext.getCurrent().getSubject();
if (!subj.isAnonymous()) {
NamespaceResolutionContext resolutionCtx = new NamespaceResolutionContext(workspace.getId(), subj.getUserId(), subj.getUserName());
String defaultNamespace = evaluateNamespaceName(resolutionCtx);
LOG.warn("The namespace '{}' of the workspace '{}' is not valid. Trying to recover" + " from this situation using a default namespace which resolved to '{}'.", namespace, workspace.getId(), defaultNamespace);
namespace = defaultNamespace;
} else {
// log a warning including a stacktrace to be able to figure out from where we got here...
LOG.warn("The namespace '{}' of the workspace '{}' is not valid but we currently don't have" + " an active user to try an recover from this situation. We're letting the parent" + " workflow continue, but it may fail at some later point in time because of" + " the incorrect namespace name in use.", namespace, workspace.getId(), new Throwable());
}
// ok, we tried to recover the namespace but nothing helped.
}
return namespace;
}
Aggregations