Commit f8c81497 authored by mengxue's avatar mengxue
Browse files

list nodes in the cluster

parent 6266ba88
package skuberopenmole
import java.text.SimpleDateFormat
import skuber.{NodeList, _}
import skuber.json.format._
import akka.actor.ActorSystem
......@@ -17,6 +19,13 @@ import scala.util.{Failure, Success}
object ListNodes extends App {
case class NodeInfo (
status: String,
role: String,
version: String,
startTime: Timestamp
)
private def listNodes(nodes: List[Node]) = {
System.out.println("")
System.out.println("Node STATUS ROLE VERSION START TIME")
......@@ -24,15 +33,44 @@ object ListNodes extends App {
nodes.map { node: Node =>
val name = node.name
val status = node.status
val phaseOpt = for {
status <- node.status
phase <- status.phase
} yield phase
val phase = phaseOpt.getOrElse("Not set")
System.out.println(f"${name}%-20s${name}%-20s${phase}")
val nodeInfo = (for {
stat <- node.status.toList
status <- stat.conditions
label <- node.metadata.labels
} yield {
NodeInfo(status._type, label._2, stat.nodeInfo.get.kubeletVersion, node.metadata.creationTimestamp.get)
}).reverse.headOption
val startTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(nodeInfo.map{_.startTime}.getOrElse("None").toString())
System.out.println(f"${name}%-20s${nodeInfo.map{_.status.toString}.getOrElse("Nono")}%-20s${nodeInfo.map{_.role}.getOrElse("Master")}%-20s${nodeInfo.map{_.version}.getOrElse("None")}%-20s${startTimeString}")
// node metadata: ObjectMeta(intern,
// ,
// ,
// ad825ab1-8614-11e9-b097-9cb6d0d185f7,
// /api/v1/nodes/intern,
// 176636,
// Some(2019-06-03T15:31:37Z),
// None,
// None,
// Map(kubernetes.io/arch -> amd64, beta.kubernetes.io/arch -> amd64, node-role.kubernetes.io/master -> , beta.kubernetes.io/os -> linux, kubernetes.io/os -> linux, kubernetes.io/hostname -> intern),
// Map(volumes.kubernetes.io/controller-managed-attach-detach -> true, kubeadm.alpha.kubernetes.io/cri-socket -> /var/run/dockershim.sock, flannel.alpha.coreos.com/public-ip -> 192.168.1.136, flannel.alpha.coreos.com/backend-type -> vxlan, node.alpha.kubernetes.io/ttl -> 0, flannel.alpha.coreos.com/kube-subnet-manager -> true, flannel.alpha.coreos.com/backend-data -> {"VtepMAC":"32:37:42:9f:f8:8e"}),
// List(),0,None,None)
// node status: Some(Status(Map(hugepages-2Mi -> 0, hugepages-1Gi -> 0, pods -> 110, cpu -> 4, ephemeral-storage -> 488949800Ki, memory -> 16140648Ki),
// None,
// List(Condition(MemoryPressure,False,Some(2019-06-12T08:21:13Z),Some(2019-06-03T15:31:36Z),Some(KubeletHasSufficientMemory),Some(kubelet has sufficient memory available)), Condition(DiskPressure,False,Some(2019-06-12T08:21:13Z),Some(2019-06-03T15:31:36Z),Some(KubeletHasNoDiskPressure),Some(kubelet has no disk pressure)), Condition(PIDPressure,False,Some(2019-06-12T08:21:13Z),Some(2019-06-03T15:31:36Z),Some(KubeletHasSufficientPID),Some(kubelet has sufficient PID available)), Condition(Ready,True,Some(2019-06-12T08:21:13Z),Some(2019-06-03T15:36:28Z),Some(KubeletReady),Some(kubelet is posting ready status. AppArmor enabled))),
// List(Address(InternalIP,192.168.1.136), Address(Hostname,intern)),
// Some(SystemInfo(9a23bfdc5d8249e6860a5cbbbef9b6a4,4c4c4544-0037-5410-8036-cac04f544332,dc497310-a797-43b8-959e-8075a8125337,5.0.0-16-generic,Ubuntu 19.04,docker://18.9.5,v1.14.2,v1.14.2)),
// Map(hugepages-2Mi -> 0, hugepages-1Gi -> 0, pods -> 110, cpu -> 4, ephemeral-storage -> 450616134934, memory -> 16038248Ki),
// Some(DaemonEndpoints(DaemonEndpoint(10250))),
// List(Image(List(openmole/openmole@sha256:c86ec16fd6b0486775c679b9a0a3feabdd97edd17124abe97ece752405a31ff7),Some(877563578)), Image(List(openmole/openmole@sha256:0269a4d35c471ba97ce7c630d2dfa26474ff0c0edf0b19c0108ccd2dd8095974, openmole/openmole:latest),Some(651897552)), Image(List(openmole/openmole@sha256:4187dffee1685cd715fd0c47321b0009fdcd53fa9d47e895b3e424cc33504c77),Some(635538287)), Image(List(quay.io/kubernetes-ingress-controller/nginx-ingress-controller@sha256:76861d167e4e3db18f2672fd3435396aaa898ddf4d1128375d7c93b91c59f87f, quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.24.1),Some(631358200)), Image(List(k8s.gcr.io/etcd@sha256:17da501f5d2a675be46040422a27b7cc21b8a43895ac998b171db1c346f361f7, k8s.gcr.io/etcd:3.3.10),Some(258116302)), Image(List(k8s.gcr.io/kube-apiserver@sha256:223577e889dfb1a6e85faa6e3993308ead0b48b2a9c9d22c8fcd84b03d8a3af0, k8s.gcr.io/kube-apiserver:v1.14.2),Some(209916798)), Image(List(k8s.gcr.io/kube-controller-manager@sha256:51a382e90acd9d11d5571850312ad4b268db8b28b2868516dfda19a6933a095c, k8s.gcr.io/kube-controller-manager:v1.14.2),Some(157933630)), Image(List(nginx@sha256:2f68b99bc0d6d25d0c56876b924ec20418544ff28e1fb89a4c27679a40da811b, nginx:1.9.1),Some(132835913)), Image(List(k8s.gcr.io/kubernetes-dashboard-amd64@sha256:0ae6b69432e78069c5ce2bcde0fe409c5c4d6f0f4d9cd50a17974fea38898747, k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1),Some(121711221)), Image(List(nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451, nginx:1.7.9),Some(91664166)), Image(List(k8s.gcr.io/kube-proxy@sha256:c91687ff6145f7fcdc7d8b3da3c530a9a9b50f0734c7a945a0d9c18fc3790dbc, k8s.gcr.io/kube-proxy:v1.14.2),Some(82106236)), Image(List(k8s.gcr.io/kube-scheduler@sha256:052e0322b8a2b22819ab0385089f202555c4099493d1bd33205a34753494d2c2, k8s.gcr.io/kube-scheduler:v1.14.2),Some(81579742)), Image(List(calico/cni@sha256:865b258549cd7a14d6a424de058536e8a6844264f43e94f8166eb16b95ac8905, calico/cni:v3.3.6),Some(75368087)), Image(List(calico/node@sha256:8de3fb410d8b2b1effe57c433ab1d4ce18ccc23f2bb9c418837bfcdbac4494a0, calico/node:v3.3.6),Some(75274059)), Image(List(quay.io/coreos/flannel@sha256:7806805c93b20a168d0bbbd25c6a213f00ac58a511c47e8fa6409543528a204e, quay.io/coreos/flannel:v0.11.0-amd64),Some(52567296)), Image(List(quay.io/coreos/flannel@sha256:60d77552f4ebb6ed4f0562876c6e2e0b0e0ab873cb01808f23f55c8adabd1f59, quay.io/coreos/flannel:v0.9.1),Some(51338831)), Image(List(k8s.gcr.io/coredns@sha256:02382353821b12c21b062c59184e227e001079bb13ebd01f9d3270ba0fcbf1e4, k8s.gcr.io/coredns:1.3.1),Some(40303560)), Image(List(k8s.gcr.io/pause@sha256:f78411e19d84a252e53bff71a4407a5686c46983a2c2eeed83929b888179acea, k8s.gcr.io/pause:3.1),Some(742472))),
// List(),
// List()))
// node spec: Some(Spec(10.244.0.0/24,,false,,List()))
}
}
implicit val system = ActorSystem()
......@@ -47,14 +85,16 @@ object ListNodes extends App {
val allNodesMap: Future[NodeList] = k8s list[NodeList]()
val printNodes = allNodesMap map { nodes => listNodes(nodes.items) }
printNodes onComplete {
case Success(value) =>
Success(value)
case Success(_) =>
k8s.close
println("\n(Waiting 30 seconds before terminating)")
Thread.sleep(30000)
system.terminate()
materializer.shutdown()
case Failure(e) => System.err.println("Failed => " + e)
case Failure(e) =>
System.err.println("Failed => " + e)
system.terminate()
materializer.shutdown()
}
// Await.ready(printNodes, 20 seconds)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment