File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "io/ioutil"
66 "os"
77 "path/filepath"
8+ "regexp"
89 "runtime"
910 "strings"
1011
@@ -227,6 +228,7 @@ func getImagesFromContainers(containers []corev1.Container) []string {
227228 var images []string
228229
229230 var imgStringsToFilter []string
231+ var regexToFilter []string
230232
231233 //Work-around for mis-identified image parameters that include a URL
232234 imgStringsToFilter = append (imgStringsToFilter , "http://" )
@@ -243,6 +245,9 @@ func getImagesFromContainers(containers []corev1.Container) []string {
243245 imgStringsToFilter = append (imgStringsToFilter , ":critical" )
244246 imgStringsToFilter = append (imgStringsToFilter , ":off" )
245247
248+ // Looking for strings like 0.0.0.0:5332
249+ regexToFilter = append (regexToFilter , ".*\\ d*\\ .\\ d*:\\ d" )
250+
246251 for _ , container := range containers {
247252 images = append (images , container .Image )
248253
@@ -267,6 +272,14 @@ func getImagesFromContainers(containers []corev1.Container) []string {
267272 }
268273 }
269274
275+ for _ , regexpPattern := range regexToFilter {
276+ found , _ := regexp .MatchString (regexpPattern , image )
277+
278+ if found {
279+ skiploop = true
280+ }
281+ }
282+
270283 if skiploop {
271284 continue
272285 }
Original file line number Diff line number Diff line change @@ -81,3 +81,24 @@ func TestGetImagesFromContainers_WithLogComponent(t *testing.T) {
8181 }
8282
8383}
84+
85+ func TestGetImagesFromContainers_WithIPParameter (t * testing.T ) {
86+ containers := []corev1.Container {
87+ {
88+ Image : "baseimage:v1" ,
89+ Args : []string {
90+ "--serving-address=0.0.0.0:6443" ,
91+ },
92+ },
93+ }
94+ actual := getImagesFromContainers (containers )
95+
96+ if ! contains (actual , "baseimage:v1" ) {
97+ t .Errorf ("expected baseimage:v1 to exist in list of images but it did not: %v" , actual )
98+ }
99+
100+ if contains (actual , "0.0.0.0:6443" ) {
101+ t .Errorf ("Invalid image parsing for args contain an ip addresses: %v" , actual )
102+ }
103+
104+ }
You can’t perform that action at this time.
0 commit comments