Upgrade kubernetes-client to 5.3.1 (#19744)

* Upgrade dependencies

Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
pull/3/head
Sergii Kabashniuk 2021-05-11 14:57:50 +03:00 committed by GitHub
parent 2a7a2f669b
commit d4e695ecac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 379 additions and 508 deletions

View File

@ -37,7 +37,7 @@
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model</artifactId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>

View File

@ -27,15 +27,12 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import io.fabric8.kubernetes.api.model.DoneableSecret;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import io.fabric8.kubernetes.api.model.SecretList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
@ -64,17 +61,11 @@ public class KubernetesGitCredentialManagerTest {
@Mock private KubernetesClientFactory clientFactory;
@Mock private KubernetesClient kubeClient;
@Mock
private MixedOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>>
secretsMixedOperation;
@Mock private MixedOperation<Secret, SecretList, Resource<Secret>> secretsMixedOperation;
@Mock
NonNamespaceOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>>
nonNamespaceOperation;
@Mock NonNamespaceOperation<Secret, SecretList, Resource<Secret>> nonNamespaceOperation;
@Mock
private FilterWatchListDeletable<Secret, SecretList, Boolean, Watch, Watcher<Secret>>
filterWatchDeletable;
@Mock private FilterWatchListDeletable<Secret, SecretList> filterWatchDeletable;
@Mock private SecretList secretList;

View File

@ -25,7 +25,6 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import io.fabric8.kubernetes.api.model.DoneableSecret;
import io.fabric8.kubernetes.api.model.LabelSelector;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
@ -68,13 +67,9 @@ public class KubernetesPersonalAccessTokenManagerTest {
@Mock private KubernetesClient kubeClient;
@Mock
private MixedOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>>
secretsMixedOperation;
@Mock private MixedOperation<Secret, SecretList, Resource<Secret>> secretsMixedOperation;
@Mock
NonNamespaceOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>>
nonNamespaceOperation;
@Mock NonNamespaceOperation<Secret, SecretList, Resource<Secret>> nonNamespaceOperation;
KubernetesPersonalAccessTokenManager personalAccessTokenManager;

View File

@ -83,7 +83,27 @@
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model</artifactId>
<artifactId>kubernetes-model-apps</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-batch</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-extensions</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-rbac</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>

View File

@ -13,9 +13,9 @@ package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static java.util.Collections.singletonList;
import io.fabric8.kubernetes.api.model.Doneable;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.ServiceAccountBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
@ -23,8 +23,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import org.eclipse.che.api.user.server.PreferenceManager;
import org.eclipse.che.api.user.server.UserManager;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.workspace.infrastructure.kubernetes.CheServerKubernetesClientFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory;
import org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool;
import org.slf4j.Logger;
@ -52,20 +54,10 @@ public abstract class AbstractWorkspaceServiceAccount<
private final String workspaceId;
private final Set<String> clusterRoleNames;
private final Function<
Client,
MixedOperation<
R,
? extends KubernetesResourceList<R>,
? extends Doneable<R>,
? extends Resource<R, ? extends Doneable<R>>>>
Client, MixedOperation<R, ? extends KubernetesResourceList<R>, ? extends Resource<R>>>
roles;
private final Function<
Client,
MixedOperation<
B,
? extends KubernetesResourceList<B>,
? extends Doneable<B>,
? extends Resource<B, ? extends Doneable<B>>>>
Client, MixedOperation<B, ? extends KubernetesResourceList<B>, ? extends Resource<B>>>
roleBindings;
protected AbstractWorkspaceServiceAccount(
@ -75,20 +67,10 @@ public abstract class AbstractWorkspaceServiceAccount<
Set<String> clusterRoleNames,
ClientFactory<Client> clientFactory,
Function<
Client,
MixedOperation<
R,
? extends KubernetesResourceList<R>,
? extends Doneable<R>,
? extends Resource<R, ? extends Doneable<R>>>>
Client, MixedOperation<R, ? extends KubernetesResourceList<R>, ? extends Resource<R>>>
roles,
Function<
Client,
MixedOperation<
B,
? extends KubernetesResourceList<B>,
? extends Doneable<B>,
? extends Resource<B, ? extends Doneable<B>>>>
Client, MixedOperation<B, ? extends KubernetesResourceList<B>, ? extends Resource<B>>>
roleBindings) {
this.workspaceId = workspaceId;
this.namespace = namespace;
@ -173,7 +155,8 @@ public abstract class AbstractWorkspaceServiceAccount<
* 'che.infra.kubernetes.workspace_sa_cluster_roles' property.
*
* @see KubernetesNamespaceFactory#KubernetesNamespaceFactory(String, String, String, String,
* boolean, KubernetesClientFactory, UserManager, KubernetesSharedPool)
* boolean, boolean, boolean, String, String, KubernetesClientFactory,
* CheServerKubernetesClientFactory, UserManager, PreferenceManager, KubernetesSharedPool)
*/
private void createExplicitClusterRoleBindings(Client k8sClient) {
// If the user specified an additional cluster roles for the workspace,
@ -220,12 +203,13 @@ public abstract class AbstractWorkspaceServiceAccount<
k8sClient
.serviceAccounts()
.inNamespace(namespace)
.createOrReplaceWithNew()
.withAutomountServiceAccountToken(true)
.withNewMetadata()
.withName(serviceAccountName)
.endMetadata()
.done();
.createOrReplace(
new ServiceAccountBuilder()
.withAutomountServiceAccountToken(true)
.withNewMetadata()
.withName(serviceAccountName)
.endMetadata()
.build());
}
private void createRole(

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.CREATE_IN_CHE_INSTALLATION_NAMESPACE;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabel;
@ -157,7 +158,7 @@ public class CheNamespace {
.configMaps()
.inNamespace(cheNamespaceName)
.withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId)
.withPropagationPolicy("Background")
.withPropagationPolicy(BACKGROUND)
.delete();
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);

View File

@ -117,7 +117,7 @@ public class K8sVersion {
synchronized (this) {
if (versionInfo == null) {
versionInfo = clientFactory.create().getVersion();
LOG.debug("Obtained k8s version {}", versionInfo.getData());
LOG.debug("Obtained k8s version {} {}", versionInfo.getMajor(), versionInfo.getMinor());
parseVersions();
}
}

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabel;
@ -88,7 +89,7 @@ public class KubernetesConfigsMaps {
.configMaps()
.inNamespace(namespace)
.withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId)
.withPropagationPolicy("Background")
.withPropagationPolicy(BACKGROUND)
.delete();
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.CompletableFuture.allOf;
@ -26,7 +27,6 @@ import com.google.common.base.Strings;
import io.fabric8.kubernetes.api.model.ContainerStateTerminated;
import io.fabric8.kubernetes.api.model.ContainerStateWaiting;
import io.fabric8.kubernetes.api.model.ContainerStatus;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.ObjectReference;
@ -36,10 +36,10 @@ import io.fabric8.kubernetes.api.model.PodSpec;
import io.fabric8.kubernetes.api.model.PodStatus;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.ExecListener;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import io.fabric8.kubernetes.client.dsl.PodResource;
@ -296,12 +296,12 @@ public class KubernetesDeployments {
Watch watch = null;
try {
PodResource<Pod, DoneablePod> podResource =
PodResource<Pod> podResource =
clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
watch =
podResource.watch(
new Watcher<Pod>() {
new Watcher<>() {
@Override
public void eventReceived(Action action, Pod pod) {
if (predicate.test(pod)) {
@ -310,7 +310,7 @@ public class KubernetesDeployments {
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
future.completeExceptionally(
new InfrastructureException(
"Waiting for pod '" + podName + "' was interrupted"));
@ -371,18 +371,18 @@ public class KubernetesDeployments {
final CompletableFuture<Void> podRunningFuture = new CompletableFuture<>();
try {
final String podName = getPodName(name);
final PodResource<Pod, DoneablePod> podResource =
final PodResource<Pod> podResource =
clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
final Watch watch =
podResource.watch(
new Watcher<Pod>() {
new Watcher<>() {
@Override
public void eventReceived(Action action, Pod pod) {
handleStartingPodStatus(podRunningFuture, pod);
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
podRunningFuture.completeExceptionally(
new InfrastructureException(
"Waiting for pod '" + podName + "' was interrupted"));
@ -515,14 +515,14 @@ public class KubernetesDeployments {
public void watch(PodActionHandler handler) throws InfrastructureException {
if (podWatch == null) {
final Watcher<Pod> watcher =
new Watcher<Pod>() {
new Watcher<>() {
@Override
public void eventReceived(Action action, Pod pod) {
podActionHandlers.forEach(h -> h.handle(action, pod));
}
@Override
public void onClose(KubernetesClientException ignored) {}
public void onClose(WatcherException cause) {}
};
try {
podWatch =
@ -550,7 +550,7 @@ public class KubernetesDeployments {
public void watchEvents(PodEventHandler handler) throws InfrastructureException {
if (containerWatch == null) {
final Watcher<Event> watcher =
new Watcher<Event>() {
new Watcher<>() {
@Override
public void eventReceived(Action action, Event event) {
ObjectReference involvedObject = event.getInvolvedObject();
@ -598,7 +598,7 @@ public class KubernetesDeployments {
}
@Override
public void onClose(KubernetesClientException ignored) {}
public void onClose(WatcherException ignored) {}
/**
* Returns the container name if the event is related to container. When the event is
@ -631,7 +631,7 @@ public class KubernetesDeployments {
try {
watcherInitializationDate = new Date();
containerWatch =
clientFactory.create(workspaceId).events().inNamespace(namespace).watch(watcher);
clientFactory.create(workspaceId).v1().events().inNamespace(namespace).watch(watcher);
} catch (KubernetesClientException ex) {
throw new KubernetesInfrastructureException(ex);
}
@ -931,7 +931,7 @@ public class KubernetesDeployments {
Watch toCloseOnException = null;
try {
ScalableResource<Deployment, DoneableDeployment> deploymentResource =
ScalableResource<Deployment> deploymentResource =
clientFactory
.create(workspaceId)
.apps()
@ -948,16 +948,16 @@ public class KubernetesDeployments {
// If we have a Pod, we have to watch to make sure it is deleted, otherwise, we watch the
// Deployment we are deleting.
if (!Strings.isNullOrEmpty(podName)) {
PodResource<Pod, DoneablePod> podResource =
PodResource<Pod> podResource =
clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
watch = podResource.watch(new DeleteWatcher<Pod>(deleteFuture));
watch = podResource.watch(new DeleteWatcher<>(deleteFuture));
toCloseOnException = watch;
} else {
watch = deploymentResource.watch(new DeleteWatcher<Deployment>(deleteFuture));
toCloseOnException = watch;
}
Boolean deleteSucceeded = deploymentResource.withPropagationPolicy("Background").delete();
Boolean deleteSucceeded = deploymentResource.withPropagationPolicy(BACKGROUND).delete();
if (deleteSucceeded == null || !deleteSucceeded) {
deleteFuture.complete(null);
@ -985,17 +985,17 @@ public class KubernetesDeployments {
protected CompletableFuture<Void> doDeletePod(String podName) throws InfrastructureException {
Watch toCloseOnException = null;
try {
PodResource<Pod, DoneablePod> podResource =
PodResource<Pod> podResource =
clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
if (podResource.get() == null) {
throw new InfrastructureException(format("No pod found to delete for name %s", podName));
}
final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
final Watch watch = podResource.watch(new DeleteWatcher<Pod>(deleteFuture));
final Watch watch = podResource.watch(new DeleteWatcher<>(deleteFuture));
toCloseOnException = watch;
Boolean deleteSucceeded = podResource.withPropagationPolicy("Background").delete();
Boolean deleteSucceeded = podResource.withPropagationPolicy(BACKGROUND).delete();
if (deleteSucceeded == null || !deleteSucceeded) {
deleteFuture.complete(null);
}
@ -1105,7 +1105,7 @@ public class KubernetesDeployments {
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
future.completeExceptionally(
new RuntimeException("Websocket connection closed before Pod creation event received"));
}
@ -1127,7 +1127,7 @@ public class KubernetesDeployments {
}
@Override
public void onClose(KubernetesClientException e) {
public void onClose(WatcherException e) {
// if event about removing is received then this completion has no effect
future.completeExceptionally(
new RuntimeException(

View File

@ -11,14 +11,15 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabel;
import io.fabric8.kubernetes.api.model.extensions.DoneableIngress;
import io.fabric8.kubernetes.api.model.extensions.Ingress;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.Resource;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@ -84,7 +85,7 @@ public class KubernetesIngresses {
CompletableFuture<Ingress> future = new CompletableFuture<>();
Watch watch = null;
try {
Resource<Ingress, DoneableIngress> ingressResource =
Resource<Ingress> ingressResource =
clientFactory
.create(workspaceId)
.extensions()
@ -94,7 +95,7 @@ public class KubernetesIngresses {
watch =
ingressResource.watch(
new Watcher<Ingress>() {
new Watcher<>() {
@Override
public void eventReceived(Action action, Ingress ingress) {
if (predicate.test(ingress)) {
@ -103,7 +104,7 @@ public class KubernetesIngresses {
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
future.completeExceptionally(
new InfrastructureException(
"Waiting for ingress '" + name + "' was interrupted"));
@ -144,7 +145,7 @@ public class KubernetesIngresses {
.ingresses()
.inNamespace(namespace)
.withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId)
.withPropagationPolicy("Background")
.withPropagationPolicy(BACKGROUND)
.delete();
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);

View File

@ -11,11 +11,11 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static java.lang.String.format;
import com.google.common.annotations.VisibleForTesting;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.DoneableServiceAccount;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
@ -28,6 +28,7 @@ import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.Resource;
import java.util.HashMap;
import java.util.Map;
@ -309,11 +310,12 @@ public class KubernetesNamespace {
Namespace namespace =
client
.namespaces()
.createNew()
.withNewMetadata()
.withName(namespaceName)
.endMetadata()
.done();
.create(
new NamespaceBuilder()
.withNewMetadata()
.withName(namespaceName)
.endMetadata()
.build());
waitDefaultServiceAccount(namespaceName, client);
return namespace;
} catch (KubernetesClientException e) {
@ -329,7 +331,7 @@ public class KubernetesNamespace {
private void delete(String namespaceName, KubernetesClient client)
throws InfrastructureException {
try {
client.namespaces().withName(namespaceName).withPropagationPolicy("Background").delete();
client.namespaces().withName(namespaceName).withPropagationPolicy(BACKGROUND).delete();
} catch (KubernetesClientException e) {
if (e.getCode() == 404) {
LOG.warn(
@ -355,14 +357,14 @@ public class KubernetesNamespace {
final CompletableFuture<ServiceAccount> future = new CompletableFuture<>();
Watch watch = null;
try {
final Resource<ServiceAccount, DoneableServiceAccount> saResource =
final Resource<ServiceAccount> saResource =
client
.serviceAccounts()
.inNamespace(namespaceName)
.withName(DEFAULT_SERVICE_ACCOUNT_NAME);
watch =
saResource.watch(
new Watcher<ServiceAccount>() {
new Watcher<>() {
@Override
public void eventReceived(Action action, ServiceAccount serviceAccount) {
if (predicate.test(serviceAccount)) {
@ -371,7 +373,7 @@ public class KubernetesNamespace {
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
future.completeExceptionally(
new InfrastructureException(
"Waiting for service account '"

View File

@ -11,14 +11,15 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static java.util.stream.Collectors.toSet;
import io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.Resource;
import java.util.Collection;
import java.util.List;
@ -151,7 +152,7 @@ public class KubernetesPersistentVolumeClaims {
.persistentVolumeClaims()
.inNamespace(namespace)
.withLabels(labels)
.withPropagationPolicy("Background")
.withPropagationPolicy(BACKGROUND)
.delete();
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);
@ -172,7 +173,7 @@ public class KubernetesPersistentVolumeClaims {
public PersistentVolumeClaim waitBound(String name, long timeoutMillis)
throws InfrastructureException {
try {
Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim> pvcResource =
Resource<PersistentVolumeClaim> pvcResource =
clientFactory
.create(workspaceId)
.persistentVolumeClaims()
@ -212,7 +213,7 @@ public class KubernetesPersistentVolumeClaims {
private Watch pvcIsBoundWatcher(
CompletableFuture<PersistentVolumeClaim> future,
Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim> pvcResource) {
Resource<PersistentVolumeClaim> pvcResource) {
return pvcResource.watch(
new Watcher<PersistentVolumeClaim>() {
@Override
@ -224,7 +225,7 @@ public class KubernetesPersistentVolumeClaims {
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
safelyFinishFutureOnClose(cause, future, pvcResource.get().getMetadata().getName());
}
});
@ -238,6 +239,7 @@ public class KubernetesPersistentVolumeClaims {
throws InfrastructureException {
return clientFactory
.create(workspaceId)
.v1()
.events()
.inNamespace(namespace)
.withField(PVC_EVENT_REASON_FIELD_KEY, PVC_EVENT_WAIT_CONSUMER_REASON)
@ -254,16 +256,14 @@ public class KubernetesPersistentVolumeClaims {
}
@Override
public void onClose(KubernetesClientException cause) {
public void onClose(WatcherException cause) {
safelyFinishFutureOnClose(cause, future, actualPvc.getMetadata().getName());
}
});
}
private void safelyFinishFutureOnClose(
KubernetesClientException cause,
CompletableFuture<PersistentVolumeClaim> future,
String pvcName) {
WatcherException cause, CompletableFuture<PersistentVolumeClaim> future, String pvcName) {
if (cause != null) {
future.completeExceptionally(
new InfrastructureException(

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabel;
@ -87,7 +88,7 @@ public class KubernetesSecrets {
.secrets()
.inNamespace(namespace)
.withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId)
.withPropagationPolicy("Background")
.withPropagationPolicy(BACKGROUND)
.delete();
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabel;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putSelector;
@ -87,7 +88,7 @@ public class KubernetesServices {
.services()
.inNamespace(namespace)
.withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId)
.withPropagationPolicy("Background")
.withPropagationPolicy(BACKGROUND)
.delete();
} catch (KubernetesClientException e) {
throw new KubernetesInfrastructureException(e);

View File

@ -11,18 +11,18 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.provision;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static java.lang.String.format;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy.COMMON_STRATEGY;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.EphemeralWorkspaceUtility.isEphemeral;
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.AsyncStorageProvisioner.ASYNC_STORAGE;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.fabric8.kubernetes.client.dsl.RollableScalableResource;
import java.util.concurrent.CompletableFuture;
@ -74,7 +74,7 @@ public class AsyncStoragePodInterceptor {
String namespace = identity.getInfrastructureNamespace();
String workspaceId = identity.getWorkspaceId();
RollableScalableResource<Deployment, DoneableDeployment> asyncStorageDeploymentResource =
RollableScalableResource<Deployment> asyncStorageDeploymentResource =
getAsyncStorageDeploymentResource(namespace, workspaceId);
if (asyncStorageDeploymentResource.get() == null) { // deployment doesn't exist
@ -103,9 +103,8 @@ public class AsyncStoragePodInterceptor {
}
}
private RollableScalableResource<Deployment, DoneableDeployment>
getAsyncStorageDeploymentResource(String namespace, String workspaceId)
throws InfrastructureException {
private RollableScalableResource<Deployment> getAsyncStorageDeploymentResource(
String namespace, String workspaceId) throws InfrastructureException {
return kubernetesClientFactory
.create(workspaceId)
.apps()
@ -115,15 +114,14 @@ public class AsyncStoragePodInterceptor {
}
private CompletableFuture<Void> deleteAsyncStorageDeployment(
RollableScalableResource<Deployment, DoneableDeployment> resource)
throws InfrastructureException {
RollableScalableResource<Deployment> resource) throws InfrastructureException {
Watch toCloseOnException = null;
try {
final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
final Watch watch = resource.watch(new DeleteWatcher<>(deleteFuture));
toCloseOnException = watch;
Boolean deleteSucceeded = resource.withPropagationPolicy("Background").delete();
Boolean deleteSucceeded = resource.withPropagationPolicy(BACKGROUND).delete();
if (deleteSucceeded == null || !deleteSucceeded) {
deleteFuture.complete(null);
}
@ -156,7 +154,7 @@ public class AsyncStoragePodInterceptor {
String namespace = identity.getInfrastructureNamespace();
String workspaceId = identity.getWorkspaceId();
PodResource<Pod, DoneablePod> asyncStoragePodResource =
PodResource<Pod> asyncStoragePodResource =
kubernetesClientFactory
.create(workspaceId)
.pods()
@ -169,7 +167,7 @@ public class AsyncStoragePodInterceptor {
}
}
private CompletableFuture<Void> deleteAsyncStoragePod(PodResource<Pod, DoneablePod> podResource)
private CompletableFuture<Void> deleteAsyncStoragePod(PodResource<Pod> podResource)
throws InfrastructureException {
Watch toCloseOnException = null;
try {
@ -177,7 +175,7 @@ public class AsyncStoragePodInterceptor {
final Watch watch = podResource.watch(new DeleteWatcher<>(deleteFuture));
toCloseOnException = watch;
Boolean deleteSucceeded = podResource.withPropagationPolicy("Background").delete();
Boolean deleteSucceeded = podResource.withPropagationPolicy(BACKGROUND).delete();
if (deleteSucceeded == null || !deleteSucceeded) {
deleteFuture.complete(null);
}
@ -217,7 +215,7 @@ public class AsyncStoragePodInterceptor {
}
@Override
public void onClose(KubernetesClientException e) {
public void onClose(WatcherException e) {
// if event about removing is received then this completion has no effect
future.completeExceptionally(
new RuntimeException(

View File

@ -23,10 +23,8 @@ import static org.eclipse.che.api.workspace.shared.Constants.LAST_ACTIVITY_TIME;
import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy.COMMON_STRATEGY;
import static org.eclipse.che.workspace.infrastructure.kubernetes.provision.AsyncStorageProvisioner.ASYNC_STORAGE;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.fabric8.kubernetes.client.dsl.RollableScalableResource;
import java.time.Instant;
@ -141,7 +139,7 @@ public class AsyncStoragePodWatcher {
ofEpochSecond(lastTimeAccessSec).plusSeconds(shutdownTimeoutSec);
if (now().isAfter(expectedShutdownAfter)) {
removeAsyncStoragePodWithoutDeployment(namespace);
RollableScalableResource<Deployment, DoneableDeployment> doneableResource =
RollableScalableResource<Deployment> doneableResource =
kubernetesClientFactory
.create()
.apps()
@ -168,7 +166,7 @@ public class AsyncStoragePodWatcher {
*/
private void removeAsyncStoragePodWithoutDeployment(String namespace)
throws InfrastructureException {
PodResource<Pod, DoneablePod> doneablePodResource =
PodResource<Pod> doneablePodResource =
kubernetesClientFactory.create().pods().inNamespace(namespace).withName(ASYNC_STORAGE);
if (doneablePodResource.get() != null) {
doneablePodResource.delete();

View File

@ -31,9 +31,6 @@ import io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.ContainerPortBuilder;
import io.fabric8.kubernetes.api.model.DoneableConfigMap;
import io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.DoneableService;
import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.IntOrStringBuilder;
import io.fabric8.kubernetes.api.model.ObjectMeta;
@ -53,7 +50,6 @@ import io.fabric8.kubernetes.api.model.VolumeMount;
import io.fabric8.kubernetes.api.model.VolumeMountBuilder;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.RollableScalableResource;
@ -188,7 +184,7 @@ public class AsyncStorageProvisioner {
}
private void createPvcIfNotExist(KubernetesClient k8sClient, String namespace, String userId) {
Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim> claimResource =
Resource<PersistentVolumeClaim> claimResource =
k8sClient.persistentVolumeClaims().inNamespace(namespace).withName(pvcName);
if (claimResource.get() != null) {
@ -242,7 +238,7 @@ public class AsyncStorageProvisioner {
String userId,
KubernetesEnvironment k8sEnv)
throws InfrastructureException {
Resource<ConfigMap, DoneableConfigMap> mapResource =
Resource<ConfigMap> mapResource =
k8sClient.configMaps().inNamespace(namespace).withName(configMapName);
if (mapResource.get() != null) { // map already exist
return;
@ -273,7 +269,7 @@ public class AsyncStorageProvisioner {
private void createAsyncStoragePodIfNotExist(
KubernetesClient k8sClient, String namespace, String configMap, String userId) {
RollableScalableResource<Deployment, DoneableDeployment> resource =
RollableScalableResource<Deployment> resource =
k8sClient.apps().deployments().inNamespace(namespace).withName(ASYNC_STORAGE);
if (resource.get() != null) {
return; // deployment already exist
@ -373,7 +369,7 @@ public class AsyncStorageProvisioner {
/** Create service for serving rsync connection */
private void createStorageServiceIfNotExist(
KubernetesClient k8sClient, String namespace, String userId) {
ServiceResource<Service, DoneableService> serviceResource =
ServiceResource<Service> serviceResource =
k8sClient.services().inNamespace(namespace).withName(ASYNC_STORAGE);
if (serviceResource.get() != null) {
return; // service already exist

View File

@ -107,7 +107,7 @@ public class PreviewUrlExposer<T extends KubernetesEnvironment> {
}
private ServicePort createServicePort(int port) {
return new ServicePort("server-" + port, null, port, "TCP", new IntOrString(port));
return new ServicePort(null, "server-" + port, null, port, "TCP", new IntOrString(port));
}
protected boolean hasMatchingEndpoint(T env, Service service, int port) {

View File

@ -228,24 +228,24 @@ public class ContainerSearchTest {
.endTemplate()
.endSpec()
.build();
Template template =
new TemplateBuilder()
.addNewDeploymentObject()
.withNewMetadata()
.withName("deploymentWithName")
.endMetadata()
.withNewSpec()
.withNewTemplate()
.withNewMetadata()
.withName("podWithName")
.endMetadata()
.withNewSpec()
.withContainers(container12)
.endSpec()
.endTemplate()
.endSpec()
.endDeploymentObject()
.addToObjects(
new DeploymentBuilder()
.withNewMetadata()
.withName("deploymentWithName")
.endMetadata()
.withNewSpec()
.withNewTemplate()
.withNewMetadata()
.withName("podWithName")
.endMetadata()
.withNewSpec()
.withContainers(container12)
.endSpec()
.endTemplate()
.endSpec()
.build())
.build();
// Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,

View File

@ -11,19 +11,20 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.CREATE_IN_CHE_INSTALLATION_NAMESPACE;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.api.model.ConfigMapList;
import io.fabric8.kubernetes.api.model.DoneableConfigMap;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
@ -60,24 +61,16 @@ public class CheNamespaceTest {
@Mock private RuntimeIdentity identity;
@Mock private KubernetesClient kubeClient;
@Mock
private MixedOperation<
ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>>
kubeConfigMaps;
@Mock private MixedOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>> kubeConfigMaps;
@Mock
private MixedOperation<
ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>>
kubeConfigMapsInNamespace;
private MixedOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>> kubeConfigMapsInNamespace;
@Mock
private MixedOperation<
ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>>
kubeConfigMapsWithLabel;
private MixedOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>> kubeConfigMapsWithLabel;
@Mock
private MixedOperation<
ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>>
private MixedOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>>
kubeConfigMapsWithPropagationPolicy;
@Mock private InternalRuntime internalRuntime;
@ -244,7 +237,7 @@ public class CheNamespaceTest {
when(kubeConfigMaps.inNamespace(CHE_NAMESPACE)).thenReturn(kubeConfigMapsInNamespace);
when(kubeConfigMapsInNamespace.withLabel(CHE_WORKSPACE_ID_LABEL, WORKSPACE_ID))
.thenReturn(kubeConfigMapsWithLabel);
when(kubeConfigMapsWithLabel.withPropagationPolicy("Background"))
when(kubeConfigMapsWithLabel.withPropagationPolicy(BACKGROUND))
.thenReturn(kubeConfigMapsWithPropagationPolicy);
// when

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.client.VersionInfo.VersionKeys.BUILD_DATE_FORMAT;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
@ -21,8 +22,6 @@ import io.fabric8.kubernetes.client.VersionInfo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesClientFactory;
import org.mockito.Mock;
@ -143,33 +142,16 @@ public class K8sVersionTest {
}
private VersionInfo createDummyVersionInfo(String major, String minor) throws ParseException {
Map<String, String> versionData = new HashMap<>();
versionData.put(
VERSION_KEYS.BUILD_DATE,
new SimpleDateFormat(VERSION_KEYS.BUILD_DATE_FORMAT).format(new Date()));
versionData.put(VERSION_KEYS.GIT_COMMIT, "3f6f40d");
versionData.put(VERSION_KEYS.GIT_VERSION, "v1.17.1+3f6f40d");
versionData.put(VERSION_KEYS.GIT_TREE_STATE, "clean");
versionData.put(VERSION_KEYS.GO_VERSION, "go1.13.4");
versionData.put(VERSION_KEYS.PLATFORM, "linux/amd64");
versionData.put(VERSION_KEYS.COMPILER, "gc");
versionData.put(VERSION_KEYS.MAJOR, major);
versionData.put(VERSION_KEYS.MINOR, minor);
return new VersionInfo(versionData);
}
private final class VERSION_KEYS {
public static final String BUILD_DATE = "buildDate";
public static final String GIT_COMMIT = "gitCommit";
public static final String GIT_VERSION = "gitVersion";
public static final String MAJOR = "major";
public static final String MINOR = "minor";
public static final String GIT_TREE_STATE = "gitTreeState";
public static final String PLATFORM = "platform";
public static final String GO_VERSION = "goVersion";
public static final String COMPILER = "compiler";
public static final String BUILD_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
return new VersionInfo.Builder()
.withBuildDate(new SimpleDateFormat(BUILD_DATE_FORMAT).format(new Date()))
.withGitCommit("3f6f40d")
.withGitVersion("1.17.1+3f6f40d")
.withGitTreeState("clean")
.withGoVersion("go1.13.4")
.withPlatform("linux/amd64")
.withCompiler("gc")
.withMajor(major)
.withMinor(minor)
.build();
}
}

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.POD_STATUS_PHASE_FAILED;
@ -36,8 +37,6 @@ import static org.testng.Assert.fail;
import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.ContainerStateBuilder;
import io.fabric8.kubernetes.api.model.ContainerStatus;
import io.fabric8.kubernetes.api.model.DoneableEvent;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.EventList;
import io.fabric8.kubernetes.api.model.LabelSelector;
@ -49,7 +48,6 @@ import io.fabric8.kubernetes.api.model.PodStatus;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentList;
import io.fabric8.kubernetes.api.model.apps.DeploymentSpec;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
@ -61,6 +59,7 @@ import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.kubernetes.client.dsl.RollableScalableResource;
import io.fabric8.kubernetes.client.dsl.V1APIGroupDSL;
import java.lang.reflect.Field;
import java.util.Calendar;
import java.util.Date;
@ -98,22 +97,14 @@ public class KubernetesDeploymentsTest {
@Mock private AppsAPIGroupDSL apps;
@Mock
private MixedOperation<
Deployment,
DeploymentList,
DoneableDeployment,
RollableScalableResource<Deployment, DoneableDeployment>>
private MixedOperation<Deployment, DeploymentList, RollableScalableResource<Deployment>>
deploymentsMixedOperation;
@Mock
private NonNamespaceOperation<
Deployment,
DeploymentList,
DoneableDeployment,
RollableScalableResource<Deployment, DoneableDeployment>>
private NonNamespaceOperation<Deployment, DeploymentList, RollableScalableResource<Deployment>>
deploymentsNamespaceOperation;
@Mock private RollableScalableResource<Deployment, DoneableDeployment> deploymentResource;
@Mock private RollableScalableResource<Deployment> deploymentResource;
@Mock private Deployment deployment;
@Mock private ObjectMeta deploymentMetadata;
@Mock private DeploymentSpec deploymentSpec;
@ -121,7 +112,7 @@ public class KubernetesDeploymentsTest {
// Pod Mocks
@Mock private Pod pod;
@Mock private PodStatus status;
@Mock private PodResource<Pod, DoneablePod> podResource;
@Mock private PodResource<Pod> podResource;
@Mock private ObjectMeta metadata;
@Mock private MixedOperation podsMixedOperation;
@Mock private NonNamespaceOperation podsNamespaceOperation;
@ -133,15 +124,13 @@ public class KubernetesDeploymentsTest {
@Mock private ObjectReference objectReference;
@Mock private PodEventHandler podEventHandler;
@Mock
private MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>>
eventMixedOperation;
@Mock private MixedOperation<Event, EventList, Resource<Event>> eventMixedOperation;
@Mock
private NonNamespaceOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>>
eventNamespaceMixedOperation;
private NonNamespaceOperation<Event, EventList, Resource<Event>> eventNamespaceMixedOperation;
@Captor private ArgumentCaptor<Watcher<Event>> eventWatcherCaptor;
@Mock private V1APIGroupDSL v1APIGroupDSL;
private KubernetesDeployments kubernetesDeployments;
@ -177,7 +166,8 @@ public class KubernetesDeploymentsTest {
// Model DSL: client.events().inNamespace(...).watch(...)
// event.getInvolvedObject().getKind()
when(kubernetesClient.events()).thenReturn(eventMixedOperation);
when(kubernetesClient.v1()).thenReturn(v1APIGroupDSL);
when(v1APIGroupDSL.events()).thenReturn(eventMixedOperation);
when(eventMixedOperation.inNamespace(any())).thenReturn(eventNamespaceMixedOperation);
lenient().when(event.getInvolvedObject()).thenReturn(objectReference);
lenient().when(event.getMetadata()).thenReturn(new ObjectMeta());
@ -488,7 +478,7 @@ public class KubernetesDeploymentsTest {
doReturn(POD_NAME).when(metadata).getName();
doReturn(Boolean.FALSE).when(podResource).delete();
doReturn(podResource).when(podResource).withPropagationPolicy(eq("Background"));
doReturn(podResource).when(podResource).withPropagationPolicy(eq(BACKGROUND));
Watch watch = mock(Watch.class);
doReturn(watch).when(podResource).watch(any());
@ -503,7 +493,7 @@ public class KubernetesDeploymentsTest {
public void testDeletePodThrowingKubernetesClientExceptionShouldCloseWatch() throws Exception {
final String POD_NAME = "nonExistingPod";
doReturn(POD_NAME).when(metadata).getName();
doReturn(podResource).when(podResource).withPropagationPolicy(eq("Background"));
doReturn(podResource).when(podResource).withPropagationPolicy(eq(BACKGROUND));
doThrow(KubernetesClientException.class).when(podResource).delete();
Watch watch = mock(Watch.class);
doReturn(watch).when(podResource).watch(any());
@ -524,8 +514,8 @@ public class KubernetesDeploymentsTest {
public void testDeleteNonExistingDeploymentBeforeWatch() throws Exception {
final String DEPLOYMENT_NAME = "nonExistingPod";
doReturn(DEPLOYMENT_NAME).when(deploymentMetadata).getName();
doReturn(podResource).when(podResource).withPropagationPolicy(eq("Background"));
doReturn(deploymentResource).when(deploymentResource).withPropagationPolicy(eq("Background"));
doReturn(podResource).when(podResource).withPropagationPolicy(eq(BACKGROUND));
doReturn(deploymentResource).when(deploymentResource).withPropagationPolicy(eq(BACKGROUND));
doReturn(Boolean.FALSE).when(deploymentResource).delete();
Watch watch = mock(Watch.class);
doReturn(watch).when(podResource).watch(any());
@ -544,7 +534,7 @@ public class KubernetesDeploymentsTest {
doReturn(DEPLOYMENT_NAME).when(deploymentMetadata).getName();
doThrow(KubernetesClientException.class).when(deploymentResource).delete();
doReturn(deploymentResource).when(deploymentResource).withPropagationPolicy(eq("Background"));
doReturn(deploymentResource).when(deploymentResource).withPropagationPolicy(eq(BACKGROUND));
Watch watch = mock(Watch.class);
doReturn(watch).when(podResource).watch(any());

View File

@ -37,19 +37,17 @@ import static org.testng.Assert.assertTrue;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.Appender;
import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.DoneableNamespace;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.NamespaceList;
import io.fabric8.kubernetes.api.model.ServiceAccountList;
import io.fabric8.kubernetes.api.model.Status;
import io.fabric8.kubernetes.api.model.rbac.ClusterRoleBuilder;
import io.fabric8.kubernetes.api.model.rbac.Role;
import io.fabric8.kubernetes.api.model.rbac.RoleBindingList;
import io.fabric8.kubernetes.api.model.rbac.RoleList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
@ -118,19 +116,15 @@ public class KubernetesNamespaceFactoryTest {
@Mock Appender mockedAppender;
@Mock
private NonNamespaceOperation<
Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>>
namespaceOperation;
private NonNamespaceOperation<Namespace, NamespaceList, Resource<Namespace>> namespaceOperation;
@Mock private Resource<Namespace, DoneableNamespace> namespaceResource;
@Mock private Resource<Namespace> namespaceResource;
private KubernetesServer serverMock;
private KubernetesNamespaceFactory namespaceFactory;
@Mock
private FilterWatchListDeletable<Namespace, NamespaceList, Boolean, Watch, Watcher<Namespace>>
namespaceListResource;
@Mock private FilterWatchListDeletable<Namespace, NamespaceList> namespaceListResource;
@Mock private NamespaceList namespaceList;
@ -771,11 +765,12 @@ public class KubernetesNamespaceFactoryTest {
k8sClient
.rbac()
.clusterRoles()
.createOrReplaceWithNew()
.withNewMetadata()
.withName(cr)
.endMetadata()
.done());
.createOrReplace(
new ClusterRoleBuilder()
.withNewMetadata()
.withName(cr)
.endMetadata()
.build()));
// when
RuntimeIdentity identity =
@ -1417,7 +1412,7 @@ public class KubernetesNamespaceFactoryTest {
private void prepareNamespaceToBeFoundByName(String name, Namespace namespace) throws Exception {
@SuppressWarnings("unchecked")
Resource<Namespace, DoneableNamespace> getNamespaceByNameOperation = mock(Resource.class);
Resource<Namespace> getNamespaceByNameOperation = mock(Resource.class);
when(namespaceOperation.withName(name)).thenReturn(getNamespaceByNameOperation);
when(getNamespaceByNameOperation.get()).thenReturn(namespace);
@ -1425,7 +1420,7 @@ public class KubernetesNamespaceFactoryTest {
private void throwOnTryToGetNamespaceByName(String namespaceName, Throwable e) throws Exception {
@SuppressWarnings("unchecked")
Resource<Namespace, DoneableNamespace> getNamespaceByNameOperation = mock(Resource.class);
Resource<Namespace> getNamespaceByNameOperation = mock(Resource.class);
when(namespaceOperation.withName(namespaceName)).thenReturn(getNamespaceByNameOperation);
when(getNamespaceByNameOperation.get()).thenThrow(e);

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@ -26,11 +27,8 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import io.fabric8.kubernetes.api.model.DoneableNamespace;
import io.fabric8.kubernetes.api.model.DoneableServiceAccount;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.NamespaceFluent.MetadataNested;
import io.fabric8.kubernetes.api.model.ServiceAccount;
import io.fabric8.kubernetes.api.model.Status;
import io.fabric8.kubernetes.client.KubernetesClient;
@ -38,6 +36,7 @@ import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.Watcher.Action;
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
@ -51,6 +50,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@ -77,7 +77,7 @@ public class KubernetesNamespaceTest {
@Mock private Executor executor;
@Mock private KubernetesClient kubernetesClient;
@Mock private NonNamespaceOperation namespaceOperation;
@Mock private Resource<ServiceAccount, DoneableServiceAccount> serviceAccountResource;
@Mock private Resource<ServiceAccount> serviceAccountResource;
private KubernetesNamespace k8sNamespace;
@ -111,10 +111,6 @@ public class KubernetesNamespaceTest {
@Test
public void testKubernetesNamespacePreparingWhenNamespaceExists() throws Exception {
// given
MetadataNested namespaceMeta =
prepareCreateNamespaceRequest(
new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).endMetadata().build());
prepareNamespace(NAMESPACE);
KubernetesNamespace namespace =
new KubernetesNamespace(clientFactory, cheClientFactory, executor, NAMESPACE, WORKSPACE_ID);
@ -123,15 +119,12 @@ public class KubernetesNamespaceTest {
namespace.prepare(true, Map.of());
// then
verify(namespaceMeta, never()).withName(NAMESPACE);
verify(namespaceOperation, never()).create(any(Namespace.class));
}
@Test
public void testKubernetesNamespacePreparingCreationWhenNamespaceDoesNotExist() throws Exception {
// given
MetadataNested namespaceMeta =
prepareCreateNamespaceRequest(
new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).endMetadata().build());
Resource resource = prepareNamespaceResource(NAMESPACE);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
@ -142,7 +135,9 @@ public class KubernetesNamespaceTest {
namespace.prepare(true, Map.of());
// then
verify(namespaceMeta).withName(NAMESPACE);
ArgumentCaptor<Namespace> captor = ArgumentCaptor.forClass(Namespace.class);
verify(namespaceOperation).create(captor.capture());
Assert.assertEquals(captor.getValue().getMetadata().getName(), NAMESPACE);
}
@Test(expectedExceptions = InfrastructureException.class)
@ -196,7 +191,6 @@ public class KubernetesNamespaceTest {
@Test(expectedExceptions = InfrastructureException.class)
public void testThrowsInfrastructureExceptionWhenFailedToGetNamespaceServiceAccounts()
throws Exception {
prepareCreateNamespaceRequest();
final Resource resource = prepareNamespaceResource(NAMESPACE);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
doThrow(KubernetesClientException.class).when(kubernetesClient).serviceAccounts();
@ -208,7 +202,6 @@ public class KubernetesNamespaceTest {
@Test(expectedExceptions = InfrastructureException.class)
public void testThrowsInfrastructureExceptionWhenServiceAccountEventNotPublished()
throws Exception {
prepareCreateNamespaceRequest();
final Resource resource = prepareNamespaceResource(NAMESPACE);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
when(serviceAccountResource.get()).thenReturn(null);
@ -219,7 +212,6 @@ public class KubernetesNamespaceTest {
@Test(expectedExceptions = InfrastructureException.class)
public void testThrowsInfrastructureExceptionWhenWatcherClosed() throws Exception {
prepareCreateNamespaceRequest();
final Resource resource = prepareNamespaceResource(NAMESPACE);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
when(serviceAccountResource.get()).thenReturn(null);
@ -227,7 +219,7 @@ public class KubernetesNamespaceTest {
(Answer<Watch>)
invocation -> {
final Watcher<ServiceAccount> watcher = invocation.getArgument(0);
watcher.onClose(mock(KubernetesClientException.class));
watcher.onClose(mock(WatcherException.class));
return mock(Watch.class);
})
.when(serviceAccountResource)
@ -239,9 +231,6 @@ public class KubernetesNamespaceTest {
@Test
public void testStopsWaitingServiceAccountEventJustAfterEventReceived() throws Exception {
prepareCreateNamespaceRequest();
prepareCreateNamespaceRequest(
new NamespaceBuilder().withNewMetadata().withName(NAMESPACE).endMetadata().build());
final Resource resource = prepareNamespaceResource(NAMESPACE);
doThrow(new KubernetesClientException("error", 403, null)).when(resource).get();
@ -455,29 +444,13 @@ public class KubernetesNamespaceTest {
verify(nonNamespaceOperation).createOrReplace(namespace);
}
private MetadataNested prepareCreateNamespaceRequest() {
return prepareCreateNamespaceRequest(new NamespaceBuilder().build());
}
private MetadataNested prepareCreateNamespaceRequest(Namespace ns) {
DoneableNamespace namespace = mock(DoneableNamespace.class);
MetadataNested metadataNested = mock(MetadataNested.class);
lenient().doReturn(namespace).when(namespaceOperation).createNew();
lenient().doReturn(metadataNested).when(namespace).withNewMetadata();
lenient().doReturn(metadataNested).when(metadataNested).withName(anyString());
lenient().doReturn(namespace).when(metadataNested).endMetadata();
lenient().doReturn(ns).when(namespace).done();
return metadataNested;
}
private Resource prepareNamespaceResource(String namespaceName) {
Resource namespaceResource = mock(Resource.class);
doReturn(namespaceResource).when(namespaceOperation).withName(namespaceName);
lenient()
.doReturn(namespaceResource)
.when(namespaceResource)
.withPropagationPolicy(eq("Background"));
.withPropagationPolicy(eq(BACKGROUND));
when(namespaceResource.get())
.thenReturn(
new NamespaceBuilder().withNewMetadata().withName(namespaceName).endMetadata().build());

View File

@ -11,6 +11,7 @@
*/
package org.eclipse.che.workspace.infrastructure.kubernetes.namespace;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_WORKSPACE_ID_LABEL;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@ -19,12 +20,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import io.fabric8.kubernetes.api.model.DoneableSecret;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
@ -50,18 +49,12 @@ public class KubernetesSecretsTest {
@Mock private KubernetesClient client;
@Mock private KubernetesClientFactory clientFactory;
@Mock
private MixedOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>>
secretsMixedOperation;
@Mock private MixedOperation<Secret, SecretList, Resource<Secret>> secretsMixedOperation;
@Mock
private NonNamespaceOperation<
Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>>
nonNamespaceOperation;
@Mock private NonNamespaceOperation<Secret, SecretList, Resource<Secret>> nonNamespaceOperation;
@Mock
private FilterWatchListDeletable<Secret, SecretList, Boolean, Watch, Watcher<Secret>>
deletableList;
@Mock private FilterWatchListDeletable<Secret, SecretList> deletableList;
@Mock private EditReplacePatchDeletable<Secret> deletableSecret;
private KubernetesSecrets kubernetesSecrets;
@ -74,7 +67,7 @@ public class KubernetesSecretsTest {
when(client.secrets()).thenReturn(secretsMixedOperation);
lenient().when(secretsMixedOperation.inNamespace(any())).thenReturn(nonNamespaceOperation);
lenient().when(nonNamespaceOperation.withLabel(any(), any())).thenReturn(deletableList);
lenient().doReturn(deletableList).when(deletableList).withPropagationPolicy(eq("Background"));
lenient().doReturn(deletableSecret).when(deletableList).withPropagationPolicy(eq(BACKGROUND));
}
@Test
@ -94,6 +87,7 @@ public class KubernetesSecretsTest {
verify(secretsMixedOperation).inNamespace(NAMESPACE);
verify(nonNamespaceOperation).withLabel(CHE_WORKSPACE_ID_LABEL, WORKSPACE_ID);
verify(deletableList).delete();
verify(deletableList).withPropagationPolicy(eq(BACKGROUND));
verify(deletableSecret).delete();
}
}

View File

@ -20,11 +20,17 @@ import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.ContainerResource;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import io.fabric8.kubernetes.client.dsl.LogWatch;
import io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.PodResource;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.concurrent.CountDownLatch;
@ -51,7 +57,22 @@ public class ContainerLogWatchTest {
@Mock PodLogHandler podLogHandler;
@Mock PodOperationsImpl pods;
@Mock MixedOperation<Pod, PodList, PodResource<Pod>> pods;
@Mock PodResource<Pod> podResource;
@Mock
ContainerResource<
LogWatch,
InputStream,
PipedOutputStream,
OutputStream,
PipedInputStream,
String,
ExecWatch,
Boolean,
InputStream,
Boolean>
containerResource;
LogWatchMock logWatch;
@ -61,9 +82,9 @@ public class ContainerLogWatchTest {
when(client.pods()).thenReturn(pods);
when(pods.inNamespace(namespace)).thenReturn(pods);
when(pods.withName(podname)).thenReturn(pods);
when(pods.inContainer(container)).thenReturn(pods);
when(pods.watchLog()).thenReturn(logWatch);
when(pods.withName(podname)).thenReturn(podResource);
when(podResource.inContainer(container)).thenReturn(containerResource);
when(containerResource.watchLog()).thenReturn(logWatch);
}
@Test
@ -241,7 +262,7 @@ public class ContainerLogWatchTest {
.handle("message", container);
// return error message logwatch first and regular message logwatch on second call
when(pods.watchLog()).thenReturn(logWatch).thenReturn(logWatchRegularMessage);
when(containerResource.watchLog()).thenReturn(logWatch).thenReturn(logWatchRegularMessage);
ContainerLogWatch clw =
new ContainerLogWatch(
@ -295,7 +316,7 @@ public class ContainerLogWatchTest {
.handle("message", container);
// return null stream first and regular message stream on second call
when(pods.watchLog()).thenReturn(logWatch).thenReturn(logWatchRegularMessage);
when(containerResource.watchLog()).thenReturn(logWatch).thenReturn(logWatchRegularMessage);
ContainerLogWatch clw =
new ContainerLogWatch(

View File

@ -12,6 +12,7 @@
package org.eclipse.che.workspace.infrastructure.kubernetes.provision;
import static com.google.common.collect.ImmutableMap.of;
import static io.fabric8.kubernetes.api.model.DeletionPropagation.BACKGROUND;
import static java.util.Collections.emptyMap;
import static java.util.UUID.randomUUID;
import static org.eclipse.che.api.workspace.shared.Constants.ASYNC_PERSIST_ATTRIBUTE;
@ -24,17 +25,13 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.PodResource;
@ -60,13 +57,13 @@ public class AsyncStoragePodInterceptorTest {
@Mock private RuntimeIdentity identity;
@Mock private KubernetesClientFactory clientFactory;
@Mock private KubernetesClient kubernetesClient;
@Mock private RollableScalableResource<Deployment, DoneableDeployment> deploymentResource;
@Mock private PodResource<Pod, DoneablePod> podResource;
@Mock private RollableScalableResource<Deployment> deploymentResource;
@Mock private PodResource<Pod> podResource;
@Mock private MixedOperation mixedOperation;
@Mock private MixedOperation mixedOperationPod;
@Mock private NonNamespaceOperation namespaceOperation;
@Mock private NonNamespaceOperation namespacePodOperation;
@Mock private FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> deletable;
@Mock private EditReplacePatchDeletable<Deployment> deletable;
@Mock private AppsAPIGroupDSL apps;
private AsyncStoragePodInterceptor asyncStoragePodInterceptor;
@ -156,7 +153,7 @@ public class AsyncStoragePodInterceptorTest {
deployment.setMetadata(meta);
when(deploymentResource.get()).thenReturn(deployment);
when(deploymentResource.withPropagationPolicy("Background")).thenReturn(deletable);
when(deploymentResource.withPropagationPolicy(BACKGROUND)).thenReturn(deletable);
Watch watch = mock(Watch.class);
when(deploymentResource.watch(any())).thenReturn(watch);
@ -192,7 +189,7 @@ public class AsyncStoragePodInterceptorTest {
deployment.setMetadata(meta);
when(deploymentResource.get()).thenReturn(deployment);
when(deploymentResource.withPropagationPolicy("Background")).thenReturn(deletable);
when(deploymentResource.withPropagationPolicy(BACKGROUND)).thenReturn(deletable);
Watch watch = mock(Watch.class);
when(deploymentResource.watch(any())).thenReturn(watch);

View File

@ -25,11 +25,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
@ -67,10 +65,10 @@ public class AsyncStoragePodWatcherTest {
@Mock private PreferenceManager preferenceManager;
@Mock private WorkspaceRuntimes runtimes;
@Mock private KubernetesClient kubernetesClient;
@Mock private RollableScalableResource<Deployment, DoneableDeployment> deploymentResource;
@Mock private RollableScalableResource<Deployment> deploymentResource;
@Mock private MixedOperation mixedOperation;
@Mock private NonNamespaceOperation namespaceOperation;
@Mock private PodResource<Pod, DoneablePod> podResource;
@Mock private PodResource<Pod> podResource;
@Mock private MixedOperation mixedOperationPod;
@Mock private NonNamespaceOperation namespacePodOperation;
@Mock private UserImpl user;

View File

@ -29,16 +29,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.DoneableConfigMap;
import io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.DoneablePod;
import io.fabric8.kubernetes.api.model.DoneableService;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DoneableDeployment;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL;
@ -81,11 +76,11 @@ public class AsyncStorageProvisionerTest {
@Mock private KubernetesClientFactory clientFactory;
@Mock private KubernetesClient kubernetesClient;
@Mock private SshManager sshManager;
@Mock private Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim> pvcResource;
@Mock private Resource<ConfigMap, DoneableConfigMap> mapResource;
@Mock private PodResource<Pod, DoneablePod> podResource;
@Mock private RollableScalableResource<Deployment, DoneableDeployment> deploymentResource;
@Mock private ServiceResource<Service, DoneableService> serviceResource;
@Mock private Resource<PersistentVolumeClaim> pvcResource;
@Mock private Resource<ConfigMap> mapResource;
@Mock private PodResource<Pod> podResource;
@Mock private RollableScalableResource<Deployment> deploymentResource;
@Mock private ServiceResource<Service> serviceResource;
@Mock private MixedOperation mixedOperationPvc;
@Mock private MixedOperation mixedOperationConfigMap;
@Mock private MixedOperation mixedOperationPod;

View File

@ -125,7 +125,8 @@ public class KubernetesPreviewUrlCommandProvisionerTest {
Service service = new Service();
ServiceSpec spec = new ServiceSpec();
spec.setPorts(
Collections.singletonList(new ServicePort("a", null, port, "TCP", new IntOrString(port))));
Collections.singletonList(
new ServicePort(null, "a", null, port, "TCP", new IntOrString(port))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
@ -158,7 +159,7 @@ public class KubernetesPreviewUrlCommandProvisionerTest {
ServiceSpec spec = new ServiceSpec();
spec.setPorts(
Collections.singletonList(
new ServicePort(SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
new ServicePort(null, SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
@ -170,7 +171,8 @@ public class KubernetesPreviewUrlCommandProvisionerTest {
new HTTPIngressRuleValue(
Collections.singletonList(
new HTTPIngressPath(
new IngressBackend("servicename", new IntOrString(SERVICE_PORT_NAME)),
new IngressBackend(null, "servicename", new IntOrString(SERVICE_PORT_NAME)),
null,
null))));
ingressSpec.setRules(Collections.singletonList(rule));
ingress.setSpec(ingressSpec);

View File

@ -18,6 +18,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.LoadBalancerStatusBuilder;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServiceBuilder;
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
@ -299,15 +300,17 @@ public class IngressServerResolverTest {
new HTTPIngressRuleValue(
singletonList(
new HTTPIngressPath(
new IngressBackend(name, new IntOrString("8080")),
INGRESS_PATH_PREFIX)))))
new IngressBackend(null, name, new IntOrString("8080")),
INGRESS_PATH_PREFIX,
null)))))
.endSpec()
.withNewStatus()
.withNewLoadBalancer()
.addNewIngress()
.withIp("127.0.0.1")
.endIngress()
.endLoadBalancer()
.withLoadBalancer(
new LoadBalancerStatusBuilder()
.addNewIngress()
.withIp("127.0.0.1")
.endIngress()
.build())
.endStatus()
.build();
}

View File

@ -100,7 +100,8 @@ public class PreviewUrlExposerTest {
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(
singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
singletonList(
new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Ingress ingress = new Ingress();
@ -111,9 +112,9 @@ public class PreviewUrlExposerTest {
IngressRule ingressRule = new IngressRule();
ingressRule.setHost("ingresshost");
IngressBackend ingressBackend =
new IngressBackend("servicename", new IntOrString(SERVER_PORT_NAME));
new IngressBackend(null, "servicename", new IntOrString(SERVER_PORT_NAME));
ingressRule.setHttp(
new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null))));
new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
@ -153,7 +154,8 @@ public class PreviewUrlExposerTest {
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(
singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
singletonList(
new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Map<String, Service> services = new HashMap<>();

View File

@ -47,7 +47,7 @@ public class GatewayServerExposerTest {
private final String serviceName = "service";
private final String serverId = "server";
private final ServicePort servicePort =
new ServicePort("portName", 1, 1, "http", new IntOrString(1234));
new ServicePort(null, "portName", 1, 1, "http", new IntOrString(1234));
private final Map<String, String> s1attrs = Collections.singletonMap("s1attr", "s1val");

View File

@ -39,7 +39,7 @@ public class IngressesTest {
final int PORT = 8080;
Service service = createService(SERVER_PORT_NAME, PORT);
Ingress ingress = createIngress(new IngressBackend("servicename", new IntOrString(PORT)));
Ingress ingress = createIngress(new IngressBackend(null, "servicename", new IntOrString(PORT)));
Optional<IngressRule> foundRule =
Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
@ -54,7 +54,7 @@ public class IngressesTest {
Service service = createService(SERVER_PORT_NAME, PORT);
Ingress ingress =
createIngress(new IngressBackend("servicename", new IntOrString(SERVER_PORT_NAME)));
createIngress(new IngressBackend(null, "servicename", new IntOrString(SERVER_PORT_NAME)));
Optional<IngressRule> foundRule =
Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
@ -69,7 +69,7 @@ public class IngressesTest {
Service service = createService(SERVER_PORT_NAME, PORT);
Ingress ingress =
createIngress(new IngressBackend("servicename", new IntOrString("does not exist")));
createIngress(new IngressBackend(null, "servicename", new IntOrString("does not exist")));
Optional<IngressRule> foundRule =
Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
@ -82,7 +82,7 @@ public class IngressesTest {
final int PORT = 8080;
Service service = createService(SERVER_PORT_NAME, PORT);
Ingress ingress = createIngress(new IngressBackend("servicename", new IntOrString(666)));
Ingress ingress = createIngress(new IngressBackend(null, "servicename", new IntOrString(666)));
Optional<IngressRule> foundRule =
Ingresses.findIngressRuleForServicePort(singletonList(ingress), service, PORT);
@ -96,7 +96,8 @@ public class IngressesTest {
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(
singletonList(new ServicePort(serverPortName, null, port, "TCP", new IntOrString(port))));
singletonList(
new ServicePort(null, serverPortName, null, port, "TCP", new IntOrString(port))));
service.setSpec(serviceSpec);
return service;
}
@ -110,7 +111,7 @@ public class IngressesTest {
IngressRule ingressRule = new IngressRule();
ingressRule.setHost("ingresshost");
ingressRule.setHttp(
new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(backend, null))));
new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(backend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
return ingress;

View File

@ -44,12 +44,24 @@
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model</artifactId>
<artifactId>kubernetes-model-apps</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-extensions</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model</artifactId>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>

View File

@ -17,6 +17,7 @@ import com.google.common.annotations.VisibleForTesting;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.openshift.api.model.Project;
import io.fabric8.openshift.api.model.ProjectRequestBuilder;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.client.OpenShiftClient;
import java.util.Map;
@ -166,11 +167,12 @@ public class OpenShiftProject extends KubernetesNamespace {
try {
osClient
.projectrequests()
.createNew()
.withNewMetadata()
.withName(projectName)
.endMetadata()
.done();
.create(
new ProjectRequestBuilder()
.withNewMetadata()
.withName(projectName)
.endMetadata()
.build());
} catch (KubernetesClientException e) {
if (e.getCode() == 403) {
LOG.error(

View File

@ -12,12 +12,12 @@
package org.eclipse.che.workspace.infrastructure.openshift.project;
import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder;
import io.fabric8.openshift.api.model.OpenshiftRole;
import io.fabric8.openshift.api.model.OpenshiftRoleBinding;
import io.fabric8.openshift.api.model.OpenshiftRoleBindingBuilder;
import io.fabric8.openshift.api.model.OpenshiftRoleBindingFluent;
import io.fabric8.openshift.api.model.OpenshiftRoleBuilder;
import io.fabric8.openshift.api.model.PolicyRuleBuilder;
import io.fabric8.openshift.api.model.Role;
import io.fabric8.openshift.api.model.RoleBinding;
import io.fabric8.openshift.api.model.RoleBindingBuilder;
import io.fabric8.openshift.api.model.RoleBindingFluent;
import io.fabric8.openshift.api.model.RoleBuilder;
import io.fabric8.openshift.client.OpenShiftClient;
import java.util.List;
import java.util.Set;
@ -34,7 +34,7 @@ import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftClientFactory
* org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesWorkspaceServiceAccount
*/
class OpenShiftWorkspaceServiceAccount
extends AbstractWorkspaceServiceAccount<OpenShiftClient, OpenshiftRole, OpenshiftRoleBinding> {
extends AbstractWorkspaceServiceAccount<OpenShiftClient, Role, RoleBinding> {
OpenShiftWorkspaceServiceAccount(
String workspaceId,
@ -54,9 +54,9 @@ class OpenShiftWorkspaceServiceAccount
}
@Override
protected OpenshiftRole buildRole(
protected Role buildRole(
String name, List<String> resources, List<String> apiGroups, List<String> verbs) {
return new OpenshiftRoleBuilder()
return new RoleBuilder()
.withNewMetadata()
.withName(name)
.endMetadata()
@ -70,10 +70,10 @@ class OpenShiftWorkspaceServiceAccount
}
@Override
protected OpenshiftRoleBinding createRoleBinding(
protected RoleBinding createRoleBinding(
String roleName, String bindingName, boolean clusterRole) {
OpenshiftRoleBindingFluent.RoleRefNested<OpenshiftRoleBindingBuilder> bld =
new OpenshiftRoleBindingBuilder()
RoleBindingFluent.RoleRefNested<RoleBindingBuilder> bld =
new RoleBindingBuilder()
.withNewMetadata()
.withName(bindingName)
.withNamespace(namespace)

View File

@ -12,11 +12,11 @@
package org.eclipse.che.workspace.infrastructure.openshift.provision;
import io.fabric8.kubernetes.api.model.ObjectReferenceBuilder;
import io.fabric8.openshift.api.model.OpenshiftRole;
import io.fabric8.openshift.api.model.OpenshiftRoleBinding;
import io.fabric8.openshift.api.model.OpenshiftRoleBindingBuilder;
import io.fabric8.openshift.api.model.OpenshiftRoleBuilder;
import io.fabric8.openshift.api.model.PolicyRuleBuilder;
import io.fabric8.openshift.api.model.Role;
import io.fabric8.openshift.api.model.RoleBinding;
import io.fabric8.openshift.api.model.RoleBindingBuilder;
import io.fabric8.openshift.api.model.RoleBuilder;
import io.fabric8.openshift.client.OpenShiftClient;
import javax.inject.Inject;
import javax.inject.Named;
@ -75,8 +75,8 @@ public class OpenShiftStopWorkspaceRoleProvisioner {
}
}
protected OpenshiftRole createStopWorkspacesRole(String name) {
return new OpenshiftRoleBuilder()
protected Role createStopWorkspacesRole(String name) {
return new RoleBuilder()
.withNewMetadata()
.withName(name)
.endMetadata()
@ -104,8 +104,8 @@ public class OpenShiftStopWorkspaceRoleProvisioner {
.build();
}
protected OpenshiftRoleBinding createStopWorkspacesRoleBinding(String projectName) {
return new OpenshiftRoleBindingBuilder()
protected RoleBinding createStopWorkspacesRoleBinding(String projectName) {
return new RoleBindingBuilder()
.withNewMetadata()
.withName("che-workspace-stop")
.withNamespace(projectName)

View File

@ -37,16 +37,13 @@ import static org.testng.Assert.assertNull;
import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.Status;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.openshift.api.model.DoneableProject;
import io.fabric8.openshift.api.model.Project;
import io.fabric8.openshift.api.model.ProjectBuilder;
import io.fabric8.openshift.api.model.ProjectList;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.dsl.ProjectOperation;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -102,20 +99,15 @@ public class OpenShiftProjectFactoryTest {
@Mock private PreferenceManager preferenceManager;
@Mock private KubernetesSharedPool pool;
@Mock
private NonNamespaceOperation<
Project, ProjectList, DoneableProject, Resource<Project, DoneableProject>>
projectOperation;
@Mock private ProjectOperation projectOperation;
@Mock private Resource<Project, DoneableProject> projectResource;
@Mock private Resource<Project> projectResource;
@Mock private OpenShiftClient osClient;
private OpenShiftProjectFactory projectFactory;
@Mock
private FilterWatchListDeletable<Project, ProjectList, Boolean, Watch, Watcher<Project>>
projectListResource;
@Mock private FilterWatchListDeletable<Project, ProjectList> projectListResource;
@Mock private ProjectList projectList;
@ -856,7 +848,7 @@ public class OpenShiftProjectFactoryTest {
private void prepareNamespaceToBeFoundByName(String name, Project project) throws Exception {
@SuppressWarnings("unchecked")
Resource<Project, DoneableProject> getProjectByNameOperation = mock(Resource.class);
Resource<Project> getProjectByNameOperation = mock(Resource.class);
when(projectOperation.withName(name)).thenReturn(getProjectByNameOperation);
when(getProjectByNameOperation.get()).thenReturn(project);
@ -865,7 +857,7 @@ public class OpenShiftProjectFactoryTest {
private void throwOnTryToGetProjectByName(String name, KubernetesClientException e)
throws Exception {
@SuppressWarnings("unchecked")
Resource<Project, DoneableProject> getProjectByNameOperation = mock(Resource.class);
Resource<Project> getProjectByNameOperation = mock(Resource.class);
when(projectOperation.withName(name)).thenReturn(getProjectByNameOperation);
when(getProjectByNameOperation.get()).thenThrow(e);

View File

@ -25,7 +25,6 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import io.fabric8.kubernetes.api.model.DoneableServiceAccount;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.ServiceAccount;
@ -35,11 +34,12 @@ import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.openshift.api.model.DoneableProjectRequest;
import io.fabric8.openshift.api.model.Project;
import io.fabric8.openshift.api.model.ProjectBuilder;
import io.fabric8.openshift.api.model.ProjectRequest;
import io.fabric8.openshift.api.model.ProjectRequestFluent.MetadataNested;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.dsl.ProjectOperation;
import io.fabric8.openshift.client.dsl.ProjectRequestOperation;
import java.util.Map;
import java.util.concurrent.Executor;
@ -55,6 +55,7 @@ import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftClientFactory
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@ -82,7 +83,9 @@ public class OpenShiftProjectTest {
@Mock private Executor executor;
@Mock private OpenShiftClient openShiftClient;
@Mock private KubernetesClient kubernetesClient;
@Mock private Resource<ServiceAccount, DoneableServiceAccount> serviceAccountResource;
@Mock private Resource<ServiceAccount> serviceAccountResource;
@Mock private ProjectRequestOperation projectRequestOperation;
@Mock private MetadataNested metadataNested;
private OpenShiftProject openShiftProject;
@ -99,6 +102,8 @@ public class OpenShiftProjectTest {
lenient().when(mixedOperation.inNamespace(anyString())).thenReturn(namespaceOperation);
lenient().when(namespaceOperation.withName(anyString())).thenReturn(serviceAccountResource);
lenient().when(serviceAccountResource.get()).thenReturn(mock(ServiceAccount.class));
lenient().doReturn(projectRequestOperation).when(openShiftClient).projectrequests();
lenient().doReturn(metadataNested).when(metadataNested).withName(anyString());
openShiftProject =
new OpenShiftProject(
@ -118,7 +123,6 @@ public class OpenShiftProjectTest {
@Test
public void testOpenShiftProjectPreparingWhenProjectExists() throws Exception {
// given
MetadataNested projectMeta = prepareProjectRequest();
prepareNamespaceGet(PROJECT_NAME);
prepareProject(PROJECT_NAME);
@ -129,13 +133,12 @@ public class OpenShiftProjectTest {
project.prepare(true, Map.of());
// then
verify(projectMeta, never()).withName(PROJECT_NAME);
verify(metadataNested, never()).withName(PROJECT_NAME);
}
@Test
public void testOpenShiftProjectPreparingWhenProjectDoesNotExist() throws Exception {
// given
MetadataNested projectMetadata = prepareProjectRequest();
prepareNamespaceGet(PROJECT_NAME);
Resource resource = prepareProjectResource(PROJECT_NAME);
@ -147,7 +150,9 @@ public class OpenShiftProjectTest {
openShiftProject.prepare(true, Map.of());
// then
verify(projectMetadata).withName(PROJECT_NAME);
ArgumentCaptor<ProjectRequest> captor = ArgumentCaptor.forClass(ProjectRequest.class);
verify(projectRequestOperation).create(captor.capture());
Assert.assertEquals(captor.getValue().getMetadata().getName(), PROJECT_NAME);
}
@Test(expectedExceptions = InfrastructureException.class)
@ -365,23 +370,10 @@ public class OpenShiftProjectTest {
verify(nonNamespaceOperation).createOrReplace(namespace);
}
private MetadataNested prepareProjectRequest() {
ProjectRequestOperation projectRequestOperation = mock(ProjectRequestOperation.class);
DoneableProjectRequest projectRequest = mock(DoneableProjectRequest.class);
MetadataNested metadataNested = mock(MetadataNested.class);
lenient().doReturn(projectRequestOperation).when(openShiftClient).projectrequests();
lenient().doReturn(projectRequest).when(projectRequestOperation).createNew();
lenient().doReturn(metadataNested).when(projectRequest).withNewMetadata();
lenient().doReturn(metadataNested).when(metadataNested).withName(anyString());
lenient().doReturn(projectRequest).when(metadataNested).endMetadata();
return metadataNested;
}
private Resource prepareProjectResource(String projectName) {
Resource projectResource = mock(Resource.class);
NonNamespaceOperation projectOperation = mock(NonNamespaceOperation.class);
ProjectOperation projectOperation = mock(ProjectOperation.class);
doReturn(projectResource).when(projectOperation).withName(projectName);
doReturn(projectOperation).when(openShiftClient).projects();

View File

@ -131,7 +131,8 @@ public class OpenShiftPreviewUrlCommandProvisionerTest {
Service service = new Service();
ServiceSpec spec = new ServiceSpec();
spec.setPorts(
Collections.singletonList(new ServicePort("a", null, port, "TCP", new IntOrString(port))));
Collections.singletonList(
new ServicePort(null, "a", null, port, "TCP", new IntOrString(port))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
@ -163,7 +164,7 @@ public class OpenShiftPreviewUrlCommandProvisionerTest {
ServiceSpec spec = new ServiceSpec();
spec.setPorts(
Collections.singletonList(
new ServicePort("8080", null, port, "TCP", new IntOrString(port))));
new ServicePort(null, "8080", null, port, "TCP", new IntOrString(port))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));

View File

@ -25,15 +25,13 @@ import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.openshift.api.model.DoneableOpenshiftRole;
import io.fabric8.openshift.api.model.DoneableOpenshiftRoleBinding;
import io.fabric8.openshift.api.model.OpenshiftRole;
import io.fabric8.openshift.api.model.OpenshiftRoleBinding;
import io.fabric8.openshift.api.model.OpenshiftRoleBindingBuilder;
import io.fabric8.openshift.api.model.OpenshiftRoleBindingList;
import io.fabric8.openshift.api.model.OpenshiftRoleBuilder;
import io.fabric8.openshift.api.model.OpenshiftRoleList;
import io.fabric8.openshift.api.model.PolicyRuleBuilder;
import io.fabric8.openshift.api.model.Role;
import io.fabric8.openshift.api.model.RoleBinding;
import io.fabric8.openshift.api.model.RoleBindingBuilder;
import io.fabric8.openshift.api.model.RoleBindingList;
import io.fabric8.openshift.api.model.RoleBuilder;
import io.fabric8.openshift.api.model.RoleList;
import io.fabric8.openshift.client.OpenShiftClient;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.CheInstallationLocation;
@ -59,45 +57,25 @@ public class OpenShiftStopWorkspaceRoleProvisionerTest {
@Mock private OpenShiftClient osClient;
@Mock private KubernetesClient kubernetesClient;
@Mock
private MixedOperation<
OpenshiftRole,
OpenshiftRoleList,
DoneableOpenshiftRole,
Resource<OpenshiftRole, DoneableOpenshiftRole>>
mixedRoleOperation;
@Mock private MixedOperation<Role, RoleList, Resource<Role>> mixedRoleOperation;
@Mock
private MixedOperation<
OpenshiftRoleBinding,
OpenshiftRoleBindingList,
DoneableOpenshiftRoleBinding,
Resource<OpenshiftRoleBinding, DoneableOpenshiftRoleBinding>>
private MixedOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>>
mixedRoleBindingOperation;
@Mock
private NonNamespaceOperation<
OpenshiftRole,
OpenshiftRoleList,
DoneableOpenshiftRole,
Resource<OpenshiftRole, DoneableOpenshiftRole>>
nonNamespaceRoleOperation;
@Mock private NonNamespaceOperation<Role, RoleList, Resource<Role>> nonNamespaceRoleOperation;
@Mock
private NonNamespaceOperation<
OpenshiftRoleBinding,
OpenshiftRoleBindingList,
DoneableOpenshiftRoleBinding,
Resource<OpenshiftRoleBinding, DoneableOpenshiftRoleBinding>>
private NonNamespaceOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>>
nonNamespaceRoleBindingOperation;
@Mock private Resource<OpenshiftRole, DoneableOpenshiftRole> roleResource;
@Mock private Resource<OpenshiftRoleBinding, DoneableOpenshiftRoleBinding> roleBindingResource;
@Mock private OpenshiftRole mockRole;
@Mock private OpenshiftRoleBinding mockRoleBinding;
@Mock private Resource<Role> roleResource;
@Mock private Resource<RoleBinding> roleBindingResource;
@Mock private Role mockRole;
@Mock private RoleBinding mockRoleBinding;
private final OpenshiftRole expectedRole =
new OpenshiftRoleBuilder()
private final Role expectedRole =
new RoleBuilder()
.withNewMetadata()
.withName("workspace-stop")
.endMetadata()
@ -124,8 +102,8 @@ public class OpenShiftStopWorkspaceRoleProvisionerTest {
.build())
.build();
private final OpenshiftRoleBinding expectedRoleBinding =
new OpenshiftRoleBindingBuilder()
private final RoleBinding expectedRoleBinding =
new RoleBindingBuilder()
.withNewMetadata()
.withName("che-workspace-stop")
.withNamespace("developer-che")

View File

@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapList;
import io.fabric8.kubernetes.api.model.ContainerBuilder;
import io.fabric8.kubernetes.api.model.DoneableConfigMap;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.Pod;
@ -72,16 +71,13 @@ public class OpenshiftTrustedCAProvisionerTest {
@Mock private CheInstallationLocation cheInstallationLocation;
@Mock
private MixedOperation<
ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>>
cheServerConfigMapGetter1;
private MixedOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>> cheServerConfigMapGetter1;
@Mock
private NonNamespaceOperation<
ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>>
private NonNamespaceOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>>
cheServerConfigMapGetter2;
@Mock private Resource<ConfigMap, DoneableConfigMap> cheServerConfigMapResource;
@Mock private Resource<ConfigMap> cheServerConfigMapResource;
@Mock private ConfigMap cheServerConfigMap;
@Mock private ObjectMeta cheServerConfigMapMetadata;

View File

@ -50,7 +50,7 @@ public class OpenShiftExternalServerExposerTest {
"machine123",
"service123",
null,
new ServicePort("servicePort", null, null, "TCP", null),
new ServicePort(null, "servicePort", null, null, "TCP", null),
servers);
// then
@ -82,7 +82,7 @@ public class OpenShiftExternalServerExposerTest {
"machine123",
"service123",
null,
new ServicePort("servicePort", null, null, "TCP", null),
new ServicePort(null, "servicePort", null, null, "TCP", null),
servers);
// then

View File

@ -86,7 +86,8 @@ public class OpenShiftPreviewUrlExposerTest {
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(
singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
singletonList(
new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Route route = new Route();
@ -127,7 +128,8 @@ public class OpenShiftPreviewUrlExposerTest {
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(
singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
singletonList(
new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Map<String, Service> services = new HashMap<>();

View File

@ -100,7 +100,7 @@ public class RoutesTest {
service.setMetadata(metadata);
ServiceSpec spec = new ServiceSpec();
spec.setPorts(
Collections.singletonList(new ServicePort(portString, null, portInt, "TCP", null)));
Collections.singletonList(new ServicePort(null, portString, null, portInt, "TCP", null)));
service.setSpec(spec);
return service;
}

73
pom.xml
View File

@ -48,8 +48,7 @@
<aopalliance.version>1.0</aopalliance.version>
<ch.qos.logback.version>1.2.1</ch.qos.logback.version>
<com.auth0.jwks-rsa.version>0.3.0</com.auth0.jwks-rsa.version>
<com.fasterxml.jackson.core.jackson-databind.version>2.10.5.1</com.fasterxml.jackson.core.jackson-databind.version>
<com.fasterxml.jackson.core.version>2.10.3</com.fasterxml.jackson.core.version>
<com.fasterxml.jackson.version>2.11.2</com.fasterxml.jackson.version>
<com.github.kirviq.dumbster.version>1.7.1</com.github.kirviq.dumbster.version>
<com.github.tomakehurst.wiremock-jre8-standalone.version>2.27.2</com.github.tomakehurst.wiremock-jre8-standalone.version>
<com.google.code.guice.version>4.2.2</com.google.code.guice.version>
@ -60,7 +59,7 @@
<com.h2database.version>1.4.196</com.h2database.version>
<com.jayway.restassured.version>2.6.0</com.jayway.restassured.version>
<com.jcraft.jsch.version>0.1.54</com.jcraft.jsch.version>
<com.squareup.okhttp3.version>3.12.6</com.squareup.okhttp3.version>
<com.squareup.okhttp3.version>3.12.12</com.squareup.okhttp3.version>
<com.squareup.okio.version>1.15.0</com.squareup.okio.version>
<commons-codec.version>1.11</commons-codec.version>
<commons-compress.version>1.19</commons-compress.version>
@ -69,7 +68,7 @@
<commons-lang.version>2.6</commons-lang.version>
<integration.mysql.db.image>quay.io/eclipse/che--centos--mysql-57-centos7:latest-e08ee4d43b7356607685b69bde6335e27cf20c020f345b6c6c59400183882764</integration.mysql.db.image>
<integration.postgresql.db.image>quay.io/eclipse/che--centos--postgresql-96-centos7:9.6-b681d78125361519180a6ac05242c296f8906c11eab7e207b5ca9a89b6344392</integration.postgresql.db.image>
<io.fabric8.kubernetes-client>4.9.0</io.fabric8.kubernetes-client>
<io.fabric8.kubernetes-client>5.3.1</io.fabric8.kubernetes-client>
<io.github.mweirauch.micrometer-jvm-extras.version>0.1.3</io.github.mweirauch.micrometer-jvm-extras.version>
<io.jaegertracing.micrometer.version>1.0.0</io.jaegertracing.micrometer.version>
<io.jaegertracing.version>1.0.0</io.jaegertracing.version>
@ -143,26 +142,6 @@
<artifactId>jwks-rsa</artifactId>
<version>${com.auth0.jwks-rsa.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${com.fasterxml.jackson.core.jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>${com.fasterxml.jackson.core.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
@ -290,38 +269,6 @@
<artifactId>commons-lang</artifactId>
<version>${commons-lang.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${io.fabric8.kubernetes-client}</version>
<exclusions>
<exclusion>
<artifactId>generex</artifactId>
<groupId>com.github.mifmif</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model</artifactId>
<version>${io.fabric8.kubernetes-client}</version>
<exclusions>
<exclusion>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<version>${io.fabric8.kubernetes-client}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>${io.fabric8.kubernetes-client}</version>
</dependency>
<dependency>
<groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId>
@ -1390,6 +1337,20 @@
<artifactId>testng</artifactId>
<version>${org.testng.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${com.fasterxml.jackson.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${io.fabric8.kubernetes-client}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.github.kirviq</groupId>
<artifactId>dumbster</artifactId>