task: adding more diagnostics for remote failed runs (#27441)

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steven Hawkins 2024-03-01 12:54:51 -05:00 committed by GitHub
parent 6609b591e1
commit ffc1b69afa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -321,7 +321,7 @@ public class BaseOperatorTest implements QuarkusTestAfterEachCallback {
// provide some helpful entries in the main log as well // provide some helpful entries in the main log as well
logFailedKeycloaks(); logFailedKeycloaks();
if (operatorDeployment == OperatorDeployment.remote) { if (operatorDeployment == OperatorDeployment.remote) {
logFailed(k8sclient.apps().deployments().withName("keycloak-operator"), Deployment::getStatus); log(k8sclient.apps().deployments().withName("keycloak-operator"), Deployment::getStatus, false);
} }
logFailed(k8sclient.apps().statefulSets().withName(POSTGRESQL_NAME), StatefulSet::getStatus); logFailed(k8sclient.apps().statefulSets().withName(POSTGRESQL_NAME), StatefulSet::getStatus);
k8sclient.pods().withLabel("app", "keycloak-realm-import").list().getItems().stream() k8sclient.pods().withLabel("app", "keycloak-realm-import").list().getItems().stream()
@ -331,16 +331,20 @@ public class BaseOperatorTest implements QuarkusTestAfterEachCallback {
} }
} }
private <T extends HasMetadata, R extends Resource<T> & Loggable> void logFailed(R resource, Function<T, Object> statusExtractor) { private <T extends HasMetadata, R extends Resource<T> & Loggable> void log(R resource, Function<T, Object> statusExtractor, boolean failedOnly) {
var instance = resource.get(); var instance = resource.get();
if (resource.isReady()) { if (failedOnly) {
return; if (resource.isReady()) {
return;
}
Log.warnf("%s failed to become ready %s", instance.getMetadata().getName(), Serialization.asYaml(statusExtractor.apply(instance)));
} else {
Log.infof("%s is ready %s", instance.getMetadata().getName(), Serialization.asYaml(statusExtractor.apply(instance)));
} }
Log.warnf("%s failed to become ready %s", instance.getMetadata().getName(), Serialization.asYaml(statusExtractor.apply(instance)));
try { try {
String log = resource.getLog(); String log = resource.getLog();
log = log.substring(Math.max(0, log.length() - 5000)); log = log.substring(Math.max(0, log.length() - 5000));
Log.warnf("%s not ready log: %s", instance.getMetadata().getName(), log); Log.warnf("%s log: %s", instance.getMetadata().getName(), log);
} catch (KubernetesClientException e) { } catch (KubernetesClientException e) {
Log.warnf("No %s log: %s", instance.getMetadata().getName(), e.getMessage()); Log.warnf("No %s log: %s", instance.getMetadata().getName(), e.getMessage());
if (instance instanceof Pod) { if (instance instanceof Pod) {
@ -357,6 +361,10 @@ public class BaseOperatorTest implements QuarkusTestAfterEachCallback {
} }
} }
private <T extends HasMetadata, R extends Resource<T> & Loggable> void logFailed(R resource, Function<T, Object> statusExtractor) {
log(resource, statusExtractor, true);
}
private void logFailedKeycloaks() { private void logFailedKeycloaks() {
k8sclient.resources(Keycloak.class).list().getItems().stream() k8sclient.resources(Keycloak.class).list().getItems().stream()
.filter(kc -> !Optional.ofNullable(kc.getStatus()).map(KeycloakStatus::isReady).orElse(false)) .filter(kc -> !Optional.ofNullable(kc.getStatus()).map(KeycloakStatus::isReady).orElse(false))