Search in sources :

Example 66 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class KafkaConnectS2IAssemblyOperatorTest method testUpdateClusterNoDiff.

@Test
public void testUpdateClusterNoDiff(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);
    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.succeededFuture());
    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.assertTrue(createResult.succeeded());
        // Vertify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        context.assertEquals(1, capturedServices.size());
        // Verify Deployment Config
        List<DeploymentConfig> capturedDc = dcCaptor.getAllValues();
        context.assertEquals(1, capturedDc.size());
        // Verify Build Config
        List<BuildConfig> capturedBc = bcCaptor.getAllValues();
        context.assertEquals(1, capturedBc.size());
        // Verify Image Streams
        List<ImageStream> capturedIs = isCaptor.getAllValues();
        context.assertEquals(2, capturedIs.size());
        // Verify scaleDown / scaleUp were not called
        context.assertEquals(1, dcScaleDownNameCaptor.getAllValues().size());
        context.assertEquals(1, dcScaleUpNameCaptor.getAllValues().size());
        async.complete();
    });
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) KafkaConnectS2ICluster(io.strimzi.controller.cluster.model.KafkaConnectS2ICluster) BuildConfigOperator(io.strimzi.controller.cluster.operator.resource.BuildConfigOperator) ImageStreamOperator(io.strimzi.controller.cluster.operator.resource.ImageStreamOperator) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test)

Example 67 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class KafkaConnectS2IAssemblyOperatorTest method testUpdateClusterScaleDown.

@Test
public void testUpdateClusterScaleDown(TestContext context) {
    int scaleTo = 2;
    String newReplicas = String.valueOf(scaleTo);
    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 replicas to create ScaleDown
    clusterCm.getData().put(KafkaConnectCluster.KEY_REPLICAS, newReplicas);
    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());
    when(mockServiceOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
    when(mockDcOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
    doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleUp(clusterCmNamespace, connect.getName(), 2);
    doAnswer(i -> Future.succeededFuture(scaleTo)).when(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
    when(mockIsOps.reconcile(any(), any(), any())).thenReturn(Future.succeededFuture());
    when(mockBcOps.reconcile(any(), any(), any())).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.assertTrue(createResult.succeeded());
        // Verify ScaleDown
        verify(mockDcOps).scaleDown(clusterCmNamespace, connect.getName(), scaleTo);
        async.complete();
    });
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Test(org.junit.Test)

Example 68 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class KafkaConnectS2IAssemblyOperatorTest method testCreateCluster.

@Test
public void testCreateCluster(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);
    when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
    when(mockServiceOps.reconcile(anyString(), anyString(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<DeploymentConfig> dcCaptor = ArgumentCaptor.forClass(DeploymentConfig.class);
    when(mockDcOps.reconcile(anyString(), anyString(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
    when(mockDcOps.scaleDown(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(42));
    when(mockDcOps.scaleUp(anyString(), anyString(), anyInt())).thenReturn(Future.succeededFuture(42));
    ArgumentCaptor<ImageStream> isCaptor = ArgumentCaptor.forClass(ImageStream.class);
    when(mockIsOps.reconcile(anyString(), anyString(), isCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<BuildConfig> bcCaptor = ArgumentCaptor.forClass(BuildConfig.class);
    when(mockBcOps.reconcile(anyString(), anyString(), bcCaptor.capture())).thenReturn(Future.succeededFuture());
    KafkaConnectS2IAssemblyOperator ops = new KafkaConnectS2IAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps, mockIsOps, mockBcOps);
    KafkaConnectS2ICluster connect = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT_S2I, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
        context.assertTrue(createResult.succeeded());
        // Vertify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        context.assertEquals(1, capturedServices.size());
        Service service = capturedServices.get(0);
        context.assertEquals(connect.getName(), service.getMetadata().getName());
        context.assertEquals(connect.generateService(), service, "Services are not equal");
        // Verify Deployment Config
        List<DeploymentConfig> capturedDc = dcCaptor.getAllValues();
        context.assertEquals(1, capturedDc.size());
        DeploymentConfig dc = capturedDc.get(0);
        context.assertEquals(connect.getName(), dc.getMetadata().getName());
        context.assertEquals(connect.generateDeploymentConfig(), dc, "Deployment Configs are not equal");
        // Verify Build Config
        List<BuildConfig> capturedBc = bcCaptor.getAllValues();
        context.assertEquals(1, capturedBc.size());
        BuildConfig bc = capturedBc.get(0);
        context.assertEquals(connect.getName(), dc.getMetadata().getName());
        context.assertEquals(connect.generateBuildConfig(), bc, "Build Configs are not equal");
        // Verify Image Streams
        List<ImageStream> capturedIs = isCaptor.getAllValues();
        context.assertEquals(2, capturedIs.size());
        int sisIndex = (connect.getSourceImageStreamName()).equals(capturedIs.get(0).getMetadata().getName()) ? 0 : 1;
        int tisIndex = (connect.getName()).equals(capturedIs.get(0).getMetadata().getName()) ? 0 : 1;
        ImageStream sis = capturedIs.get(sisIndex);
        context.assertEquals(connect.getSourceImageStreamName(), sis.getMetadata().getName());
        context.assertEquals(connect.generateSourceImageStream(), sis, "Source Image Streams are not equal");
        ImageStream tis = capturedIs.get(tisIndex);
        context.assertEquals(connect.getName(), tis.getMetadata().getName());
        context.assertEquals(connect.generateTargetImageStream(), tis, "Target Image Streams are not equal");
        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 69 with Context

use of io.fabric8.kubernetes.api.model.Context in project strimzi by strimzi.

the class KafkaConnectS2IAssemblyOperatorTest method testUpdateCluster.

@Test
public void testUpdateCluster(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.succeededFuture());
    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.assertTrue(createResult.succeeded());
        KafkaConnectS2ICluster compareTo = KafkaConnectS2ICluster.fromConfigMap(clusterCm);
        // Vertify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        context.assertEquals(1, capturedServices.size());
        Service service = capturedServices.get(0);
        context.assertEquals(compareTo.getName(), service.getMetadata().getName());
        context.assertEquals(compareTo.generateService(), service, "Services are not equal");
        // Verify Deployment Config
        List<DeploymentConfig> capturedDc = dcCaptor.getAllValues();
        context.assertEquals(1, capturedDc.size());
        DeploymentConfig dc = capturedDc.get(0);
        context.assertEquals(compareTo.getName(), dc.getMetadata().getName());
        context.assertEquals(compareTo.generateDeploymentConfig(), dc, "Deployment Configs are not equal");
        // Verify Build Config
        List<BuildConfig> capturedBc = bcCaptor.getAllValues();
        context.assertEquals(1, capturedBc.size());
        BuildConfig bc = capturedBc.get(0);
        context.assertEquals(compareTo.getName(), dc.getMetadata().getName());
        context.assertEquals(compareTo.generateBuildConfig(), bc, "Build Configs are not equal");
        // Verify Image Streams
        List<ImageStream> capturedIs = isCaptor.getAllValues();
        context.assertEquals(2, capturedIs.size());
        int sisIndex = (compareTo.getSourceImageStreamName()).equals(capturedIs.get(0).getMetadata().getName()) ? 0 : 1;
        int tisIndex = (compareTo.getName()).equals(capturedIs.get(0).getMetadata().getName()) ? 0 : 1;
        ImageStream sis = capturedIs.get(sisIndex);
        context.assertEquals(compareTo.getSourceImageStreamName(), sis.getMetadata().getName());
        context.assertEquals(compareTo.generateSourceImageStream(), sis, "Source Image Streams are not equal");
        ImageStream tis = capturedIs.get(tisIndex);
        context.assertEquals(compareTo.getName(), tis.getMetadata().getName());
        context.assertEquals(compareTo.generateTargetImageStream(), tis, "Target Image Streams are not equal");
        async.complete();
    });
}
Also used : ImageStream(io.fabric8.openshift.api.model.ImageStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.controller.cluster.operator.resource.ServiceOperator) Async(io.vertx.ext.unit.Async) Reconciliation(io.strimzi.controller.cluster.Reconciliation) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Service(io.fabric8.kubernetes.api.model.Service) KafkaConnectS2ICluster(io.strimzi.controller.cluster.model.KafkaConnectS2ICluster) BuildConfigOperator(io.strimzi.controller.cluster.operator.resource.BuildConfigOperator) ImageStreamOperator(io.strimzi.controller.cluster.operator.resource.ImageStreamOperator) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) DeploymentConfigOperator(io.strimzi.controller.cluster.operator.resource.DeploymentConfigOperator) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test)

Example 70 with Context

use of io.fabric8.kubernetes.api.model.Context 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)

Aggregations

Test (org.junit.Test)135 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)58 Async (io.vertx.ext.unit.Async)52 Expectations (mockit.Expectations)34 Probe (io.fabric8.kubernetes.api.model.Probe)33 Reconciliation (io.strimzi.controller.cluster.Reconciliation)24 File (java.io.File)23 Git (org.eclipse.jgit.api.Git)23 GitContext (io.fabric8.api.GitContext)21 IOException (java.io.IOException)21 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)20 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 HashMap (java.util.HashMap)17 LockHandle (io.fabric8.api.LockHandle)15 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)15 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (io.fabric8.kubernetes.client.dsl.Resource)14