use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziOperatorManager method doInstall.
protected CompletableFuture<Void> doInstall(KubeClient kubeClient) throws IOException {
LOGGER.info("Installing Strimzi : {} version: {}", operatorNs, version);
Namespace namespace = new NamespaceBuilder().withNewMetadata().withName(operatorNs).endMetadata().build();
kubeClient.client().namespaces().createOrReplace(namespace);
URL url = new URL(String.format(STRIMZI_URL_FORMAT, version));
// modify namespaces, convert rolebinding to clusterrolebindings, update deployment if needed
String crbID = UUID.randomUUID().toString().substring(0, 5);
kubeClient.apply(operatorNs, url.openStream(), i -> {
if (i instanceof Namespaced) {
i.getMetadata().setNamespace(operatorNs);
}
if (i instanceof ClusterRoleBinding) {
ClusterRoleBinding crb = (ClusterRoleBinding) i;
crb.getSubjects().forEach(sbj -> sbj.setNamespace(operatorNs));
crb.getMetadata().setName(crb.getMetadata().getName() + "." + operatorNs);
clusterWideResourceDeleters.add(unused -> {
kubeClient.client().rbac().clusterRoleBindings().withName(crb.getMetadata().getName()).delete();
});
} else if (i instanceof RoleBinding) {
RoleBinding rb = (RoleBinding) i;
rb.getSubjects().forEach(sbj -> sbj.setNamespace(operatorNs));
ClusterRoleBinding crb = new ClusterRoleBindingBuilder().withNewMetadata().withName(rb.getMetadata().getName() + "-all-ns-" + crbID).withAnnotations(rb.getMetadata().getAnnotations()).withLabels(rb.getMetadata().getLabels()).endMetadata().withRoleRef(rb.getRoleRef()).withSubjects(rb.getSubjects()).build();
LOGGER.info("Creating {} named {}", crb.getKind(), crb.getMetadata().getName());
kubeClient.client().rbac().clusterRoleBindings().createOrReplace(crb);
clusterWideResourceDeleters.add(unused -> {
kubeClient.client().rbac().clusterRoleBindings().withName(crb.getMetadata().getName()).delete();
});
} else if (i instanceof Deployment && "strimzi-cluster-operator".equals(i.getMetadata().getName())) {
modifyDeployment((Deployment) i);
}
return i;
});
LOGGER.info("Done installing Strimzi : {}", operatorNs);
return TestUtils.asyncWaitFor("Strimzi operator ready", 1_000, FleetShardOperatorManager.INSTALL_TIMEOUT_MS, () -> isReady(kubeClient, operatorNs, version));
}
use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class UpgradeST method testUpgradeStrimziVersion.
@SequentialTest
void testUpgradeStrimziVersion(ExtensionContext extensionContext) throws Exception {
String mkAppName = "mk-test-upgrade";
LOGGER.info("Create namespace");
resourceManager.createResource(extensionContext, new NamespaceBuilder().withNewMetadata().withName(mkAppName).endMetadata().build());
String startVersion = SyncApiClient.getPreviousStrimziVersion(syncEndpoint);
String kafkaVersion = SyncApiClient.getLatestKafkaVersion(syncEndpoint, startVersion);
LOGGER.info("Create managedkafka with version {}", startVersion);
ManagedKafka mk = ManagedKafkaResourceType.getDefault(mkAppName, mkAppName, keycloak, startVersion, kafkaVersion);
mk = resourceManager.createResource(extensionContext, mk);
AssertUtils.assertManagedKafka(mk);
LOGGER.info("Upgrade to {}", latestStrimziVersion);
mk = ManagedKafkaResourceType.getDefault(mkAppName, mkAppName, keycloak, latestStrimziVersion, kafkaVersion);
mk = resourceManager.createResource(extensionContext, mk);
if (!ManagedKafkaResourceType.isDevKafka(mk)) {
resourceManager.waitResourceCondition(mk, m -> {
String reason = ManagedKafkaResourceType.getCondition(m.getStatus(), ManagedKafkaCondition.Type.Ready).get().getReason();
if (reason != null) {
return reason.equals(ManagedKafkaCondition.Reason.StrimziUpdating.toString());
}
return false;
}, TimeUnit.MINUTES.toMillis(5));
resourceManager.waitResourceCondition(mk, m -> ManagedKafkaResourceType.getCondition(m.getStatus(), ManagedKafkaCondition.Type.Ready).get().getReason() == null, TimeUnit.MINUTES.toMillis(10));
}
TestUtils.waitFor("MK is upgraded", TimeUnit.SECONDS.toMillis(20), TimeUnit.MINUTES.toMillis(10), () -> {
try {
assertEquals(latestStrimziVersion, ManagedKafkaResourceType.getOperation().inNamespace(mkAppName).withName(mkAppName).get().getStatus().getVersions().getStrimzi());
return true;
} catch (AssertionError err) {
return false;
}
});
}
use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class StrimziManagerTest method testStrimziVersionChange.
@Test
public void testStrimziVersionChange() {
ManagedKafka mk = ManagedKafka.getDummyInstance(1);
mk.getSpec().getVersions().setStrimzi("strimzi-cluster-operator.v1");
Kafka kafka = this.kafkaCluster.kafkaFrom(mk, null);
kafkaClient.create(kafka);
// Kafka reconcile not paused and current label version as the ManagedKafka one
assertFalse(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), mk.getSpec().getVersions().getStrimzi());
// ManagedKafka and Kafka updated their status information
mk.setStatus(new ManagedKafkaStatusBuilder().withVersions(new VersionsBuilder().withStrimzi("strimzi-cluster-operator.v1").build()).build());
kafka.setStatus(new KafkaStatusBuilder().withConditions(new ConditionBuilder().withType("Ready").withStatus("True").build()).build());
kafkaClient.replaceStatus(kafka);
// ask for a Strimzi version change on ManagedKafka
mk.getSpec().getVersions().setStrimzi("strimzi-cluster-operator.v2");
kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
// Kafka reconcile paused but label is still the current version
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), mk.getStatus().getVersions().getStrimzi());
// nothing should change after an intermediate reconcile
kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
// Kafka moves to be paused
kafka.setStatus(new KafkaStatusBuilder().withConditions(new ConditionBuilder().withType("ReconciliationPaused").withStatus("True").build()).build());
kafkaClient.replaceStatus(kafka);
kafka = this.kafkaCluster.kafkaFrom(mk, kafka);
// Kafka reconcile not paused and Kafka label updated to requested Strimzi version
assertFalse(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_RECONCILE_ANNOTATION));
// the pause reason should stay until strimzi updates to ready
assertTrue(kafka.getMetadata().getAnnotations().containsKey(StrimziManager.STRIMZI_PAUSE_REASON_ANNOTATION));
assertEquals(kafka.getMetadata().getLabels().get(this.strimziManager.getVersionLabel()), "strimzi-cluster-operator.v2");
}
use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaProvisioner method deployCluster.
/**
* TODO: if/when this will need to test bin packing, then we'll separate the profile setting from deployCluster
*
* Deploy a Kafka cluster using this provisioner.
* @param profile
*/
public ManagedKafkaDeployment deployCluster(String name, ManagedKafkaCapacity managedKafkaCapacity, KafkaInstanceConfiguration profile) throws Exception {
// set and validate the strimzi version
String strimziVersion = PerformanceEnvironment.STRIMZI_VERSION;
if (strimziVersion == null) {
strimziVersion = strimziVersions.get(strimziVersions.size() - 1);
}
String kafkaVersion = PerformanceEnvironment.KAFKA_VERSION;
if (kafkaVersion == null) {
kafkaVersion = getKafkaVersion(strimziVersion);
}
List<String> versions = strimziManager.getVersions();
if (!versions.contains(strimziVersion)) {
throw new IllegalStateException(String.format("Strimzi version %s is not in the set of installed versions %s", strimziVersion, versions));
}
int replicas = 3;
if (managedKafkaCapacity.getMaxPartitions() != null) {
replicas = (int) (3 * Math.ceil(managedKafkaCapacity.getMaxPartitions() / (double) profile.getKafka().getPartitionCapacity()));
}
applyProfile(profile, replicas);
String namespace = Constants.KAFKA_NAMESPACE;
ManagedKafka managedKafka = new ManagedKafkaBuilder().withNewMetadata().withName(name).withNamespace(namespace).endMetadata().withSpec(new ManagedKafkaSpecBuilder().withCapacity(managedKafkaCapacity).withNewEndpoint().withBootstrapServerHost(String.format("%s-kafka-bootstrap-%s.%s", name, namespace, domain)).withNewTls().withCert(tlsConfig.getCert()).withKey(tlsConfig.getKey()).endTls().endEndpoint().withNewVersions().withKafka(kafkaVersion).withStrimzi(strimziVersion).endVersions().build()).build();
clusters.add(managedKafka);
LOGGER.info("Deploying {}", Serialization.asYaml(managedKafka));
ManagedKafkaDeployment kafkaDeployment = deployCluster(namespace, managedKafka);
kafkaDeployment.start();
return kafkaDeployment;
}
use of org.bf2.cos.fleetshard.api.Version in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class OperatorST method testUpgradeStrimziVersion.
@SequentialTest
void testUpgradeStrimziVersion(ExtensionContext extensionContext) throws Exception {
String mkAppName = "mk-test-upgrade";
LOGGER.info("Create namespace");
resourceManager.addResource(extensionContext, new NamespaceBuilder().withNewMetadata().withName(mkAppName).endMetadata().build());
String startVersion = strimziVersions.get(strimziVersions.size() - 2);
LOGGER.info("Create managedkafka with version {}", startVersion);
ManagedKafka mk = ManagedKafkaResourceType.getDefault(mkAppName, mkAppName, null, startVersion, latestKafkaVersion);
mk = resourceManager.createResource(extensionContext, mk);
Resource<ManagedKafka> mkResource = kube.client().resources(ManagedKafka.class).inNamespace(mk.getMetadata().getNamespace()).withName(mk.getMetadata().getName());
LOGGER.info("Upgrading managedkafka to version {}", latestStrimziVersion);
mkResource.edit(r -> {
r.getSpec().getVersions().setStrimzi(latestStrimziVersion);
return r;
});
mkResource.waitUntilCondition(m -> {
String reason = ManagedKafkaResourceType.getCondition(m.getStatus(), ManagedKafkaCondition.Type.Ready).get().getReason();
return ManagedKafkaCondition.Reason.StrimziUpdating.name().equals(reason);
}, 5, TimeUnit.MINUTES);
mkResource.waitUntilCondition(m -> ManagedKafkaResourceType.getCondition(m.getStatus(), ManagedKafkaCondition.Type.Ready).get().getReason() == null && latestStrimziVersion.equals(m.getStatus().getVersions().getStrimzi()), 10, TimeUnit.MINUTES);
}
Aggregations