Search in sources :

Example 1 with ClusterRoleOperator

use of io.strimzi.operator.common.operator.resource.ClusterRoleOperator in project strimzi by strimzi.

the class Main method maybeCreateClusterRoles.

/*test*/
static Future<Void> maybeCreateClusterRoles(Vertx vertx, ClusterOperatorConfig config, KubernetesClient client) {
    if (config.isCreateClusterRoles()) {
        @SuppressWarnings({ "rawtypes" }) List<Future> futures = new ArrayList<>();
        ClusterRoleOperator cro = new ClusterRoleOperator(vertx, client);
        Map<String, String> clusterRoles = new HashMap<>(6);
        clusterRoles.put("strimzi-cluster-operator-namespaced", "020-ClusterRole-strimzi-cluster-operator-role.yaml");
        clusterRoles.put("strimzi-cluster-operator-global", "021-ClusterRole-strimzi-cluster-operator-role.yaml");
        clusterRoles.put("strimzi-kafka-broker", "030-ClusterRole-strimzi-kafka-broker.yaml");
        clusterRoles.put("strimzi-entity-operator", "031-ClusterRole-strimzi-entity-operator.yaml");
        clusterRoles.put("strimzi-kafka-client", "033-ClusterRole-strimzi-kafka-client.yaml");
        for (Map.Entry<String, String> clusterRole : clusterRoles.entrySet()) {
            LOGGER.info("Creating cluster role {}", clusterRole.getKey());
            try (BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream("/cluster-roles/" + clusterRole.getValue()), StandardCharsets.UTF_8))) {
                String yaml = br.lines().collect(Collectors.joining(System.lineSeparator()));
                ClusterRole role = ClusterRoleOperator.convertYamlToClusterRole(yaml);
                @SuppressWarnings({ "rawtypes" }) Future fut = cro.reconcile(new Reconciliation("start-cluster-operator", "Deployment", config.getOperatorNamespace(), "cluster-operator"), role.getMetadata().getName(), role);
                futures.add(fut);
            } catch (IOException e) {
                LOGGER.error("Failed to create Cluster Roles.", e);
                throw new RuntimeException(e);
            }
        }
        Promise<Void> returnPromise = Promise.promise();
        CompositeFuture.all(futures).onComplete(res -> {
            if (res.succeeded()) {
                returnPromise.complete();
            } else {
                returnPromise.fail("Failed to create Cluster Roles.");
            }
        });
        return returnPromise.future();
    } else {
        return Future.succeededFuture();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ClusterRoleOperator(io.strimzi.operator.common.operator.resource.ClusterRoleOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) BufferedReader(java.io.BufferedReader) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ClusterRoleOperator

use of io.strimzi.operator.common.operator.resource.ClusterRoleOperator in project strimzi by strimzi.

the class MainIT method testCreateClusterRolesCreatesClusterRoles.

@Test
public void testCreateClusterRolesCreatesClusterRoles(VertxTestContext context) {
    assertDoesNotThrow(() -> KubeCluster.bootstrap());
    Map<String, String> envVars = new HashMap<>(6);
    envVars.put(ClusterOperatorConfig.STRIMZI_CREATE_CLUSTER_ROLES, "TRUE");
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMakerImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString());
    ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(envVars, KafkaVersionTestUtils.getKafkaVersionLookup());
    ClusterRoleOperator cro = new ClusterRoleOperator(vertx, client);
    Checkpoint a = context.checkpoint();
    Main.maybeCreateClusterRoles(vertx, config, client).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(cro.get("strimzi-cluster-operator-namespaced"), is(notNullValue()));
        assertThat(cro.get("strimzi-cluster-operator-global"), is(notNullValue()));
        assertThat(cro.get("strimzi-kafka-broker"), is(notNullValue()));
        assertThat(cro.get("strimzi-entity-operator"), is(notNullValue()));
        a.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) KubeCluster(io.strimzi.test.k8s.cluster.KubeCluster) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) VertxExtension(io.vertx.junit5.VertxExtension) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) ClusterRoleOperator(io.strimzi.operator.common.operator.resource.ClusterRoleOperator) Checkpoint(io.vertx.junit5.Checkpoint) HashMap(java.util.HashMap) ClusterRoleOperator(io.strimzi.operator.common.operator.resource.ClusterRoleOperator) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterRoleOperator

use of io.strimzi.operator.common.operator.resource.ClusterRoleOperator in project strimzi-kafka-operator by strimzi.

the class Main method maybeCreateClusterRoles.

/*test*/
static Future<Void> maybeCreateClusterRoles(Vertx vertx, ClusterOperatorConfig config, KubernetesClient client) {
    if (config.isCreateClusterRoles()) {
        @SuppressWarnings({ "rawtypes" }) List<Future> futures = new ArrayList<>();
        ClusterRoleOperator cro = new ClusterRoleOperator(vertx, client);
        Map<String, String> clusterRoles = new HashMap<>(6);
        clusterRoles.put("strimzi-cluster-operator-namespaced", "020-ClusterRole-strimzi-cluster-operator-role.yaml");
        clusterRoles.put("strimzi-cluster-operator-global", "021-ClusterRole-strimzi-cluster-operator-role.yaml");
        clusterRoles.put("strimzi-kafka-broker", "030-ClusterRole-strimzi-kafka-broker.yaml");
        clusterRoles.put("strimzi-entity-operator", "031-ClusterRole-strimzi-entity-operator.yaml");
        clusterRoles.put("strimzi-kafka-client", "033-ClusterRole-strimzi-kafka-client.yaml");
        for (Map.Entry<String, String> clusterRole : clusterRoles.entrySet()) {
            LOGGER.info("Creating cluster role {}", clusterRole.getKey());
            try (BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream("/cluster-roles/" + clusterRole.getValue()), StandardCharsets.UTF_8))) {
                String yaml = br.lines().collect(Collectors.joining(System.lineSeparator()));
                ClusterRole role = ClusterRoleOperator.convertYamlToClusterRole(yaml);
                @SuppressWarnings({ "rawtypes" }) Future fut = cro.reconcile(new Reconciliation("start-cluster-operator", "Deployment", config.getOperatorNamespace(), "cluster-operator"), role.getMetadata().getName(), role);
                futures.add(fut);
            } catch (IOException e) {
                LOGGER.error("Failed to create Cluster Roles.", e);
                throw new RuntimeException(e);
            }
        }
        Promise<Void> returnPromise = Promise.promise();
        CompositeFuture.all(futures).onComplete(res -> {
            if (res.succeeded()) {
                returnPromise.complete();
            } else {
                returnPromise.fail("Failed to create Cluster Roles.");
            }
        });
        return returnPromise.future();
    } else {
        return Future.succeededFuture();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClusterRole(io.fabric8.kubernetes.api.model.rbac.ClusterRole) ClusterRoleOperator(io.strimzi.operator.common.operator.resource.ClusterRoleOperator) Reconciliation(io.strimzi.operator.common.Reconciliation) BufferedReader(java.io.BufferedReader) CompositeFuture(io.vertx.core.CompositeFuture) Future(io.vertx.core.Future) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ClusterRoleOperator

use of io.strimzi.operator.common.operator.resource.ClusterRoleOperator in project strimzi-kafka-operator by strimzi.

the class MainIT method testCreateClusterRolesCreatesClusterRoles.

@Test
public void testCreateClusterRolesCreatesClusterRoles(VertxTestContext context) {
    assertDoesNotThrow(() -> KubeCluster.bootstrap());
    Map<String, String> envVars = new HashMap<>(6);
    envVars.put(ClusterOperatorConfig.STRIMZI_CREATE_CLUSTER_ROLES, "TRUE");
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_IMAGES, KafkaVersionTestUtils.getKafkaImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_CONNECT_IMAGES, KafkaVersionTestUtils.getKafkaConnectImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMakerImagesEnvVarString());
    envVars.put(ClusterOperatorConfig.STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES, KafkaVersionTestUtils.getKafkaMirrorMaker2ImagesEnvVarString());
    ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(envVars, KafkaVersionTestUtils.getKafkaVersionLookup());
    ClusterRoleOperator cro = new ClusterRoleOperator(vertx, client);
    Checkpoint a = context.checkpoint();
    Main.maybeCreateClusterRoles(vertx, config, client).onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(cro.get("strimzi-cluster-operator-namespaced"), is(notNullValue()));
        assertThat(cro.get("strimzi-cluster-operator-global"), is(notNullValue()));
        assertThat(cro.get("strimzi-kafka-broker"), is(notNullValue()));
        assertThat(cro.get("strimzi-entity-operator"), is(notNullValue()));
        a.flag();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) KubeCluster(io.strimzi.test.k8s.cluster.KubeCluster) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) VertxExtension(io.vertx.junit5.VertxExtension) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Checkpoint(io.vertx.junit5.Checkpoint) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) ClusterRoleOperator(io.strimzi.operator.common.operator.resource.ClusterRoleOperator) Checkpoint(io.vertx.junit5.Checkpoint) HashMap(java.util.HashMap) ClusterRoleOperator(io.strimzi.operator.common.operator.resource.ClusterRoleOperator) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterRoleOperator (io.strimzi.operator.common.operator.resource.ClusterRoleOperator)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ClusterRole (io.fabric8.kubernetes.api.model.rbac.ClusterRole)2 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 KubeCluster (io.strimzi.test.k8s.cluster.KubeCluster)2 CompositeFuture (io.vertx.core.CompositeFuture)2 Future (io.vertx.core.Future)2 Vertx (io.vertx.core.Vertx)2 Checkpoint (io.vertx.junit5.Checkpoint)2 VertxExtension (io.vertx.junit5.VertxExtension)2 VertxTestContext (io.vertx.junit5.VertxTestContext)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)2