Skip to content

Commit 8867998

Browse files
authored
Fixed containerInventory image issue for digest image format (#1374)
* Fixed containerInventory image issue for guid image * Updated comment to include digest image format
1 parent d011f26 commit 8867998

File tree

3 files changed

+354
-5
lines changed

3 files changed

+354
-5
lines changed

source/plugins/go/input/lib/kubernetescontainerinventory.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ func GetContainerInventoryRecords(podItem map[string]interface{}, batchTime stri
166166

167167
func addImageInfoToContainerInventoryRecord(containerInventoryRecord map[string]interface{}, imageValue string) {
168168
// image can be in any one of below formats:
169-
// repository/image[:imagetag | @digest], repository/image:imagetag@digest, repo/image, image:imagetag, image@digest, image
170-
if imageValue == "" {
169+
// repository/image[:imagetag | @digest], repository/image:imagetag@digest, repo/image, image:imagetag, image@digest, image, digest
170+
// if the image is in digest format - which is expected in certain scenarios, we do not process the image
171+
if imageValue == "" || regexp.MustCompile(`^sha256:[a-fA-F0-9]{64}$`).MatchString(imageValue) {
171172
return
172173
}
173174
atLocation := strings.Index(imageValue, "@")

source/plugins/go/input/lib/testdata/pods1.json

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,353 @@
143143
}
144144
]
145145
},
146+
"spec": {
147+
"volumes": [
148+
{
149+
"name": "azure-ip-masq-agent-config-volume",
150+
"projected": {
151+
"sources": [
152+
{
153+
"configMap": {
154+
"name": "azure-ip-masq-agent-config",
155+
"items": [
156+
{
157+
"key": "ip-masq-agent",
158+
"path": "ip-masq-agent",
159+
"mode": 444
160+
}
161+
],
162+
"optional": true
163+
}
164+
},
165+
{
166+
"configMap": {
167+
"name": "azure-ip-masq-agent-config-reconciled",
168+
"items": [
169+
{
170+
"key": "ip-masq-agent-reconciled",
171+
"path": "ip-masq-agent-reconciled",
172+
"mode": 444
173+
}
174+
],
175+
"optional": true
176+
}
177+
}
178+
],
179+
"defaultMode": 420
180+
}
181+
},
182+
{
183+
"name": "iptableslock",
184+
"hostPath": {
185+
"path": "/run/xtables.lock",
186+
"type": "FileOrCreate"
187+
}
188+
}
189+
],
190+
"containers": [
191+
{
192+
"name": "azure-ip-masq-agent",
193+
"image": "mcr.microsoft.com/aks/ip-masq-agent-v2:v0.1.7@sha256:3a691ceb2fae32df0fbd04f17509babd82f4de3fd6a23f8d9f26381ac89c4822",
194+
"args": [
195+
"--v=2",
196+
"--resync-interval=60"
197+
],
198+
"env": [
199+
{
200+
"name": "KUBERNETES_PORT_443_TCP_ADDR",
201+
"value": "ci-logs-prod-aks-syslog-dns-1ebf13ac.hcp.eastus.azmk8s.io"
202+
},
203+
{
204+
"name": "KUBERNETES_PORT",
205+
"value": "tcp://ci-logs-prod-aks-syslog-dns-1ebf13ac.hcp.eastus.azmk8s.io:443"
206+
},
207+
{
208+
"name": "KUBERNETES_PORT_443_TCP",
209+
"value": "tcp://ci-logs-prod-aks-syslog-dns-1ebf13ac.hcp.eastus.azmk8s.io:443"
210+
},
211+
{
212+
"name": "KUBERNETES_SERVICE_HOST",
213+
"value": "ci-logs-prod-aks-syslog-dns-1ebf13ac.hcp.eastus.azmk8s.io"
214+
}
215+
],
216+
"resources": {
217+
"limits": {
218+
"cpu": "500m",
219+
"memory": "250Mi"
220+
},
221+
"requests": {
222+
"cpu": "100m",
223+
"memory": "50Mi"
224+
}
225+
},
226+
"volumeMounts": [
227+
{
228+
"name": "azure-ip-masq-agent-config-volume",
229+
"mountPath": "/etc/config"
230+
},
231+
{
232+
"name": "iptableslock",
233+
"mountPath": "/run/xtables.lock"
234+
}
235+
],
236+
"terminationMessagePath": "/dev/termination-log",
237+
"terminationMessagePolicy": "File",
238+
"imagePullPolicy": "IfNotPresent",
239+
"securityContext": {
240+
"capabilities": {
241+
"add": [
242+
"NET_ADMIN",
243+
"NET_RAW"
244+
]
245+
}
246+
}
247+
}
248+
],
249+
"restartPolicy": "Always",
250+
"terminationGracePeriodSeconds": 30,
251+
"dnsPolicy": "ClusterFirst",
252+
"serviceAccountName": "default",
253+
"serviceAccount": "default",
254+
"automountServiceAccountToken": false,
255+
"nodeName": "aks-newpool-21676506-vmss000000",
256+
"hostNetwork": true,
257+
"securityContext": {},
258+
"affinity": {
259+
"nodeAffinity": {
260+
"requiredDuringSchedulingIgnoredDuringExecution": {
261+
"nodeSelectorTerms": [
262+
{
263+
"matchFields": [
264+
{
265+
"key": "metadata.name",
266+
"operator": "In",
267+
"values": [
268+
"aks-newpool-21676506-vmss000000"
269+
]
270+
}
271+
]
272+
}
273+
]
274+
}
275+
}
276+
},
277+
"schedulerName": "default-scheduler",
278+
"tolerations": [
279+
{
280+
"key": "CriticalAddonsOnly",
281+
"operator": "Exists"
282+
},
283+
{
284+
"operator": "Exists",
285+
"effect": "NoExecute"
286+
},
287+
{
288+
"operator": "Exists",
289+
"effect": "NoSchedule"
290+
}
291+
],
292+
"priorityClassName": "system-node-critical",
293+
"priority": 2000001000,
294+
"enableServiceLinks": true,
295+
"preemptionPolicy": "PreemptLowerPriority"
296+
},
297+
"status": {
298+
"phase": "Running",
299+
"conditions": [
300+
{
301+
"type": "Initialized",
302+
"status": "True",
303+
"lastProbeTime": null,
304+
"lastTransitionTime": "2023-08-03T16:07:48Z"
305+
},
306+
{
307+
"type": "Ready",
308+
"status": "True",
309+
"lastProbeTime": null,
310+
"lastTransitionTime": "2023-08-03T16:07:53Z"
311+
},
312+
{
313+
"type": "ContainersReady",
314+
"status": "True",
315+
"lastProbeTime": null,
316+
"lastTransitionTime": "2023-08-03T16:07:53Z"
317+
},
318+
{
319+
"type": "PodScheduled",
320+
"status": "True",
321+
"lastProbeTime": null,
322+
"lastTransitionTime": "2023-08-03T16:07:46Z"
323+
}
324+
],
325+
"hostIP": "10.224.0.6",
326+
"podIP": "10.224.0.6",
327+
"podIPs": [
328+
{
329+
"ip": "10.224.0.6"
330+
}
331+
],
332+
"startTime": "2023-08-03T16:07:48Z",
333+
"containerStatuses": [
334+
{
335+
"name": "azure-ip-masq-agent",
336+
"state": {
337+
"running": {
338+
"startedAt": "2023-08-03T16:07:52Z"
339+
}
340+
},
341+
"lastState": {},
342+
"ready": true,
343+
"restartCount": 0,
344+
"image": "sha256:7f0239fd72a8664f0cc0c4203a7bbb616d3de1b64d1dac9094a5a28fb2b750b4",
345+
"imageID": "mcr.microsoft.com/aks/ip-masq-agent-v2@sha256:3a691ceb2fae32df0fbd04f17509babd82f4de3fd6a23f8d9f26381ac89c4822",
346+
"containerID": "containerd://3b988c9fb1dad91e191fbbc8f0db13c37eeaf9a0002b30e75b4fb62a37ee54eb",
347+
"started": true
348+
}
349+
],
350+
"qosClass": "Burstable"
351+
}
352+
},
353+
{
354+
"metadata": {
355+
"name": "azure-ip-masq-agent-jlfv4",
356+
"generateName": "azure-ip-masq-agent-",
357+
"namespace": "kube-system",
358+
"uid": "072529c3-4297-4d1c-96df-8b8a43ba8932",
359+
"resourceVersion": "72098978",
360+
"creationTimestamp": "2023-08-03T16:07:46Z",
361+
"labels": {
362+
"controller-revision-hash": "86d676b776",
363+
"k8s-app": "azure-ip-masq-agent",
364+
"kubernetes.azure.com/managedby": "aks",
365+
"pod-template-generation": "4",
366+
"tier": "node"
367+
},
368+
"annotations": {
369+
"kubernetes.io/config.seen": "2023-08-03T16:07:48.216168377Z",
370+
"kubernetes.io/config.source": "api"
371+
},
372+
"ownerReferences": [
373+
{
374+
"apiVersion": "apps/v1",
375+
"kind": "DaemonSet",
376+
"name": "azure-ip-masq-agent",
377+
"uid": "72b38180-3dda-4f4c-be06-b2d5adc02ac1",
378+
"controller": true,
379+
"blockOwnerDeletion": true
380+
}
381+
],
382+
"managedFields": [
383+
{
384+
"manager": "kube-controller-manager",
385+
"operation": "Update",
386+
"apiVersion": "v1",
387+
"time": "2023-08-03T16:07:46Z",
388+
"fieldsType": "FieldsV1",
389+
"fieldsV1": {
390+
"f:metadata": {
391+
"f:generateName": {},
392+
"f:labels": {
393+
".": {},
394+
"f:controller-revision-hash": {},
395+
"f:k8s-app": {},
396+
"f:kubernetes.azure.com/managedby": {},
397+
"f:pod-template-generation": {},
398+
"f:tier": {}
399+
},
400+
"f:ownerReferences": {
401+
".": {},
402+
"k:{\"uid\":\"72b38180-3dda-4f4c-be06-b2d5adc02ac1\"}": {}
403+
}
404+
},
405+
"f:spec": {
406+
"f:affinity": {
407+
".": {},
408+
"f:nodeAffinity": {
409+
".": {},
410+
"f:requiredDuringSchedulingIgnoredDuringExecution": {}
411+
}
412+
},
413+
"f:automountServiceAccountToken": {},
414+
"f:containers": {
415+
"k:{\"name\":\"azure-ip-masq-agent\"}": {
416+
".": {},
417+
"f:args": {},
418+
"f:image": {},
419+
"f:imagePullPolicy": {},
420+
"f:name": {},
421+
"f:resources": {
422+
".": {},
423+
"f:limits": {
424+
".": {},
425+
"f:cpu": {},
426+
"f:memory": {}
427+
},
428+
"f:requests": {
429+
".": {},
430+
"f:cpu": {},
431+
"f:memory": {}
432+
}
433+
},
434+
"f:securityContext": {
435+
".": {},
436+
"f:capabilities": {
437+
".": {},
438+
"f:add": {}
439+
}
440+
},
441+
"f:terminationMessagePath": {},
442+
"f:terminationMessagePolicy": {},
443+
"f:volumeMounts": {
444+
".": {},
445+
"k:{\"mountPath\":\"/etc/config\"}": {
446+
".": {},
447+
"f:mountPath": {},
448+
"f:name": {}
449+
},
450+
"k:{\"mountPath\":\"/run/xtables.lock\"}": {
451+
".": {},
452+
"f:mountPath": {},
453+
"f:name": {}
454+
}
455+
}
456+
}
457+
},
458+
"f:dnsPolicy": {},
459+
"f:enableServiceLinks": {},
460+
"f:hostNetwork": {},
461+
"f:priorityClassName": {},
462+
"f:restartPolicy": {},
463+
"f:schedulerName": {},
464+
"f:securityContext": {},
465+
"f:terminationGracePeriodSeconds": {},
466+
"f:tolerations": {},
467+
"f:volumes": {
468+
".": {},
469+
"k:{\"name\":\"azure-ip-masq-agent-config-volume\"}": {
470+
".": {},
471+
"f:name": {},
472+
"f:projected": {
473+
".": {},
474+
"f:defaultMode": {},
475+
"f:sources": {}
476+
}
477+
},
478+
"k:{\"name\":\"iptableslock\"}": {
479+
".": {},
480+
"f:hostPath": {
481+
".": {},
482+
"f:path": {},
483+
"f:type": {}
484+
},
485+
"f:name": {}
486+
}
487+
}
488+
}
489+
}
490+
}
491+
]
492+
},
146493
"spec": {
147494
"volumes": [
148495
{

source/plugins/ruby/kubernetes_container_inventory.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ def getContainerInventoryRecords(podItem, batchTime, clusterCollectEnvironmentVa
139139

140140
def addImageInfoToContainerInventoryRecord(containerInventoryRecord, imageValue)
141141
begin
142-
if imageValue.nil? || imageValue.empty?
142+
# image can be in any one of below formats:
143+
# repository/image[:imagetag | @digest], repository/image:imagetag@digest, repo/image, image:imagetag, image@digest, image, digest
144+
# if the image is in digest format - which is expected in certain scenarios, we do not process the image
145+
if imageValue.nil? || imageValue.empty? || imageValue.match?(/^sha256:[a-fA-F0-9]{64}$/)
143146
return
144147
end
145-
# image can be in any one of below formats:
146-
# repository/image[:imagetag | @digest], repository/image:imagetag@digest, repo/image, image:imagetag, image@digest, image
147148
# Find delimiters in image format
148149
atLocation = imageValue.index("@")
149150
isDigestSpecified = false

0 commit comments

Comments
 (0)