oc new-project cleaner
oc create -f openshift/openshift-job-cleaner.list.yml
This will create the objects you need and a default configuration map.
You will then need to configure your serviceaccount to have access to the projects it should be able to clean. It is recommended to give
the sa a cluster wide edit role and use the blacklist configuration to exclude unwanted namespaces.
oc adm policy add-cluster-role-to-user edit system:serviceaccount:cleaner:openshift-job-cleaner
See example config for an example configuration.
activeDeadlineSecondsmax-age is in MINUTES.
Any namespace in the blacklist is excluded by the job cleaner for both successful and failed jobs
The application is configured using environmental variables
The following secrets should be mounted in the container, usually this is handled automatically by openshift
As you probably want to have good logging for a service that runs over all your namespaces this project uses logrus which allows you to provide your own adapters and easily integrate logging systems without extensive code changes.
Currently it is only configured to use sentry but this can be easily altered from main.go
the openshift folder contains openshift yml files that can be used to create and run jobs
Creates the ServiceAccount, ConfigMap and CronJob needed for the service. Does NOT give permissions to the ServiceAccount to access other namespaces, this should be done manually or added at a cluster level
oc new-project cleaner
oc create -f openshift/openshift-job-cleaner.list.yml
oc adm policy add-cluster-role-to-user edit system:serviceaccount:cleaner:openshift-job-cleaner
One off job execution with dynamic name, should be used in the namespace with the ServiceAccount configured
oc project cleaner
oc create -f openshift/openshift-job-cleaner.job.yml
Example appliation configuration file showing all usable keys and with annotations
For development you will need a few tools and dependencies installed as well as docker and oc
go get -u github.com/golang/dep/cmd/dep
go get -u github.com/go-task/task/cmd/task
go get -u github.com/alecthomas/gometalinter
go get -u github.com/haya14busa/goverage
dep ensure
# NON GOLANG DEPENDENCIES
# See https://github.com/aelsabbahy/goss/releases for release versions
curl -L https://github.com/aelsabbahy/goss/releases/download/_VERSION_/goss-linux-amd64 -o /usr/local/bin/goss
chmod +rx /usr/local/bin/goss
#https://github.com/hadolint/hadolint/releases
brew install hadolint
This should allow you to run all of the tasks in the taskfile successfully.
The task test:integration will take ~15 minutes to complete and involves starting and stopping a local oc cluster .
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: ServiceAccount
metadata:
name: openshift-job-cleaner
- apiVersion: v1
data:
ojc.yml: >-
blacklist:
- default
- openshift-infra
- logging
- kube-public
- kube-system
- management-infra
- openshift
default:
success:
max_age: 120
failure:
max_age: 120
kind: ConfigMap
metadata:
name: ojc.yml
- apiVersion: batch/v2alpha1
kind: ScheduledJob
metadata:
name: openshift-job-cleaner
spec:
concurrencyPolicy: Forbid
# every hour
schedule: "0 * * * *"
jobTemplate:
spec:
completions: 1
parallelism: 1
template:
spec:
activeDeadlineSeconds: 300
serviceAccountName: openshift-job-cleaner
volumes:
- configMap:
defaultMode: 420
name: ojc.yml
name: ojc-config-file
containers:
- name: openshift-job-cleaner
image: ninech/openshift-job-cleaner:latest
env:
- name: SENTRY_DSN
value: 'https://<key>:<secret>@sentry.io/<project>'
volumeMounts:
- mountPath: /opt/ojc/
name: ojc-config-file
readOnly: true
restartPolicy: OnFailure
Content type
Image
Digest
Size
139.7 MB
Last updated
over 8 years ago
docker pull ninech/openshift-job-cleaner