use of io.fabric8.patch.Service in project strimzi by strimzi.
the class KafkaConnectS2IAssemblyOperatorTest method testUpdateClusterFailure.
@Test
public void testUpdateClusterFailure(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentConfigOperator mockDcOps = mock(DeploymentConfigOperator.class);
BuildConfigOperator mockBcOps = mock(BuildConfigOperator.class);
ImageStreamOperator mockIsOps = mock(ImageStreamOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
// Change the image to generate some diff
clusterCm.getData().put("image", "some/different:image");
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeploymentConfig());
when(mockIsOps.get(clusterCmNamespace, connect.getSourceImageStreamName())).thenReturn(connect.generateSourceImageStream());
when(mockIsOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateTargetImageStream());
when(mockBcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateBuildConfig());
ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<DeploymentConfig> dcCaptor = ArgumentCaptor.forClass(DeploymentConfig.class);
when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.failedFuture("Failed"));
ArgumentCaptor<String> dcScaleUpNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(dcScaleUpNamespaceCaptor.capture(), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(dcScaleDownNamespaceCaptor.capture(), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> isNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> isNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ImageStream> isCaptor = ArgumentCaptor.forClass(ImageStream.class);
when(mockIsOps.reconcile(isNamespaceCaptor.capture(), isNameCaptor.capture(), isCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> bcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> bcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<BuildConfig> bcCaptor = ArgumentCaptor.forClass(BuildConfig.class);
when(mockBcOps.reconcile(bcNamespaceCaptor.capture(), bcNameCaptor.capture(), bcCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertFalse(createResult.succeeded());
async.complete();
});
}
use of io.fabric8.patch.Service in project strimzi by strimzi.
the class AbstractModel method createHeadlessService.
protected Service createHeadlessService(String name, List<ServicePort> ports, Map<String, String> annotations) {
Service service = new ServiceBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName(name)).withNamespace(namespace).withAnnotations(annotations).endMetadata().withNewSpec().withType("ClusterIP").withClusterIP("None").withSelector(getLabelsWithName()).withPorts(ports).endSpec().build();
log.trace("Created headless service {}", service);
return service;
}
use of io.fabric8.patch.Service in project strimzi by strimzi.
the class KafkaAssemblyOperator method createOrUpdateKafka.
private final Future<Void> createOrUpdateKafka(Reconciliation reconciliation, ConfigMap assemblyCm) {
String namespace = assemblyCm.getMetadata().getNamespace();
String name = assemblyCm.getMetadata().getName();
log.info("{}: create/update kafka {}", reconciliation, name);
KafkaCluster kafka = KafkaCluster.fromConfigMap(assemblyCm);
Service service = kafka.generateService();
Service headlessService = kafka.generateHeadlessService();
ConfigMap metricsConfigMap = kafka.generateMetricsConfigMap();
StatefulSet statefulSet = kafka.generateStatefulSet(isOpenShift);
Future<Void> chainFuture = Future.future();
kafkaSetOperations.scaleDown(namespace, kafka.getName(), kafka.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, kafka.getName(), service)).compose(i -> serviceOperations.reconcile(namespace, kafka.getHeadlessName(), headlessService)).compose(i -> configMapOperations.reconcile(namespace, kafka.getMetricsConfigName(), metricsConfigMap)).compose(i -> kafkaSetOperations.reconcile(namespace, kafka.getName(), statefulSet)).compose(diffs -> {
if (diffs instanceof ReconcileResult.Patched && ((ReconcileResult.Patched<Boolean>) diffs).differences()) {
return kafkaSetOperations.rollingUpdate(namespace, kafka.getName());
} else {
return Future.succeededFuture();
}
}).compose(i -> kafkaSetOperations.scaleUp(namespace, kafka.getName(), kafka.getReplicas())).compose(scale -> serviceOperations.endpointReadiness(namespace, service, 1_000, operationTimeoutMs)).compose(i -> serviceOperations.endpointReadiness(namespace, headlessService, 1_000, operationTimeoutMs)).compose(chainFuture::complete, chainFuture);
return chainFuture;
}
use of io.fabric8.patch.Service in project strimzi by strimzi.
the class KafkaClusterTest method testGenerateService.
@Test
public void testGenerateService() {
Service headful = kc.generateService();
checkService(headful);
}
use of io.fabric8.patch.Service in project strimzi by strimzi.
the class KafkaConnectS2IClusterTest method testGenerateService.
@Test
public void testGenerateService() {
Service svc = kc.generateService();
assertEquals("ClusterIP", svc.getSpec().getType());
Map<String, String> expectedLabels = ResourceUtils.labels("my-user-label", "cromulent", Labels.STRIMZI_CLUSTER_LABEL, cluster, Labels.STRIMZI_TYPE_LABEL, "kafka-connect-s2i", Labels.STRIMZI_NAME_LABEL, kc.kafkaConnectClusterName(cluster));
assertEquals(expectedLabels, svc.getMetadata().getLabels());
assertEquals(expectedLabels, svc.getSpec().getSelector());
assertEquals(1, svc.getSpec().getPorts().size());
assertEquals(new Integer(KafkaConnectCluster.REST_API_PORT), svc.getSpec().getPorts().get(0).getPort());
assertEquals(KafkaConnectCluster.REST_API_PORT_NAME, svc.getSpec().getPorts().get(0).getName());
assertEquals("TCP", svc.getSpec().getPorts().get(0).getProtocol());
}
Aggregations