refactor: replaced individual convigurators with set
Signed-off-by: xbaran4 <pbaran@redhat.com>pull/117/head
parent
31366691ec
commit
e73266e957
|
|
@ -48,6 +48,9 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.devfile.KubernetesDev
|
|||
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironmentFactory;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.RemoveNamespaceOnWorkspaceRemove;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.UserPreferencesConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.UserProfileConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.PerWorkspacePVCStrategy;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.UniqueWorkspacePVCStrategy;
|
||||
|
|
@ -98,6 +101,11 @@ public class KubernetesInfraModule extends AbstractModule {
|
|||
workspaceAttributeValidators.addBinding().to(K8sInfraNamespaceWsAttributeValidator.class);
|
||||
workspaceAttributeValidators.addBinding().to(AsyncStorageModeValidator.class);
|
||||
|
||||
Multibinder<NamespaceConfigurator> namespaceConfigurators =
|
||||
Multibinder.newSetBinder(binder(), NamespaceConfigurator.class);
|
||||
namespaceConfigurators.addBinding().to(UserProfileConfigurator.class);
|
||||
namespaceConfigurators.addBinding().to(UserPreferencesConfigurator.class);
|
||||
|
||||
bind(KubernetesNamespaceService.class);
|
||||
|
||||
MapBinder<String, InternalEnvironmentFactory> factories =
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.che.workspace.infrastructure.kubernetes.provision;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.Namespace;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl;
|
||||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
|
||||
|
|
@ -20,8 +21,6 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.Kubernetes
|
|||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.NamespaceConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.UserPreferencesConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.UserProfileConfigurator;
|
||||
|
||||
/**
|
||||
* Provisions the k8s {@link Namespace}. After provisioning, configures the namespace through {@link
|
||||
|
|
@ -31,17 +30,14 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurato
|
|||
*/
|
||||
public class NamespaceProvisioner {
|
||||
private final KubernetesNamespaceFactory namespaceFactory;
|
||||
private final UserProfileConfigurator userProfileConfigurator;
|
||||
private final UserPreferencesConfigurator userPreferencesConfigurator;
|
||||
private final Set<NamespaceConfigurator> namespaceConfigurators;
|
||||
|
||||
@Inject
|
||||
public NamespaceProvisioner(
|
||||
KubernetesNamespaceFactory namespaceFactory,
|
||||
UserProfileConfigurator userProfileConfigurator,
|
||||
UserPreferencesConfigurator userPreferencesConfigurator) {
|
||||
Set<NamespaceConfigurator> namespaceConfigurators) {
|
||||
this.namespaceFactory = namespaceFactory;
|
||||
this.userProfileConfigurator = userProfileConfigurator;
|
||||
this.userPreferencesConfigurator = userPreferencesConfigurator;
|
||||
this.namespaceConfigurators = namespaceConfigurators;
|
||||
}
|
||||
|
||||
/** Tests for this method are in KubernetesFactoryTest. */
|
||||
|
|
@ -68,7 +64,8 @@ public class NamespaceProvisioner {
|
|||
|
||||
private void configureNamespace(NamespaceResolutionContext namespaceResolutionContext)
|
||||
throws InfrastructureException {
|
||||
userProfileConfigurator.configure(namespaceResolutionContext);
|
||||
userPreferencesConfigurator.configure(namespaceResolutionContext);
|
||||
for (NamespaceConfigurator configurator : namespaceConfigurators) {
|
||||
configurator.configure(namespaceResolutionContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE;
|
||||
import static org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta.DEFAULT_ATTRIBUTE;
|
||||
|
|
@ -23,7 +24,6 @@ import static org.mockito.ArgumentMatchers.any;
|
|||
import static org.mockito.ArgumentMatchers.anyMap;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
|
|
@ -87,8 +87,6 @@ import org.eclipse.che.workspace.infrastructure.kubernetes.CheServerKubernetesCl
|
|||
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls.KubernetesNamespaceMetaImpl;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.UserPreferencesConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.UserProfileConfigurator;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.provision.NamespaceProvisioner;
|
||||
import org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
|
@ -140,9 +138,6 @@ public class KubernetesNamespaceFactoryTest {
|
|||
|
||||
@Mock private NamespaceList namespaceList;
|
||||
|
||||
@Mock private UserProfileConfigurator userProfileConfigurator;
|
||||
@Mock private UserPreferencesConfigurator userPreferencesConfigurator;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() throws Exception {
|
||||
serverMock = new KubernetesServer(true, true);
|
||||
|
|
@ -1546,10 +1541,6 @@ public class KubernetesNamespaceFactoryTest {
|
|||
|
||||
private KubernetesNamespaceMeta testProvisioning(NamespaceResolutionContext context)
|
||||
throws InfrastructureException {
|
||||
doNothing().when(userProfileConfigurator).configure(any());
|
||||
doNothing().when(userPreferencesConfigurator).configure(any());
|
||||
return new NamespaceProvisioner(
|
||||
namespaceFactory, userProfileConfigurator, userPreferencesConfigurator)
|
||||
.provision(context);
|
||||
return new NamespaceProvisioner(namespaceFactory, emptySet()).provision(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2021 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.namespace.configurator;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,14 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2021 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.namespace.configurator;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
|
|
|||
Loading…
Reference in New Issue