I am trying to collect IP addresses of the pods which has 3 network interfaces attached to. From the output of kubectl get pod .. -o yaml
, I would like to collect the IPs of 2nd and 3rd interfaces including pod-name.
kubectl describe pod
data:
apiVersion: v1
items:
- apiVersion: v1
kind: Pod
metadata:
annotations:
k8s.v1.cni.cncf.io/network-status: |-
[{
"name": "default-cni-network",
"ips": [
"10.244.160.191"
],
"default": true,
"dns": {}
},{
"name": "minio-tenant/minio-sriov1",
"interface": "net1",
"ips": [
"10.56.217.100"
],
"mac": "6a:58:82:8a:93:7b",
"dns": {},
"device-info": {
"type": "pci",
"version": "1.0.0",
"pci": {
"pci-address": "0000:b1:02.7"
}
}
},{
"name": "minio-tenant/minio-sriov2",
"interface": "net2",
"ips": [
"10.56.218.100"
],
"mac": "66:a2:70:eb:5e:04",
"dns": {},
"device-info": {
"type": "pci",
"version": "1.0.0",
"pci": {
"pci-address": "0000:b1:14.0"
}
}
}]
k8s.v1.cni.cncf.io/networks: minio-sriov1,minio-sriov2
k8s.v1.cni.cncf.io/networks-status: |-
[{
"name": "default-cni-network",
"ips": [
"10.244.160.191"
],
"default": true,
"dns": {}
},{
"name": "minio-tenant/minio-sriov1",
"interface": "net1",
"ips": [
"10.56.217.100"
],
"mac": "6a:58:82:8a:93:7b",
"dns": {},
"device-info": {
"type": "pci",
"version": "1.0.0",
"pci": {
"pci-address": "0000:b1:02.7"
}
}
},{
"name": "minio-tenant/minio-sriov2",
"interface": "net2",
"ips": [
"10.56.218.100"
],
"mac": "66:a2:70:eb:5e:04",
"dns": {},
"device-info": {
"type": "pci",
"version": "1.0.0",
"pci": {
"pci-address": "0000:b1:14.0"
}
}
}]
kubernetes.io/psp: node-exporter
meta.helm.sh/release-name: minio-tenant
meta.helm.sh/release-namespace: minio-tenant
min.io/revision: "0"
creationTimestamp: "2022-04-27T08:09:45Z"
generateName: minio-tenant-ss-0-
labels:
app: minio
app.kubernetes.io/managed-by: Helm
controller-revision-hash: minio-tenant-ss-0-7976bbfbc6
statefulset.kubernetes.io/pod-name: minio-tenant-ss-0-0
spec:
affinity:
containers:
- args:
- :9090
env:
- name: MINIO_UPDATE
Using this regular expression:
networks-status:[\s\S]*?
(?:")(name)(?:":\s*")([\S]*)(?:",[\s]*)
(?:")(interface)(?:":\s*")([\S]*)(?:",[\s\S]*?)
(?:")(ips)(?:":\s*\[\s*")([\S]*)(?:")
[\s\S]*?(pod-name)(?::\s)([\S]*)
I would like to get the following output:
name
minio-tenant/minio-sriov1
interface
net1
ips
10.56.217.100
name
minio-tenant/minio-sriov2
interface
net2
ips
10.56.218.100
pod-name
minio-tenant-ss-0-0
It gets me:
name
minio-tenant/minio-sriov1
interface
net1
ips
10.56.217.100
pod-name
minio-tenant-ss-0-0
There is missing portion of IP:
name
minio-tenant/minio-sriov2
interface
net2
ips
10.56.218.100
If I use *
or +
to repeat on the data section, I am getting unexpected result.
networks-status:[\s\S]*?
(
(?:")(name)(?:":\s*")([\S]*)(?:",[\s]*)
(?:")(interface)(?:":\s*")([\S]*)(?:",[\s\S]*?)
(?:")(ips)(?:":\s*\[\s*")([\S]*)(?:")
)*
[\s\S]*?(pod-name)(?::\s)([\S]*)
Can you give some hints how I can get the expected results?