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();
}
}
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();
})));
}
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();
}
}
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();
})));
}
Aggregations