Search in sources :

Example 96 with Service

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();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) ImageStream(io.fabric8.openshift.api.model.ImageStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) KafkaConnectS2ICluster(io.strimzi.controller.cluster.model.KafkaConnectS2ICluster) BuildConfigOperator(io.strimzi.controller.cluster.operator.resource.BuildConfigOperator) ImageStreamOperator(io.strimzi.controller.cluster.operator.resource.ImageStreamOperator) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test)

Example 97 with Service

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;
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 98 with 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;
}
Also used : PvcOperator(io.strimzi.controller.cluster.operator.resource.PvcOperator) TopicController.topicControllerName(io.strimzi.controller.cluster.model.TopicController.topicControllerName) KafkaSetOperator(io.strimzi.controller.cluster.operator.resource.KafkaSetOperator) ZookeeperCluster(io.strimzi.controller.cluster.model.ZookeeperCluster) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ZookeeperSetOperator(io.strimzi.controller.cluster.operator.resource.ZookeeperSetOperator) LoggerFactory(org.slf4j.LoggerFactory) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) Storage(io.strimzi.controller.cluster.model.Storage) Labels(io.strimzi.controller.cluster.model.Labels) ArrayList(java.util.ArrayList) CompositeFuture(io.vertx.core.CompositeFuture) Reconciliation(io.strimzi.controller.cluster.Reconciliation) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) KafkaCluster(io.strimzi.controller.cluster.model.KafkaCluster) Service(io.fabric8.kubernetes.api.model.Service) AsyncResult(io.vertx.core.AsyncResult) AssemblyType(io.strimzi.controller.cluster.model.AssemblyType) Logger(org.slf4j.Logger) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Vertx(io.vertx.core.Vertx) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) TopicController(io.strimzi.controller.cluster.model.TopicController) ReconcileResult(io.strimzi.controller.cluster.operator.resource.ReconcileResult) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) List(java.util.List) Handler(io.vertx.core.Handler) KafkaCluster(io.strimzi.controller.cluster.model.KafkaCluster) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ReconcileResult(io.strimzi.controller.cluster.operator.resource.ReconcileResult) Service(io.fabric8.kubernetes.api.model.Service) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Example 99 with Service

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);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) Test(org.junit.Test)

Example 100 with Service

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());
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) Test(org.junit.Test)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)100 Test (org.junit.Test)78 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)33 File (java.io.File)28 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)26 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)24 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)22 Map (java.util.Map)19 Pod (io.fabric8.kubernetes.api.model.Pod)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)17 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)17 List (java.util.List)17 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 Reconciliation (io.strimzi.controller.cluster.Reconciliation)15 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)15 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)15