LIRAN Y
11/14/2022, 11:05 AMprivate fun printAllPodsName() {
val podList = client.pods().inNamespace("default").list()
podList.items.forEach(Consumer { obj: Pod ->
println(obj.metadata.name)
})
}
now i want to go over this pod name list so it will check if the status is ready or not i tried to do something like this
fun waitUntilAllPodsAreReady() {
for (podname in printAllPodsName().toString()) {
client.pods().inNamespace("default").waitUntilCondition({ pods ->
pods.status != null && pods.status.conditions != null
}, 10, TimeUnit.MINUTES)
println(podname.toString())
}
}
but it seems like not working
any idea will be blessedRoukanken
11/14/2022, 11:23 AMprintAllPodsName
function - as its name says, it is printing names of all pods, not returning them
So when you try to use the names of the pods, it does not compile, as you may have noticed by having to add .toString()
in the for cycle: for (podname in printAllPodsName().toString()) {
Since your function does not have a return value, it implicitly returns Unit
, of which .toString()
is `kotlin.Unit`: so you are searching for pods named k
, o
, t
, ... and so onRoukanken
11/14/2022, 11:25 AMpodname
variable while trying to wait on itLIRAN Y
11/14/2022, 12:21 PMpodname
i changed the func to this:
fun waitUntilAllPodsAreReady() {
for (podname in printAllPodsName().toString()) {
client.pods().inNamespace("default").withName("$podname").waitUntilReady(20, TimeUnit.SECONDS)
Gauge.writeMessage("$podname is ready")
}
}
Roukanken
11/14/2022, 12:23 PMpodList.items
? It probably implements List<T>
so you should be able to call .map { pod -> pod.metadata.name }
on it - which will return you a list of pod names, and you can pass that onwardsNico Filzmoser
11/14/2022, 12:32 PMfun getAllPodNames(): List<String> {
val podList = client.pods().inNamespace("default").list()
return podList.items.map { it.metadata.name }
}
fun waitUntilAllPodsAreReady() {
getAllPodNames().forEach { podName ->
client.pods().inNamespace("default").withName(podName).waitUntilCondition(
{ pod ->
pod.status != null && pod.status.conditions != null
}, 10, TimeUnit.MINUTES
)
}
}
LIRAN Y
11/14/2022, 12:53 PM.map
saved me 10xxx
and @Nico Filzmoser yeap i did like you wrote
thanks you both 👍 i also succeeded to write other fun to print just the running pods
fun printAllTheRunningPods() {
client.pods().withField("status.phase", "Running").list().items.stream()
.map { obj: Pod -> obj.metadata }.map { obj: ObjectMeta -> obj.name }
.forEach { msg: String? -> println("$msg is running OK") }
}