Skip to content

Commit

Permalink
Run a cronjob that generates monthly openshift usage report.
Browse files Browse the repository at this point in the history
The k8s cronjob uses an init container that downloads the metrics from the
previous month and then the main container generates the report and uploads
it to our B2 bucket.
  • Loading branch information
naved001 committed Mar 4, 2024
1 parent e9ae059 commit 588f7b4
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
resources:
- daily-openshift-metrics-collector-cronjob.yaml
- produce-report-cronjob.yaml
- metrics-downloader-configmap.yaml
9 changes: 9 additions & 0 deletions k8s/base/metrics-downloader-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: metrics-downloader
data:
script.sh: |
DIRECTORY_NAME=$(date --date="$(date +%Y-%m-15) -1 month" +'data_%Y-%m')
echo $DIRECTORY_NAME
aws s3 cp s3://openshift-metrics/$DIRECTORY_NAME/ /data --endpoint-url=https://s3.us-east-005.backblazeb2.com --recursive
66 changes: 66 additions & 0 deletions k8s/base/produce-report-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: produce-report
spec:
schedule: "0 13 1 * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: daily-openshift-metrics-collector
image: ghcr.io/cci-moc/openshift-usage-scripts:main
env:
- name: S3_OUTPUT_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: nerc-invoices-b2-bucket
key: access-key-id
- name: S3_OUTPUT_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: nerc-invoices-b2-bucket
key: secret-access-key
- name: CLIENT_ID
valueFrom:
secretKeyRef:
name: keycloak-client
key: client-id
- name: CLIENT_SECRET
valueFrom:
secretKeyRef:
name: keycloak-client
key: client-secret
volumeMounts:
- name: data-volume
mountPath: /data
command: ["/bin/sh", "-c", "cd /data && python /app/openshift_metrics/merge.py /data/*.json --upload-to-s3"]
initContainers:
- name: download-metrics
image: amazon/aws-cli
command: ["/bin/sh", "-c", "/script/script.sh"]
env:
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: openshift-metrics-b2-bucket
key: access-key-id
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: openshift-metrics-b2-bucket
key: secret-access-key
volumeMounts:
- name: data-volume
mountPath: /data
- name: metrics-downloader
mountPath: /script
volumes:
- name: data-volume
emptyDir: {}
- name: metrics-downloader
configMap:
name: metrics-downloader
defaultMode: 0555
restartPolicy: OnFailure
8 changes: 8 additions & 0 deletions k8s/overlay/dev/keycloak-client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: keycloak-client
type: Opaque
data:
client-id: id
client-secret: secret
2 changes: 2 additions & 0 deletions k8s/overlay/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ resources:
- ../../base
- openshift-metrics-b2-bucket.yaml
- metrics-reader-token.yaml
- nerc-invoices-b2-bucket.yaml
- keycloak-client.yaml
namespace: xdmod-reader
8 changes: 8 additions & 0 deletions k8s/overlay/dev/nerc-invoices-b2-bucket.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: nerc-invoices-b2-bucket
type: Opaque
data:
access-key-id: 1234
secret-access-key: secret

0 comments on commit 588f7b4

Please sign in to comment.