use of io.fabric8.kubernetes.client.KubernetesClient in project strimzi by strimzi.
the class MockKube method build.
public KubernetesClient build() {
KubernetesClient mockClient = mock(KubernetesClient.class);
MixedOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> mockCms = buildConfigMaps();
MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> mockPvcs = buildPvcs();
MixedOperation<Endpoints, EndpointsList, DoneableEndpoints, Resource<Endpoints, DoneableEndpoints>> mockEndpoints = buildEndpoints();
MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> mockSvc = buildServices();
MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods = buildPods();
MixedOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> mockSs = buildStatefulSets(mockPods);
MixedOperation<Deployment, DeploymentList, DoneableDeployment, ScalableResource<Deployment, DoneableDeployment>> mockDep = buildDeployments();
when(mockClient.configMaps()).thenReturn(mockCms);
when(mockClient.services()).thenReturn(mockSvc);
AppsAPIGroupDSL api = mock(AppsAPIGroupDSL.class);
when(api.statefulSets()).thenReturn(mockSs);
when(mockClient.apps()).thenReturn(api);
ExtensionsAPIGroupDSL ext = mock(ExtensionsAPIGroupDSL.class);
when(mockClient.extensions()).thenReturn(ext);
when(ext.deployments()).thenReturn(mockDep);
when(mockClient.pods()).thenReturn(mockPods);
when(mockClient.endpoints()).thenReturn(mockEndpoints);
when(mockClient.persistentVolumeClaims()).thenReturn(mockPvcs);
return mockClient;
}
use of io.fabric8.kubernetes.client.KubernetesClient in project strimzi by strimzi.
the class DeploymentOperatorTest method mocker.
@Override
protected void mocker(KubernetesClient mockClient, MixedOperation op) {
ExtensionsAPIGroupDSL mockExt = mock(ExtensionsAPIGroupDSL.class);
when(mockExt.deployments()).thenReturn(op);
when(mockClient.extensions()).thenReturn(mockExt);
}
use of io.fabric8.kubernetes.client.KubernetesClient in project vertx-openshift-it by cescoffier.
the class Deployment method deployIfNeeded.
public static String deployIfNeeded(KubernetesClient client, String name, String path) {
if (oc(client).deploymentConfigs().withName(name).get() != null) {
System.out.println("Skipping the creation of dc/" + name);
return name;
}
ImageStream stream = findImageStream(client, name);
ensureThat("the image stream " + name + " exists in the namespace " + client.getNamespace(), () -> assertThat(stream).isNotNull());
File file = filter(Objects.requireNonNull(path), ImmutableMap.of("image", stream.getStatus().getDockerImageRepository()));
String name2 = deployIfNeeded(client, file);
assertThat(name).isEqualTo(name2);
return name;
}
use of io.fabric8.kubernetes.client.KubernetesClient in project vertx-openshift-it by cescoffier.
the class Kube method createServiceIfNeeded.
public static Service createServiceIfNeeded(KubernetesClient client, String name, String type) {
Objects.requireNonNull(name);
Service service = client.services().withName(name).get();
if (service != null) {
return service;
}
Map<String, String> labels = new HashMap<>();
if (type != null) {
labels.put("service-type", type);
}
labels.put("name", name);
return client.services().createNew().withNewMetadata().withName(name).withLabels(labels).endMetadata().withNewSpec().addNewPort().withProtocol("TCP").withPort(80).withNewTargetPort(8080).endPort().addToSelector("name", name).withType("ClusterIP").withSessionAffinity("None").endSpec().done();
}
use of io.fabric8.kubernetes.client.KubernetesClient in project vertx-openshift-it by cescoffier.
the class Kube method createRouteForService.
public static Route createRouteForService(KubernetesClient client, String svc, boolean deleteIfExist) {
OpenShiftClient oc = oc(client);
Route existing = oc.routes().withName(svc).get();
if (existing != null && deleteIfExist) {
oc.routes().withName(name(existing)).delete();
}
if (existing != null && !deleteIfExist) {
return existing;
}
return oc.routes().createNew().withNewMetadata().withName(svc).endMetadata().withNewSpec().withNewTo().withName(svc).withKind("Service").endTo().endSpec().done();
}
Aggregations