use of org.bf2.test.k8s.KubeClient in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class ManagedKafkaResourceType method readiness.
@Override
public Predicate<ManagedKafka> readiness(KubeClient client) {
AtomicInteger count = new AtomicInteger();
Set<String> messages = Collections.synchronizedSet(new LinkedHashSet<>());
return mk -> {
if (mk == null) {
throw new IllegalStateException("ManagedKafka is null");
}
ManagedKafkaCondition mkc = getCondition(mk.getStatus(), ManagedKafkaCondition.Type.Ready).orElse(null);
if (mkc == null) {
return false;
}
if (ManagedKafkaCondition.Status.True.name().equals(mkc.getStatus())) {
return true;
}
if (ManagedKafkaCondition.Reason.Error.name().equals(mkc.getReason())) {
if (messages.add(mkc.getMessage())) {
LOGGER.warn("ManagedKafka {} in error state {}", mk.getMetadata().getName(), mkc.getMessage());
}
// throw new IllegalStateException(String.format("ManagedKafka %s in error state %s", mk.getMetadata().getName(), mkc.getMessage()));
}
if (count.getAndIncrement() % 15 == 0) {
ListOptions opts = new ListOptionsBuilder().withFieldSelector("status.phase=Pending").build();
client.client().pods().inNamespace(mk.getMetadata().getNamespace()).withLabel("strimzi.io/cluster").list(opts).getItems().forEach(ManagedKafkaResourceType::checkUnschedulablePod);
}
return false;
};
}
use of org.bf2.test.k8s.KubeClient in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class DrainCleanerTest method testKafkaAvailabilityDuringClusterUpgrade.
@Test
@Tag(TestTags.PERF)
void testKafkaAvailabilityDuringClusterUpgrade(TestInfo info) throws Exception {
long throughput = 41943040;
int numWorkers = 12;
int topics = 10;
int messageSize = 1024;
int partitionsPerTopic = 205;
int workerProducerRate = 40000;
ensureClientClusterCapacityForWorkers(omb.getOmbCluster(), numWorkers, WORKER_SIZE, CPU_SIZE);
workers = omb.deployWorkers(numWorkers);
ManagedKafkaCapacity capacity = kafkaProvisioner.defaultCapacity(throughput);
ManagedKafkaDeployment deployCluster = kafkaProvisioner.deployCluster("cluster1", capacity, AdopterProfile.VALUE_PROD);
String bootstrapHosts = deployCluster.waitUntilReady();
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
Future<Integer> nodeDrain;
Future<File> resultDone;
try {
nodeDrain = scheduler.schedule(() -> {
// this thread simulates the OpenShift cluster upgrade
LOGGER.info("PERFORMING SCHEDULED NODES DRAIN");
kafkaProvisioner.getKubernetesCluster().kubeClient().getClusterWorkers().forEach(node -> {
TestUtils.drainNode(kafkaProvisioner.getKubernetesCluster(), node.getMetadata().getName());
TestUtils.waitUntilAllPodsReady(kafkaProvisioner.getKubernetesCluster(), deployCluster.getManagedKafka().getMetadata().getNamespace());
TestUtils.setNodeSchedule(kafkaProvisioner.getKubernetesCluster(), node.getMetadata().getName(), true);
});
return 0;
}, 2, TimeUnit.MINUTES);
resultDone = scheduler.submit(() -> {
OMBDriver driver = new OMBDriver().setReplicationFactor(3).setTopicConfig("min.insync.replicas=2\n").setCommonConfigWithBootstrapUrl(bootstrapHosts).setProducerConfig("acks=all\n").setConsumerConfig("auto.offset.reset=earliest\nenable.auto.commit=false\n");
int producerConsumer = numWorkers / 2;
LOGGER.info("PERFORMING OMB WORKLOAD");
OMBWorkloadResult result = omb.runWorkload(instanceDir, driver, workers, new OMBWorkload().setName(info.getDisplayName()).setTopics(topics).setPartitionsPerTopic(partitionsPerTopic).setMessageSize(messageSize).setPayloadFile("src/test/resources/payload/payload-1Kb.data").setSubscriptionsPerTopic(1).setConsumerPerSubscription(producerConsumer).setProducersPerTopic(producerConsumer).setProducerRate(workerProducerRate).setConsumerBacklogSizeGB(0).setTestDurationMinutes(15));
LOGGER.info("{}: results {}", info.getDisplayName(), result.getResultFile());
LOGGER.info("COMPLETED OMB WORKLOAD");
return result.getResultFile();
});
Integer podTaskRetVal = nodeDrain.get(25, TimeUnit.MINUTES);
LOGGER.info("Node drain task return value: {}", podTaskRetVal.toString());
File resultFile = resultDone.get(25, TimeUnit.MINUTES);
LOGGER.info("Result file: {}", resultFile);
} finally {
scheduler.shutdown();
scheduler.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.bf2.test.k8s.KubeClient in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class TestExceptionCallbackListener method afterTestExecution.
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
for (KubeClusterResource kubeClusterResource : KubeClusterResource.getCurrentConnectedClusters()) {
KubeClient kubeClient = kubeClusterResource.kubeClient();
kubeClient.client().namespaces().list().getItems().stream().filter(ns -> checkAnnotation(ns, Constants.ORG_BF2_PERFORMANCE_CHECKRESTARTEDCONTAINERS)).forEach(ns -> {
List<Pod> podsWithRestartedContainers = kubeClient.client().pods().inNamespace(ns.getMetadata().getName()).list().getItems().stream().filter(p -> p.getStatus().getContainerStatuses().stream().anyMatch(cs -> cs.getRestartCount() > 0)).collect(Collectors.toList());
if (!podsWithRestartedContainers.isEmpty()) {
LOGGER.error("Found {} pod(s) with containers that had restarted at least once", podsWithRestartedContainers.size());
podsWithRestartedContainers.forEach(p -> {
p.getStatus().getContainerStatuses().stream().filter(cs -> cs.getRestartCount() > 0).forEach(cs -> {
LOGGER.error("Pod {} container {} restart count {}", p.getMetadata().getName(), cs.getName(), cs.getRestartCount());
});
});
if (context.getExecutionException().isEmpty()) {
// Fail the test
throw new RuntimeException("Found {} pod(s) with containers that had restarted at least once");
}
}
});
}
}
use of org.bf2.test.k8s.KubeClient in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class LogCollector method saveClusterState.
private static void saveClusterState(Path logpath) throws IOException {
KubeClient kube = KubeClient.getInstance();
Files.writeString(logpath.resolve("describe-cluster-nodes.log"), kube.cmdClient().exec(false, false, "describe", "nodes").out());
Files.writeString(logpath.resolve("all-events.log"), kube.cmdClient().exec(false, false, "get", "events", "--all-namespaces").out());
Files.writeString(logpath.resolve("pvs.log"), kube.cmdClient().exec(false, false, "describe", "pv").out());
Files.writeString(logpath.resolve("operator-routes.yml"), kube.cmdClient().exec(false, false, "get", "routes", "-n", FleetShardOperatorManager.OPERATOR_NS, "-o", "yaml").out());
Files.writeString(logpath.resolve("operator-services.yml"), kube.cmdClient().exec(false, false, "get", "service", "-n", FleetShardOperatorManager.OPERATOR_NS, "-o", "yaml").out());
Files.writeString(logpath.resolve("kas-fleetshard-operator-pods.yml"), kube.cmdClient().exec(false, false, "get", "pod", "-l", "app=" + FleetShardOperatorManager.OPERATOR_NAME, "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("strimzi-kafka-pods.yml"), kube.cmdClient().exec(false, false, "get", "pod", "-l", "app.kubernetes.io/managed-by=strimzi-cluster-operator", "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("managedkafkas.yml"), kube.cmdClient().exec(false, false, "get", "managedkafka", "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("kafkas.yml"), kube.cmdClient().exec(false, false, "get", "kafka", "-l", "app.kubernetes.io/managed-by=" + FleetShardOperatorManager.OPERATOR_NAME, "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("pods-managed-by-operator.yml"), kube.cmdClient().exec(false, false, "get", "pods", "-l", "app.kubernetes.io/managed-by=" + FleetShardOperatorManager.OPERATOR_NAME, "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("operator-namespace-events.yml"), kube.cmdClient().exec(false, false, "get", "events", "-n", FleetShardOperatorManager.OPERATOR_NS).out());
Files.writeString(logpath.resolve("operator.log"), kube.cmdClient().exec(false, false, "logs", "deployment/" + FleetShardOperatorManager.OPERATOR_NAME, "-n", FleetShardOperatorManager.OPERATOR_NS).out());
Files.writeString(logpath.resolve("sync.log"), kube.cmdClient().exec(false, false, "logs", "deployment/" + FleetShardOperatorManager.SYNC_NAME, "-n", FleetShardOperatorManager.OPERATOR_NS).out());
StrimziOperatorManager.getStrimziOperatorPods().forEach(pod -> {
try {
Files.writeString(logpath.resolve(pod.getMetadata().getName() + ".log"), kube.cmdClient().exec(false, false, "logs", pod.getMetadata().getName(), "--tail", "-1", "-n", pod.getMetadata().getNamespace()).out());
} catch (Exception e) {
LOGGER.warn("Cannot get logs from pod {} in namespace {}", pod.getMetadata().getName(), pod.getMetadata().getNamespace());
}
});
}
use of org.bf2.test.k8s.KubeClient in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class FleetShardOperatorManager method createEndpoint.
public static String createEndpoint(KubeClient kubeClient) {
String externalEndpointName = SYNC_NAME + "-external";
if (kubeClient.isGenericKubernetes()) {
if (kubeClient.client().services().inNamespace(OPERATOR_NS).list().getItems().stream().anyMatch(service -> service.getMetadata().getName().equals(externalEndpointName))) {
kubeClient.client().services().inNamespace(OPERATOR_NS).withName(externalEndpointName).delete();
}
kubeClient.cmdClient().namespace(OPERATOR_NS).execInCurrentNamespace("expose", "service", SYNC_NAME, "--type=LoadBalancer", "--name", externalEndpointName);
return new ExecBuilder().withCommand("minikube", "service", "--url", externalEndpointName, "-n", OPERATOR_NS).logToOutput(false).exec().out().trim();
} else {
OpenShiftClient openShiftClient = kubeClient.client().adapt(OpenShiftClient.class);
if (openShiftClient.routes().inNamespace(OPERATOR_NS).list().getItems().stream().anyMatch(service -> service.getMetadata().getName().equals(externalEndpointName))) {
openShiftClient.routes().inNamespace(OPERATOR_NS).withName(externalEndpointName).delete();
}
kubeClient.cmdClient().namespace(OPERATOR_NS).execInCurrentNamespace("expose", "service", SYNC_NAME, "--name", externalEndpointName);
Route r = openShiftClient.routes().inNamespace(OPERATOR_NS).withName(externalEndpointName).get();
return String.format("%s://%s:%d", r.getSpec().getPort().getTargetPort().getStrVal(), r.getSpec().getHost(), r.getSpec().getPort().getTargetPort().getStrVal().equals("http") ? 80 : 443);
}
}
Aggregations