|
1 | | -use promkit::{json::JsonStream, preset::json::Json, serde_json::Deserializer}; |
| 1 | +use promkit::{jsonstream::JsonStream, preset::json::Json}; |
| 2 | +use serde_json::Deserializer; |
2 | 3 |
|
3 | 4 | fn main() -> anyhow::Result<()> { |
4 | 5 | let stream = JsonStream::new( |
5 | 6 | Deserializer::from_str( |
6 | | - r#"{ |
7 | | - "number": 9, |
8 | | - "map": { |
9 | | - "entry1": "first", |
10 | | - "entry2": "second" |
11 | | - }, |
12 | | - "list": [ |
13 | | - "abc", |
14 | | - "def" |
15 | | - ] |
16 | | - }"#, |
| 7 | + r#" |
| 8 | + { |
| 9 | + "apiVersion": "v1", |
| 10 | + "kind": "Pod", |
| 11 | + "metadata": { |
| 12 | + "annotations": { |
| 13 | + "kubeadm.kubernetes.io/etcd.advertise-client-urls": "https://172.18.0.2:2379", |
| 14 | + "kubernetes.io/config.hash": "9c4c3ba79af7ad68d939c568f053bfff", |
| 15 | + "kubernetes.io/config.mirror": "9c4c3ba79af7ad68d939c568f053bfff", |
| 16 | + "kubernetes.io/config.seen": "2024-10-12T12:53:27.751706220Z", |
| 17 | + "kubernetes.io/config.source": "file" |
| 18 | + }, |
| 19 | + "creationTimestamp": "2024-10-12T12:53:31Z", |
| 20 | + "labels": { |
| 21 | + "component": "etcd", |
| 22 | + "tier": "control-plane" |
| 23 | + }, |
| 24 | + "name": "etcd-kind-control-plane", |
| 25 | + "namespace": "kube-system", |
| 26 | + "ownerReferences": [ |
| 27 | + { |
| 28 | + "apiVersion": "v1", |
| 29 | + "controller": true, |
| 30 | + "kind": "Node", |
| 31 | + "name": "kind-control-plane", |
| 32 | + "uid": "6cb2c3e5-1a73-4932-9cc5-6d69b80a9932" |
| 33 | + } |
| 34 | + ], |
| 35 | + "resourceVersion": "192988", |
| 36 | + "uid": "77465839-5a58-43b1-b754-55deed66d5ca" |
| 37 | + }, |
| 38 | + "spec": { |
| 39 | + "containers": [ |
| 40 | + { |
| 41 | + "command": [ |
| 42 | + "etcd", |
| 43 | + "--advertise-client-urls=https://172.18.0.2:2379", |
| 44 | + "--cert-file=/etc/kubernetes/pki/etcd/server.crt", |
| 45 | + "--client-cert-auth=true", |
| 46 | + "--data-dir=/var/lib/etcd", |
| 47 | + "--experimental-initial-corrupt-check=true", |
| 48 | + "--experimental-watch-progress-notify-interval=5s", |
| 49 | + "--initial-advertise-peer-urls=https://172.18.0.2:2380", |
| 50 | + "--initial-cluster=kind-control-plane=https://172.18.0.2:2380", |
| 51 | + "--key-file=/etc/kubernetes/pki/etcd/server.key", |
| 52 | + "--listen-client-urls=https://127.0.0.1:2379,https://172.18.0.2:2379", |
| 53 | + "--listen-metrics-urls=http://127.0.0.1:2381", |
| 54 | + "--listen-peer-urls=https://172.18.0.2:2380", |
| 55 | + "--name=kind-control-plane", |
| 56 | + "--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt", |
| 57 | + "--peer-client-cert-auth=true", |
| 58 | + "--peer-key-file=/etc/kubernetes/pki/etcd/peer.key", |
| 59 | + "--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt", |
| 60 | + "--snapshot-count=10000", |
| 61 | + "--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt" |
| 62 | + ], |
| 63 | + "image": "registry.k8s.io/etcd:3.5.15-0", |
| 64 | + "imagePullPolicy": "IfNotPresent", |
| 65 | + "livenessProbe": { |
| 66 | + "failureThreshold": 8, |
| 67 | + "httpGet": { |
| 68 | + "host": "127.0.0.1", |
| 69 | + "path": "/livez", |
| 70 | + "port": 2381, |
| 71 | + "scheme": "HTTP" |
| 72 | + }, |
| 73 | + "initialDelaySeconds": 10, |
| 74 | + "periodSeconds": 10, |
| 75 | + "successThreshold": 1, |
| 76 | + "timeoutSeconds": 15 |
| 77 | + }, |
| 78 | + "name": "etcd", |
| 79 | + "readinessProbe": { |
| 80 | + "failureThreshold": 3, |
| 81 | + "httpGet": { |
| 82 | + "host": "127.0.0.1", |
| 83 | + "path": "/readyz", |
| 84 | + "port": 2381, |
| 85 | + "scheme": "HTTP" |
| 86 | + }, |
| 87 | + "periodSeconds": 1, |
| 88 | + "successThreshold": 1, |
| 89 | + "timeoutSeconds": 15 |
| 90 | + }, |
| 91 | + "resources": { |
| 92 | + "requests": { |
| 93 | + "cpu": "100m", |
| 94 | + "memory": "100Mi" |
| 95 | + } |
| 96 | + }, |
| 97 | + "startupProbe": { |
| 98 | + "failureThreshold": 24, |
| 99 | + "httpGet": { |
| 100 | + "host": "127.0.0.1", |
| 101 | + "path": "/readyz", |
| 102 | + "port": 2381, |
| 103 | + "scheme": "HTTP" |
| 104 | + }, |
| 105 | + "initialDelaySeconds": 10, |
| 106 | + "periodSeconds": 10, |
| 107 | + "successThreshold": 1, |
| 108 | + "timeoutSeconds": 15 |
| 109 | + }, |
| 110 | + "terminationMessagePath": "/dev/termination-log", |
| 111 | + "terminationMessagePolicy": "File", |
| 112 | + "volumeMounts": [ |
| 113 | + { |
| 114 | + "mountPath": "/var/lib/etcd", |
| 115 | + "name": "etcd-data" |
| 116 | + }, |
| 117 | + { |
| 118 | + "mountPath": "/etc/kubernetes/pki/etcd", |
| 119 | + "name": "etcd-certs" |
| 120 | + } |
| 121 | + ] |
| 122 | + } |
| 123 | + ], |
| 124 | + "dnsPolicy": "ClusterFirst", |
| 125 | + "enableServiceLinks": true, |
| 126 | + "hostNetwork": true, |
| 127 | + "nodeName": "kind-control-plane", |
| 128 | + "preemptionPolicy": "PreemptLowerPriority", |
| 129 | + "priority": 2000001000, |
| 130 | + "priorityClassName": "system-node-critical", |
| 131 | + "restartPolicy": "Always", |
| 132 | + "schedulerName": "default-scheduler", |
| 133 | + "securityContext": { |
| 134 | + "seccompProfile": { |
| 135 | + "type": "RuntimeDefault" |
| 136 | + } |
| 137 | + }, |
| 138 | + "terminationGracePeriodSeconds": 30, |
| 139 | + "tolerations": [ |
| 140 | + { |
| 141 | + "effect": "NoExecute", |
| 142 | + "operator": "Exists" |
| 143 | + } |
| 144 | + ], |
| 145 | + "volumes": [ |
| 146 | + { |
| 147 | + "hostPath": { |
| 148 | + "path": "/etc/kubernetes/pki/etcd", |
| 149 | + "type": "DirectoryOrCreate" |
| 150 | + }, |
| 151 | + "name": "etcd-certs" |
| 152 | + }, |
| 153 | + { |
| 154 | + "hostPath": { |
| 155 | + "path": "/var/lib/etcd", |
| 156 | + "type": "DirectoryOrCreate" |
| 157 | + }, |
| 158 | + "name": "etcd-data" |
| 159 | + } |
| 160 | + ] |
| 161 | + }, |
| 162 | + "status": { |
| 163 | + "conditions": [ |
| 164 | + { |
| 165 | + "lastProbeTime": null, |
| 166 | + "lastTransitionTime": "2024-12-06T13:28:35Z", |
| 167 | + "status": "True", |
| 168 | + "type": "PodReadyToStartContainers" |
| 169 | + }, |
| 170 | + { |
| 171 | + "lastProbeTime": null, |
| 172 | + "lastTransitionTime": "2024-12-06T13:28:34Z", |
| 173 | + "status": "True", |
| 174 | + "type": "Initialized" |
| 175 | + }, |
| 176 | + { |
| 177 | + "lastProbeTime": null, |
| 178 | + "lastTransitionTime": "2024-12-06T13:28:50Z", |
| 179 | + "status": "True", |
| 180 | + "type": "Ready" |
| 181 | + }, |
| 182 | + { |
| 183 | + "lastProbeTime": null, |
| 184 | + "lastTransitionTime": "2024-12-06T13:28:50Z", |
| 185 | + "status": "True", |
| 186 | + "type": "ContainersReady" |
| 187 | + }, |
| 188 | + { |
| 189 | + "lastProbeTime": null, |
| 190 | + "lastTransitionTime": "2024-12-06T13:28:34Z", |
| 191 | + "status": "True", |
| 192 | + "type": "PodScheduled" |
| 193 | + } |
| 194 | + ], |
| 195 | + "containerStatuses": [ |
| 196 | + { |
| 197 | + "containerID": "containerd://de0d57479a3ac10e213df6ea4fc1d648ad4d70d4ddf1b95a7999d0050171a41e", |
| 198 | + "image": "registry.k8s.io/etcd:3.5.15-0", |
| 199 | + "imageID": "sha256:27e3830e1402783674d8b594038967deea9d51f0d91b34c93c8f39d2f68af7da", |
| 200 | + "lastState": { |
| 201 | + "terminated": { |
| 202 | + "containerID": "containerd://28d1a65bd9cfa40624a0c17979208f66a5cc7f496a57fa9a879907bb936f57b3", |
| 203 | + "exitCode": 255, |
| 204 | + "finishedAt": "2024-12-06T13:28:31Z", |
| 205 | + "reason": "Unknown", |
| 206 | + "startedAt": "2024-11-04T15:14:19Z" |
| 207 | + } |
| 208 | + }, |
| 209 | + "name": "etcd", |
| 210 | + "ready": true, |
| 211 | + "restartCount": 2, |
| 212 | + "started": true, |
| 213 | + "state": { |
| 214 | + "running": { |
| 215 | + "startedAt": "2024-12-06T13:28:35Z" |
| 216 | + } |
| 217 | + } |
| 218 | + } |
| 219 | + ], |
| 220 | + "hostIP": "172.18.0.2", |
| 221 | + "hostIPs": [ |
| 222 | + { |
| 223 | + "ip": "172.18.0.2" |
| 224 | + } |
| 225 | + ], |
| 226 | + "phase": "Running", |
| 227 | + "podIP": "172.18.0.2", |
| 228 | + "podIPs": [ |
| 229 | + { |
| 230 | + "ip": "172.18.0.2" |
| 231 | + } |
| 232 | + ], |
| 233 | + "qosClass": "Burstable", |
| 234 | + "startTime": "2024-12-06T13:28:34Z" |
| 235 | + } |
| 236 | + } |
| 237 | + "#, |
17 | 238 | ) |
18 | 239 | .into_iter::<serde_json::Value>() |
19 | | - .filter_map(serde_json::Result::ok), |
20 | | - None, |
| 240 | + .filter_map(serde_json::Result::ok) |
| 241 | + .collect::<Vec<_>>() |
| 242 | + .iter(), |
21 | 243 | ); |
22 | 244 |
|
23 | | - let mut p = Json::new(stream) |
24 | | - .title("JSON viewer") |
25 | | - .json_lines(5) |
26 | | - .prompt()?; |
| 245 | + let mut p = Json::new(stream).title("JSON viewer").prompt()?; |
27 | 246 | println!("result: {:?}", p.run()?); |
28 | 247 | Ok(()) |
29 | 248 | } |
0 commit comments