-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathscan-yaml.awk
98 lines (82 loc) · 1.5 KB
/
scan-yaml.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/awk
BEGIN {
im="";
n_space=c_space=0;
matched=1;
}
function saveim() {
split(im,ims,",");
for (i in ims) {
if (ims[i]!="" && (matched || labels=="*")) {
images[ims[i]]=1;
}
}
im="";
matched=1;
}
/containers:/ {
c_space=index($0,"containers:");
}
/initContainers:/ {
c_space=index($0,"initContainers:");
}
/image:/ && c_space==0 {
saveim();
im=$NF;
}
/image:/ && c_space>0 {
im=im","$NF
}
/VCAC_IMAGE:/ {
im=im","$NF
}
/- node\..*==.*/ && labels!="*" {
gsub(/[" ]/,"",$2);
if (index(labels,$2)==0) {
im="";
matched=0;
}
}
/- node\..*!=.*/ && labels!="*" {
gsub(/[" ]/,"",$2);
gsub(/!=/,"==",$2);
if (index(labels,$2)!=0) {
im="";
matched=0;
}
}
/^\s*---\s*$/ || /^\s*$/ {
n_space=c_space=0;
saveim();
}
/- key:/ && n_space>0 {
match($0, /^ */);
if (RLENGTH > n_space) key=$3;
}
/operator:/ && n_space>0 {
match($0, /^ */);
if (RLENGTH > n_space) operator=$2
}
/- ".*"/ && n_space>0 {
match($0, /^ */);
if (RLENGTH > n_space) {
label_eqn=key":"$2
gsub(/[" ]/,"",label_eqn);
i=index(labels,label_eqn);
if ((operator=="In" && i==0) || (operator=="NotIn" && i!=0)) {
im="";
matched=0;
}
}
}
/nodeAffinity:/ {
n_space=index($0,"nodeAffinity:");
}
/podAffinity:/ || /podAntiAffinity/ {
n_space=0;
}
END {
saveim();
for (im in images)
print(im);
}