Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pruning images using CronJobs #4

Merged
merged 1 commit into from Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -104,6 +104,13 @@ Role Variables
osbs_sources_command: fedpkg sources
osbs_source_registry_uri: https://source.registry.fedoraproject.org # Empty default value

# Pruning
osbs_prune: false
osbs_prune_schedule: '0 0 */8 * *'
osbs_prune_secret: ''
osbs_prune_image: ''
osbs_prune_commands: ["/prune.sh"]

For a full list, see defaults/main.yml

Dependencies
Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Expand Up @@ -39,3 +39,9 @@ osbs_build_json_dir: /usr/share/osbs
osbs_sources_command: fedpkg sources
osbs_vendor: Fedora Project
osbs_nodeselector: ''

osbs_prune: false
osbs_prune_schedule: '0 0 */8 * *'
osbs_prune_secret: ''
osbs_prune_image: ''
osbs_prune_commands: ["/prune.sh"]
20 changes: 20 additions & 0 deletions tasks/main.yml
Expand Up @@ -188,5 +188,25 @@
tags:
- oc

- name: copy prune cronjob yaml
template:
src: openshift-prune-cronjob.yml.j2
dest: "{{ osbs_openshift_home }}/{{ inventory_hostname }}-{{ osbs_namespace }}-prune-cronjob.yml"
register: yaml_cronjob
when: osbs_prune
tags:
- oc

- name: import prune cronjob yaml
command: >
oc replace
--namespace={{ osbs_namespace }}
--force=true
--filename={{ osbs_openshift_home }}/{{ inventory_hostname }}-{{ osbs_namespace }}-prune-cronjob.yml
environment: "{{ osbs_environment }}"
when: osbs_prune and yaml_cronjob.changed
tags:
- oc

- include: orchestrator.yml
when: osbs_orchestrator
26 changes: 26 additions & 0 deletions templates/openshift-prune-cronjob.yml.j2
@@ -0,0 +1,26 @@
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
name: build-pruner
spec:
schedule: "{{ osbs_prune_schedule }}"
jobTemplate:
spec:
template:
spec:
volumes:
- name: token
secret:
defaultMode: 420
secretName: {{ osbs_prune_secret }}
containers:
- name: build-pruner
image: {{ osbs_prune_image }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this image look like? Will it be maintained by OpenShift via a BuildConfig?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this image look like? Will it be maintained by OpenShift via a BuildConfig?

The most easy way to that is to include necessary utils and scripts in the buildroot. For other instances it could be a separate image with tools only

{-% if osbs_prune_commands %}
command: {{ osbs_prune_commands }}
{% endif -%}
volumeMounts:
- mountPath: /token
name: token
readOnly: true
restartPolicy: Never