use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class VolumeResizingTest method testVolumesResizing.
@Test
public void testVolumesResizing() {
Kafka kafka = getKafkaCrd();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the PVC Operator
PvcOperator mockPvcOps = supplier.pvcOperations;
List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage());
for (PersistentVolumeClaim pvc : realPvcs) {
pvc.setStatus(new PersistentVolumeClaimStatusBuilder().withPhase("Bound").withConditions(new PersistentVolumeClaimConditionBuilder().withStatus("True").withType("Resizing").build()).withCapacity(singletonMap("storage", new Quantity("10Gi"))).build());
}
when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))).thenAnswer(invocation -> {
String pvcName = invocation.getArgument(1);
return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null));
});
ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class);
when(mockPvcOps.reconcile(any(), anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture());
// Mock the StorageClass Operator
StorageClassOperator mockSco = supplier.storageClassOperations;
when(mockSco.getAsync(eq("mysc"))).thenAnswer(invocation -> {
StorageClass sc = new StorageClassBuilder().withNewMetadata().withName("mysc").endMetadata().withAllowVolumeExpansion(true).build();
return Future.succeededFuture(sc);
});
MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> {
assertThat(res.succeeded(), is(true));
// The volumes are resizing => no reconciliation
assertThat(pvcCaptor.getAllValues().size(), is(0));
});
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class KafkaCluster method generateJmxSecret.
/**
* Generate the Secret containing the username and password to secure the jmx port on the kafka brokers
*
* @return The generated Secret
*/
public Secret generateJmxSecret() {
Map<String, String> data = new HashMap<>(2);
String[] keys = { SECRET_JMX_USERNAME_KEY, SECRET_JMX_PASSWORD_KEY };
PasswordGenerator passwordGenerator = new PasswordGenerator(16);
for (String key : keys) {
data.put(key, Base64.getEncoder().encodeToString(passwordGenerator.generate().getBytes(StandardCharsets.US_ASCII)));
}
return createJmxSecret(KafkaCluster.jmxSecretName(cluster), data);
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class KafkaCluster method generateJmxSecret.
/**
* Generate the Secret containing the username and password to secure the jmx port on the Kafka brokers.
*
* @param currentSecret The existing Secret with the current JMX credentials. Null if no secret exists yet.
*
* @return The generated Secret
*/
public Secret generateJmxSecret(Secret currentSecret) {
if (isJmxAuthenticated) {
PasswordGenerator passwordGenerator = new PasswordGenerator(16);
Map<String, String> data = new HashMap<>(2);
if (currentSecret != null && currentSecret.getData() != null) {
data.put(SECRET_JMX_USERNAME_KEY, currentSecret.getData().computeIfAbsent(SECRET_JMX_USERNAME_KEY, (key) -> Util.encodeToBase64(passwordGenerator.generate())));
data.put(SECRET_JMX_PASSWORD_KEY, currentSecret.getData().computeIfAbsent(SECRET_JMX_PASSWORD_KEY, (key) -> Util.encodeToBase64(passwordGenerator.generate())));
} else {
data.put(SECRET_JMX_USERNAME_KEY, Util.encodeToBase64(passwordGenerator.generate()));
data.put(SECRET_JMX_PASSWORD_KEY, Util.encodeToBase64(passwordGenerator.generate()));
}
return createJmxSecret(KafkaResources.kafkaJmxSecretName(cluster), data);
} else {
return null;
}
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class Main method run.
static CompositeFuture run(Vertx vertx, KubernetesClient client, PlatformFeaturesAvailability pfa, ClusterOperatorConfig config) {
Util.printEnvInfo();
ResourceOperatorSupplier resourceOperatorSupplier = new ResourceOperatorSupplier(vertx, client, pfa, config.getOperationTimeoutMs());
KafkaAssemblyOperator kafkaClusterOperations = null;
KafkaConnectAssemblyOperator kafkaConnectClusterOperations = null;
KafkaMirrorMaker2AssemblyOperator kafkaMirrorMaker2AssemblyOperator = null;
KafkaMirrorMakerAssemblyOperator kafkaMirrorMakerAssemblyOperator = null;
KafkaBridgeAssemblyOperator kafkaBridgeAssemblyOperator = null;
KafkaRebalanceAssemblyOperator kafkaRebalanceAssemblyOperator = null;
if (!config.isPodSetReconciliationOnly()) {
OpenSslCertManager certManager = new OpenSslCertManager();
PasswordGenerator passwordGenerator = new PasswordGenerator(12, "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789");
kafkaClusterOperations = new KafkaAssemblyOperator(vertx, pfa, certManager, passwordGenerator, resourceOperatorSupplier, config);
kafkaConnectClusterOperations = new KafkaConnectAssemblyOperator(vertx, pfa, resourceOperatorSupplier, config);
kafkaMirrorMaker2AssemblyOperator = new KafkaMirrorMaker2AssemblyOperator(vertx, pfa, resourceOperatorSupplier, config);
kafkaMirrorMakerAssemblyOperator = new KafkaMirrorMakerAssemblyOperator(vertx, pfa, certManager, passwordGenerator, resourceOperatorSupplier, config);
kafkaBridgeAssemblyOperator = new KafkaBridgeAssemblyOperator(vertx, pfa, certManager, passwordGenerator, resourceOperatorSupplier, config);
kafkaRebalanceAssemblyOperator = new KafkaRebalanceAssemblyOperator(vertx, resourceOperatorSupplier, config);
}
@SuppressWarnings({ "rawtypes" }) List<Future> futures = new ArrayList<>(config.getNamespaces().size());
for (String namespace : config.getNamespaces()) {
Promise<String> prom = Promise.promise();
futures.add(prom.future());
ClusterOperator operator = new ClusterOperator(namespace, config, client, kafkaClusterOperations, kafkaConnectClusterOperations, kafkaMirrorMakerAssemblyOperator, kafkaMirrorMaker2AssemblyOperator, kafkaBridgeAssemblyOperator, kafkaRebalanceAssemblyOperator, resourceOperatorSupplier);
vertx.deployVerticle(operator, res -> {
if (res.succeeded()) {
if (config.getCustomResourceSelector() != null) {
LOGGER.info("Cluster Operator verticle started in namespace {} with label selector {}", namespace, config.getCustomResourceSelector());
} else {
LOGGER.info("Cluster Operator verticle started in namespace {} without label selector", namespace);
}
} else {
LOGGER.error("Cluster Operator verticle in namespace {} failed to start", namespace, res.cause());
System.exit(1);
}
prom.handle(res);
});
}
return CompositeFuture.join(futures);
}
use of io.strimzi.operator.common.PasswordGenerator in project strimzi by strimzi.
the class KafkaConnectCluster method generateJmxSecret.
/**
* Generate the Secret containing the username and password to secure the jmx port on the kafka connect workers
*
* @return The generated Secret
*/
public Secret generateJmxSecret() {
Map<String, String> data = new HashMap<>(2);
String[] keys = { SECRET_JMX_USERNAME_KEY, SECRET_JMX_PASSWORD_KEY };
PasswordGenerator passwordGenerator = new PasswordGenerator(16);
for (String key : keys) {
data.put(key, Base64.getEncoder().encodeToString(passwordGenerator.generate().getBytes(StandardCharsets.US_ASCII)));
}
return createJmxSecret(KafkaConnectCluster.jmxSecretName(cluster), data);
}
Aggregations