Skip to content

Commit

Permalink
add dbaas cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
mweibel committed Dec 9, 2022
1 parent a9e67f0 commit 6ab71f7
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 69 deletions.
13 changes: 11 additions & 2 deletions component/class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@ parameters:
repository: 'vshn/exoscale-metrics-collector'
tag: 'v0.3.0'
# Times in UTC! Don't run job around midnight as exoscale API may return incomplete data
# default: Every day at minute 10 past hour 10, 16 and 20.
schedule: '10 10,16,20 * * *'

objectStorage:
# schedule for objectstorage cronjob
# default: Every day at minute 10 past hour 10, 16 and 20.
schedule: '10 10,16,20 * * *'

dbaas:
# enable DBaaS cronjob in addition to objectstorage cronjob.
enabled: false
# schedule for DBaaS cronjob every 15min
schedule: '*/15 * * * *'
143 changes: 78 additions & 65 deletions component/component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,82 @@ local secrets = [
for s in std.objectFields(params.secrets)
];

local cronjob(name, subcommand, schedule) = {
kind: 'CronJob',
apiVersion: 'batch/v1',
metadata: {
name: name,
namespace: paramsACR.namespace,
labels+: labels,
},
spec: {
concurrencyPolicy: 'Forbid',
failedJobsHistoryLimit: 5,
jobTemplate: {
spec: {
template: {
spec: {
restartPolicy: 'OnFailure',
containers: [
{
name: 'exoscale-metrics-collector-backfill',
image: collectorImage,
args: [
subcommand,
],
envFrom: [
{
secretRef: {
name: credentials_secret_name,
},
},
],
env: [
{
name: 'password',
valueFrom: {
secretKeyRef: {
key: 'password',
name: 'reporting-db',
},
},
},
{
name: 'username',
valueFrom: {
secretKeyRef: {
key: 'username',
name: 'reporting-db',
},
},
},
{
name: 'ACR_DB_URL',
value: 'postgres://$(username):$(password)@%(host)s:%(port)s/%(name)s?%(parameters)s' % paramsACR.database,
},
],
resources: {},
},
],
},
},
},
},
schedule: schedule,
successfulJobsHistoryLimit: 3,
},
};

local objectStorageSchedule =
if std.objectHas(params, 'schedule') then
std.trace(
'Parameter `schedule` is deprecated,'
+ ' please use parameter `objectStorage.schedule` instead',
params.schedule
)
else
params.objectStorage.schedule;

{
assert params.secrets != null : 'secrets must be set.',
assert params.secrets.credentials != null : 'secrets.credentials must be set.',
Expand All @@ -39,69 +115,6 @@ local secrets = [

secrets: std.filter(function(it) it != null, secrets),

cronjob: {
kind: 'CronJob',
apiVersion: 'batch/v1',
metadata: {
name: alias,
namespace: paramsACR.namespace,
labels+: labels,
},
spec: {
concurrencyPolicy: 'Forbid',
failedJobsHistoryLimit: 5,
jobTemplate: {
spec: {
template: {
spec: {
restartPolicy: 'OnFailure',
containers: [
{
name: 'exoscale-metrics-collector-backfill',
image: collectorImage,
args: [
'objectstorage',
],
envFrom: [
{
secretRef: {
name: credentials_secret_name
}
}
],
env: [
{
name: 'password',
valueFrom: {
secretKeyRef: {
key: 'password',
name: 'reporting-db',
},
},
},
{
name: 'username',
valueFrom: {
secretKeyRef: {
key: 'username',
name: 'reporting-db',
},
},
},
{
name: 'ACR_DB_URL',
value: 'postgres://$(username):$(password)@%(host)s:%(port)s/%(name)s?%(parameters)s' % paramsACR.database,
},
],
resources: {},
},
],
},
},
},
},
schedule: params.schedule,
successfulJobsHistoryLimit: 3,
},
},
objectStorageCronjob: cronjob(alias + '-objectstorage', 'objectstorage', objectStorageSchedule),
[if params.dbaas.enabled then 'dbaasCronjob']: cronjob(alias + '-dbaas', 'dbaas', params.dbaas.schedule),
}
3 changes: 3 additions & 0 deletions component/tests/exoscale-metrics-collector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ parameters:
parameters: 'sslmode=disable'
password: 'passw0rd'
port: 5432
exoscale_metrics_collector:
dbaas:
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
app.kubernetes.io/managed-by: commodore
app.kubernetes.io/name: exoscale-metrics-collector
app.kubernetes.io/part-of: appuio-cloud-reporting
name: collector-cloudscale-lpg-2
name: collector-cloudscale-lpg-2-objectstorage
namespace: appuio-cloud-reporting
spec:
concurrencyPolicy: Forbid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: batch/v1
kind: CronJob
metadata:
labels:
app.kubernetes.io/component: exoscale-metrics-collector
app.kubernetes.io/managed-by: commodore
app.kubernetes.io/name: exoscale-metrics-collector
app.kubernetes.io/part-of: appuio-cloud-reporting
name: exoscale-metrics-collector-dbaas
namespace: appuio-cloud-reporting
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
containers:
- args:
- dbaas
env:
- name: password
valueFrom:
secretKeyRef:
key: password
name: reporting-db
- name: username
valueFrom:
secretKeyRef:
key: username
name: reporting-db
- name: ACR_DB_URL
value: postgres://$(username):$(password)@reporting-db.appuio-reporting.svc:5432/reporting?sslmode=disable
envFrom:
- secretRef:
name: credentials-exoscale-metrics-collector
image: ghcr.io/vshn/exoscale-metrics-collector:v0.3.0
name: exoscale-metrics-collector-backfill
resources: {}
restartPolicy: OnFailure
schedule: '*/15 * * * *'
successfulJobsHistoryLimit: 3
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
app.kubernetes.io/managed-by: commodore
app.kubernetes.io/name: exoscale-metrics-collector
app.kubernetes.io/part-of: appuio-cloud-reporting
name: exoscale-metrics-collector
name: exoscale-metrics-collector-objectstorage
namespace: appuio-cloud-reporting
spec:
concurrencyPolicy: Forbid
Expand Down

0 comments on commit 6ab71f7

Please sign in to comment.