Search in sources :

Example 81 with Image

use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.

the class KafkaConnectAssemblyOperatorTest method testUpdateClusterFailure.

@Test
public void testUpdateClusterFailure(TestContext context) {
    ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
    ServiceOperator mockServiceOps = mock(ServiceOperator.class);
    DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
    String clusterCmName = "foo";
    String clusterCmNamespace = "test";
    ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
    KafkaConnectCluster connect = KafkaConnectCluster.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.generateDeployment());
    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<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.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());
    KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
    Async async = context.async();
    ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, 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) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) KafkaConnectCluster(io.strimzi.controller.cluster.model.KafkaConnectCluster) 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) ConfigMapOperator(io.strimzi.controller.cluster.operator.resource.ConfigMapOperator) DeploymentOperator(io.strimzi.controller.cluster.operator.resource.DeploymentOperator) Test(org.junit.Test)

Example 82 with Image

use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.

the class ResourceUtils method createKafkaConnectS2IClusterConfigMap.

/**
 * Generate ConfigMap for Kafka Connect S2I cluster
 */
public static ConfigMap createKafkaConnectS2IClusterConfigMap(String clusterCmNamespace, String clusterCmName, int replicas, String image, int healthDelay, int healthTimeout, String bootstrapServers, String groupID, int configReplicationFactor, int offsetReplicationFactor, int statusReplicationFactor, String keyConverter, String valueConverter, boolean keyConverterSchemas, boolean valuesConverterSchema) {
    Map<String, String> cmData = new HashMap<>();
    cmData.put(KafkaConnectS2ICluster.KEY_IMAGE, image);
    cmData.put(KafkaConnectS2ICluster.KEY_REPLICAS, Integer.toString(replicas));
    cmData.put(KafkaConnectS2ICluster.KEY_HEALTHCHECK_DELAY, Integer.toString(healthDelay));
    cmData.put(KafkaConnectS2ICluster.KEY_HEALTHCHECK_TIMEOUT, Integer.toString(healthTimeout));
    cmData.put(KafkaConnectS2ICluster.KEY_BOOTSTRAP_SERVERS, bootstrapServers);
    cmData.put(KafkaConnectS2ICluster.KEY_GROUP_ID, groupID);
    cmData.put(KafkaConnectS2ICluster.KEY_CONFIG_STORAGE_REPLICATION_FACTOR, Integer.toString(configReplicationFactor));
    cmData.put(KafkaConnectS2ICluster.KEY_OFFSET_STORAGE_REPLICATION_FACTOR, Integer.toString(offsetReplicationFactor));
    cmData.put(KafkaConnectS2ICluster.KEY_STATUS_STORAGE_REPLICATION_FACTOR, Integer.toString(statusReplicationFactor));
    cmData.put(KafkaConnectS2ICluster.KEY_KEY_CONVERTER, keyConverter);
    cmData.put(KafkaConnectS2ICluster.KEY_KEY_CONVERTER_SCHEMAS_EXAMPLE, Boolean.toString(keyConverterSchemas));
    cmData.put(KafkaConnectS2ICluster.KEY_VALUE_CONVERTER, valueConverter);
    cmData.put(KafkaConnectS2ICluster.KEY_VALUE_CONVERTER_SCHEMAS_EXAMPLE, Boolean.toString(valuesConverterSchema));
    ConfigMap cm = createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
    cm.setData(cmData);
    return cm;
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap)

Example 83 with Image

use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.

the class ResourceUtils method createKafkaClusterConfigMap.

public static ConfigMap createKafkaClusterConfigMap(String clusterCmNamespace, String clusterCmName, int replicas, String image, int healthDelay, int healthTimeout, String metricsCmJson, String storage, String topicController) {
    Map<String, String> cmData = new HashMap<>();
    cmData.put(KafkaCluster.KEY_REPLICAS, Integer.toString(replicas));
    cmData.put(KafkaCluster.KEY_IMAGE, image);
    cmData.put(KafkaCluster.KEY_HEALTHCHECK_DELAY, Integer.toString(healthDelay));
    cmData.put(KafkaCluster.KEY_HEALTHCHECK_TIMEOUT, Integer.toString(healthTimeout));
    cmData.put(KafkaCluster.KEY_STORAGE, storage);
    cmData.put(KafkaCluster.KEY_METRICS_CONFIG, metricsCmJson);
    cmData.put(ZookeeperCluster.KEY_REPLICAS, Integer.toString(replicas));
    cmData.put(ZookeeperCluster.KEY_IMAGE, image + "-zk");
    cmData.put(ZookeeperCluster.KEY_HEALTHCHECK_DELAY, Integer.toString(healthDelay));
    cmData.put(ZookeeperCluster.KEY_HEALTHCHECK_TIMEOUT, Integer.toString(healthTimeout));
    cmData.put(ZookeeperCluster.KEY_STORAGE, storage);
    cmData.put(ZookeeperCluster.KEY_METRICS_CONFIG, metricsCmJson);
    if (topicController != null) {
        cmData.put(TopicController.KEY_CONFIG, topicController);
    }
    return new ConfigMapBuilder().withNewMetadata().withName(clusterCmName).withNamespace(clusterCmNamespace).withLabels(Labels.userLabels(singletonMap("my-user-label", "cromulent")).withKind("cluster").withType(AssemblyType.KAFKA).toMap()).endMetadata().withData(cmData).build();
}
Also used : HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 84 with Image

use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.

the class TopicControllerTest method testFromConfigMapDefaultConfig.

@Test
public void testFromConfigMapDefaultConfig() {
    ConfigMap cm = ResourceUtils.createKafkaClusterConfigMap(namespace, cluster, replicas, image, healthDelay, healthTimeout, metricsCmJson, storageJson, "{ }");
    TopicController tc = TopicController.fromConfigMap(cm);
    assertEquals(TopicController.DEFAULT_IMAGE, tc.getImage());
    assertEquals(namespace, tc.getWatchedNamespace());
    assertEquals(TopicController.DEFAULT_FULL_RECONCILIATION_INTERVAL_MS, tc.getReconciliationIntervalMs());
    assertEquals(TopicController.DEFAULT_ZOOKEEPER_SESSION_TIMEOUT_MS, tc.getZookeeperSessionTimeoutMs());
    assertEquals(TopicController.defaultBootstrapServers(cluster), tc.getKafkaBootstrapServers());
    assertEquals(TopicController.defaultZookeeperConnect(cluster), tc.getZookeeperConnect());
    assertEquals(TopicController.defaultTopicConfigMapLabels(cluster), tc.getTopicConfigMapLabels());
    assertEquals(TopicController.DEFAULT_TOPIC_METADATA_MAX_ATTEMPTS, tc.getTopicMetadataMaxAttempts());
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 85 with Image

use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.

the class TopicControllerTest method testFromConfigMapNoConfig.

@Test
public void testFromConfigMapNoConfig() {
    ConfigMap cm = ResourceUtils.createKafkaClusterConfigMap(namespace, cluster, replicas, image, healthDelay, healthTimeout, metricsCmJson);
    TopicController tc = TopicController.fromConfigMap(cm);
    assertNull(tc);
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)35 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)28 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)20 IOException (java.io.IOException)16 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 File (java.io.File)13 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)12 ImageStream (io.fabric8.openshift.api.model.ImageStream)10 Arguments (io.fabric8.maven.docker.config.Arguments)8 Service (io.fabric8.kubernetes.api.model.Service)7 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)7 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)6 BuildService (io.fabric8.maven.core.service.BuildService)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 HashMap (java.util.HashMap)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)5 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)5 ImageName (io.fabric8.maven.docker.util.ImageName)5 ImageStreamTag (io.fabric8.openshift.api.model.ImageStreamTag)5