use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class KafkaConnectS2ICluster method generateBuildConfig.
/**
* Generate new BuildConfig
*
* @return BuildConfig resource definition
*/
public BuildConfig generateBuildConfig() {
BuildTriggerPolicy triggerConfigChange = new BuildTriggerPolicy();
triggerConfigChange.setType("ConfigChange");
BuildTriggerPolicy triggerImageChange = new BuildTriggerPolicy();
triggerImageChange.setType("ImageChange");
triggerImageChange.setImageChange(new ImageChangeTrigger());
BuildConfig build = new BuildConfigBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).endMetadata().withNewSpec().withFailedBuildsHistoryLimit(5).withNewOutput().withNewTo().withKind("ImageStreamTag").withName(image).endTo().endOutput().withRunPolicy("Serial").withNewSource().withType("Binary").withBinary(new BinaryBuildSource()).endSource().withNewStrategy().withType("Source").withNewSourceStrategy().withNewFrom().withKind("ImageStreamTag").withName(getSourceImageStreamName() + ":" + sourceImageTag).endFrom().endSourceStrategy().endStrategy().withTriggers(triggerConfigChange, triggerImageChange).endSpec().build();
return build;
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class AbstractAssemblyOperator method reconcileAssembly.
/**
* Reconcile assembly resources in the given namespace having the given {@code assemblyName}.
* Reconciliation works by getting the assembly ConfigMap in the given namespace with the given assemblyName and
* comparing with the corresponding {@linkplain #getResources(String) resource}.
* <ul>
* <li>An assembly will be {@linkplain #createOrUpdate(Reconciliation, ConfigMap, Handler) created or updated} if ConfigMap is without same-named resources</li>
* <li>An assembly will be {@linkplain #delete(Reconciliation, Handler) deleted} if resources without same-named ConfigMap</li>
* </ul>
*/
public final void reconcileAssembly(Reconciliation reconciliation, Handler<AsyncResult<Void>> handler) {
String namespace = reconciliation.namespace();
String assemblyName = reconciliation.assemblyName();
final String lockName = getLockName(assemblyType, namespace, assemblyName);
vertx.sharedData().getLockWithTimeout(lockName, LOCK_TIMEOUT, res -> {
if (res.succeeded()) {
log.debug("{}: Lock {} acquired", reconciliation, lockName);
Lock lock = res.result();
try {
// get ConfigMap and related resources for the specific cluster
ConfigMap cm = configMapOperations.get(namespace, assemblyName);
if (cm != null) {
log.info("{}: assembly {} should be created or updated", reconciliation, assemblyName);
createOrUpdate(reconciliation, cm, createResult -> {
lock.release();
log.debug("{}: Lock {} released", reconciliation, lockName);
handler.handle(createResult);
});
} else {
log.info("{}: assembly {} should be deleted", reconciliation, assemblyName);
delete(reconciliation, deleteResult -> {
lock.release();
log.debug("{}: Lock {} released", reconciliation, lockName);
handler.handle(deleteResult);
});
}
} catch (Throwable ex) {
lock.release();
log.debug("{}: Lock {} released", reconciliation, lockName);
handler.handle(Future.failedFuture(ex));
}
} else {
log.warn("{}: Failed to acquire lock {}.", reconciliation, lockName);
}
});
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class KafkaAssemblyOperator method createOrUpdateKafka.
private final Future<Void> createOrUpdateKafka(Reconciliation reconciliation, ConfigMap assemblyCm) {
String namespace = assemblyCm.getMetadata().getNamespace();
String name = assemblyCm.getMetadata().getName();
log.info("{}: create/update kafka {}", reconciliation, name);
KafkaCluster kafka = KafkaCluster.fromConfigMap(assemblyCm);
Service service = kafka.generateService();
Service headlessService = kafka.generateHeadlessService();
ConfigMap metricsConfigMap = kafka.generateMetricsConfigMap();
StatefulSet statefulSet = kafka.generateStatefulSet(isOpenShift);
Future<Void> chainFuture = Future.future();
kafkaSetOperations.scaleDown(namespace, kafka.getName(), kafka.getReplicas()).compose(scale -> serviceOperations.reconcile(namespace, kafka.getName(), service)).compose(i -> serviceOperations.reconcile(namespace, kafka.getHeadlessName(), headlessService)).compose(i -> configMapOperations.reconcile(namespace, kafka.getMetricsConfigName(), metricsConfigMap)).compose(i -> kafkaSetOperations.reconcile(namespace, kafka.getName(), statefulSet)).compose(diffs -> {
if (diffs instanceof ReconcileResult.Patched && ((ReconcileResult.Patched<Boolean>) diffs).differences()) {
return kafkaSetOperations.rollingUpdate(namespace, kafka.getName());
} else {
return Future.succeededFuture();
}
}).compose(i -> kafkaSetOperations.scaleUp(namespace, kafka.getName(), kafka.getReplicas())).compose(scale -> serviceOperations.endpointReadiness(namespace, service, 1_000, operationTimeoutMs)).compose(i -> serviceOperations.endpointReadiness(namespace, headlessService, 1_000, operationTimeoutMs)).compose(chainFuture::complete, chainFuture);
return chainFuture;
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class KafkaAssemblyOperator method deleteZk.
private final Future<CompositeFuture> deleteZk(Reconciliation reconciliation) {
String namespace = reconciliation.namespace();
String name = reconciliation.assemblyName();
log.info("{}: delete zookeeper {}", reconciliation, name);
StatefulSet ss = zkSetOperations.get(namespace, ZookeeperCluster.zookeeperClusterName(name));
ZookeeperCluster zk = ss == null ? null : ZookeeperCluster.fromAssembly(ss, namespace, name);
boolean deleteClaims = zk != null && zk.getStorage().type() == Storage.StorageType.PERSISTENT_CLAIM && zk.getStorage().isDeleteClaim();
List<Future> result = new ArrayList<>(4 + (deleteClaims ? zk.getReplicas() : 0));
result.add(configMapOperations.reconcile(namespace, ZookeeperCluster.zookeeperMetricsName(name), null));
result.add(serviceOperations.reconcile(namespace, ZookeeperCluster.zookeeperClusterName(name), null));
result.add(serviceOperations.reconcile(namespace, ZookeeperCluster.zookeeperHeadlessName(name), null));
result.add(zkSetOperations.reconcile(namespace, ZookeeperCluster.zookeeperClusterName(name), null));
if (deleteClaims) {
for (int i = 0; i < zk.getReplicas(); i++) {
result.add(pvcOperations.reconcile(namespace, zk.getPersistentVolumeClaimName(i), null));
}
}
return CompositeFuture.join(result);
}
use of io.fabric8.kubernetes.api.model.Namespace in project strimzi by strimzi.
the class KafkaAssemblyOperator method createOrUpdateTopicController.
private final Future<ReconcileResult<Void>> createOrUpdateTopicController(Reconciliation reconciliation, ConfigMap assemblyCm) {
String namespace = assemblyCm.getMetadata().getNamespace();
String name = assemblyCm.getMetadata().getName();
log.info("{}: create/update topic controller {}", reconciliation, name);
TopicController topicController = TopicController.fromConfigMap(assemblyCm);
Deployment deployment = topicController != null ? topicController.generateDeployment() : null;
return deploymentOperations.reconcile(namespace, topicControllerName(name), deployment);
}
Aggregations