Skip to content

Commit

Permalink
Merge pull request #127 from dirgim/dptp-image-source
Browse files Browse the repository at this point in the history
[CVP-1713] Add a playbook for parsing collected image pull events
  • Loading branch information
dirgim authored Mar 10, 2021
2 parents a808586 + e3d785b commit 5635b9c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
18 changes: 18 additions & 0 deletions parse-collected-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: "Parse the collected image pull events"
hosts: all
become: false
gather_facts: false

vars:
run_upstream: false
operator_work_dir: "/home/jenkins/agent/test-operator"
work_dir: "{{ lookup('env', 'WORKSPACE') }}"
collect_pull_events: false

tasks:
- name: "Parse the collected image pull events"
include_role:
name: collect_modified_images
vars:
events_file_path: "{{ work_dir }}/image_pull_events.json"
1 change: 1 addition & 0 deletions roles/collect_modified_images/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pulled_images: []
events_file_path: /tmp/events.json
deployment_start_time: 1970-01-01T00:00:00Z
collect_pull_events: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -o nounset
set -o errexit
set -o pipefail

# Collect all image pull events from the testing cluster
# The output will contain the timestamp and the event message
# in a comma-separated value format

PULL_EVENTS_ART="${ARTIFACT_DIR}/image_pull_events.csv"
echo "Collecting all image pull events from the testing cluster in ${PULL_EVENTS_ART}"
oc get events --all-namespaces --field-selector reason==Pulling -o go-template='{{range .items}}{{.lastTimestamp}},{{.message}}{{"\n"}}{{end}}' > "${PULL_EVENTS_ART}"
30 changes: 19 additions & 11 deletions roles/collect_modified_images/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@
# should be run immediately after the deployment, there should be no need to filter
# images pulled after the deployment.

- name: "Set the output CSV file location"
set_fact:
image_pull_events: "{{ work_dir }}/image_pull_events.csv"
when: image_pull_events is not defined


- name: "Generate events.json"
shell: "{{ oc_bin_path }} {% raw %}get events --all-namespaces --field-selector reason==Pulling -o go-template='{{range .items}}{{.lastTimestamp}},{{.message}}{{\"\\n\"}}{{end}}'{% endraw %}"
- name: "Collect the image pull events from the cluster in a CSV format"
shell: "{{ lookup('file', 'optional-operators-cvp-common-test-commands.sh') }}"
environment:
KUBECONFIG: "{{ kubeconfig_path }}"
register: events
ARTIFACT_DIR: "{{ work_dir }}"
when: collect_pull_events|bool

- name: "Read the resulting file and split it by lines"
set_fact:
image_pull_events_lines: "{{ lookup('file', image_pull_events).splitlines() }}"

- name: "get list of images in events.json"
- name: "Filter the list of images in the image_pull_events.csv by timestamp"
include_tasks: parse_image_names.yml
with_items:
- "{{ events.stdout_lines }}"
- "{{ image_pull_events_lines }}"

- name: "Print images"
- name: "Print filtered images"
debug:
msg: "pulled images: {{ pulled_images }}"

- name: "Save images to file"
module: copy
content: "{{ pulled_images | to_json }}"
dest: "{{ events_file_path }}"
- name: "Save images to an output json file"
copy:
content: "{{ pulled_images | to_json }}"
dest: "{{ events_file_path }}"
delegate_to: localhost

0 comments on commit 5635b9c

Please sign in to comment.