Skip to content

feat: 支持k8s shell任务出错时,上报容器日志 #210 #208 #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class K8sShellHandler(
}
data = mapOf(CMD to source)
}
val configMap = api.createNamespacedConfigMap(namespace, configMapBody, null, null, null)
logger.info("Created configmap $configMap")
api.createNamespacedConfigMap(namespace, configMapBody, null, null, null)
logger.info("Created configmap $configMapName")
}
val podBody = V1Pod {
metadata {
Expand All @@ -73,7 +73,8 @@ class K8sShellHandler(
setEnv(context)
volumeMounts {
name = "shell-$logId"
mountPath = WORK_SPACE
mountPath = "$WORK_SPACE/$CMD"
subPath = CMD
readOnly = true
}
resources {
Expand Down Expand Up @@ -116,21 +117,37 @@ class K8sShellHandler(
status = pod?.status?.phase.orEmpty()
}
logger.info("Pod status: $status")
val log = api.readNamespacedPodLog(
podName,
namespace,
logId,
true,
null,
null,
null,
null,
null,
null,
null,
)
logger.info("Pod log: $log")
check(pod?.status?.phase == "Succeeded")
if (logger.isDebugEnabled) {
val log = api.readNamespacedPodLog(
podName,
namespace,
logId,
false,
null,
null,
null,
null,
null,
null,
null,
)
logger.debug("Pod log: $log")
}
check(pod?.status?.phase == "Succeeded") {
api.readNamespacedPodLog(
podName,
namespace,
logId,
false,
null,
null,
null,
null,
null,
LOG_TAIL_LINES,
null,
)
}
} catch (e: ApiException) {
logger.error(e.buildMessage())
throw e
Expand Down Expand Up @@ -179,5 +196,6 @@ class K8sShellHandler(
private val logger = LoggerFactory.getLogger(K8sShellHandler::class.java)
private const val CMD = "run.sh"
private const val WORK_SPACE = "/data/workspace"
private const val LOG_TAIL_LINES = 20
}
}
Loading