Skip to content

Commit

Permalink
Update billing add on cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Saratura committed Dec 6, 2024
1 parent 3c51ae7 commit 7fffab9
Show file tree
Hide file tree
Showing 58 changed files with 82 additions and 70 deletions.
2 changes: 1 addition & 1 deletion class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ parameters:
appcat:
registry: ghcr.io
repository: vshn/appcat
tag: v4.116.0
tag: v4.116.1
functionAppcat:
registry: ${appcat:images:appcat:registry}
repository: ${appcat:images:appcat:repository}
Expand Down
26 changes: 11 additions & 15 deletions component/billing.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ local commonEnv = std.prune([
},
]);

local backfillCJ = function(name, query, sla, type)
local backfillCJ = function(name, query, sla, type, isAddOn)

local orgId = if type == 'cloud' then paramsBilling.prometheus.cloud_org_id else paramsBilling.prometheus.managed_org_id;

Expand All @@ -91,9 +91,11 @@ local backfillCJ = function(name, query, sla, type)

local instanceJsonnet = 'local labels = std.extVar("labels"); "%s" %% labels' % '%(cluster_id)s/%(label_appcat_vshn_io_claim_namespace)s/%(label_appcat_vshn_io_claim_name)s';

local instanceAddOnJsonnet = 'local labels = std.extVar("labels"); "%s" %% labels' % '%(cluster_id)s/%(label_appcat_vshn_io_claim_namespace)s/%(label_appcat_vshn_io_claim_name)s/%(label_appcat_vshn_io_addon_name)s';

local productID = 'appcat-vshn-%(name)s-%(sla)s' % { name: name, sla: sla };

local jobEnv = std.prune([
local jobEnv = function(isAddOn) std.prune([
{
name: 'AR_ORG_ID',
value: orgId,
Expand All @@ -108,7 +110,7 @@ local backfillCJ = function(name, query, sla, type)
},
{
name: 'AR_INSTANCE_JSONNET',
value: instanceJsonnet,
value: if isAddOn then instanceAddOnJsonnet else instanceJsonnet,
},
if itemGroupDescJsonnet != null then {
name: 'AR_ITEM_GROUP_DESCRIPTION_JSONNET',
Expand All @@ -123,12 +125,13 @@ local backfillCJ = function(name, query, sla, type)
value: paramsBilling.instanceUOM,
},
]);

cronjob.CronJob('%(product)s-%(type)s' % { product: escape(productID), type: type }, 'backfill', {
containers: [
{
name: 'backfill',
image: formatImage(params.images.reporting),
env+: commonEnv + jobEnv,
env+: commonEnv + jobEnv(isAddOn),
command: [ 'sh', '-c' ],
args: [
'appuio-reporting report --timerange 1h --begin=$(date -d "now -3 hours" -u +"%Y-%m-%dT%H:00:00Z") --repeat-until=$(date -u +"%Y-%m-%dT%H:00:00Z")',
Expand Down Expand Up @@ -185,14 +188,7 @@ local getPermutations = function(cloudQuery, managedQuery)
},
];

local generateAddOnsCloudAndManaged = function(name)
local queryName = if name == 'postgres' then name + 'ql' else name;
local managedQuery = getManagedQuery(queryName);
local cloudQuery = getCloudQuery(queryName);
local permutations = getPermutations(cloudQuery, managedQuery);
std.flatMap(function(r) [ backfillCJ(name, r.query, r.sla, r.type) ], permutations);

local generateCloudAndManaged = function(name)
local generateCloudAndManaged = function(name, isAddOn)

// For postgresql we have a missmatch between the label and the name in our definition.
local queryName = if name == 'postgres' then name + 'ql' else name;
Expand Down Expand Up @@ -223,11 +219,11 @@ local generateCloudAndManaged = function(name)
},
];

std.flatMap(function(r) [ backfillCJ(name, r.query, r.sla, r.type) ], permutations);
std.flatMap(function(r) [ backfillCJ(name, r.query, r.sla, r.type, isAddOn) ], permutations);

local vshnServices = common.FilterServiceByBoolean('billing');
local billingCronjobs = std.flattenArrays(std.flatMap(function(r) [ generateCloudAndManaged(r.name) ], vshnServices));
local billingAddOnsCronjobs = std.flattenArrays(std.flatMap(function(addOn) [ generateAddOnsCloudAndManaged(addOn) ], addOns));
local billingCronjobs = std.flattenArrays(std.flatMap(function(r) [ generateCloudAndManaged(r.name, false) ], vshnServices));
local billingAddOnsCronjobs = std.flattenArrays(std.flatMap(function(addOn) [ generateCloudAndManaged(addOn, true) ], addOns));

if paramsBilling.vshn.enableCronjobs then
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
argocd.argoproj.io/sync-wave: '-40'
name: function-appcat
spec:
package: ghcr.io/vshn/appcat:v4.116.0-func
package: ghcr.io/vshn/appcat:v4.116.1-func
runtimeConfigRef:
name: function-appcat
Original file line number Diff line number Diff line change
Expand Up @@ -11719,6 +11719,7 @@ spec:
type: boolean
type: object
service:
default: {}
description: Service contains PostgreSQL DBaaS specific
properties
properties:
Expand Down Expand Up @@ -11847,6 +11848,7 @@ spec:
- guaranteed
type: string
tls:
default: {}
description: TLS settings for the instance.
properties:
enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11705,6 +11705,7 @@ spec:
type: boolean
type: object
service:
default: {}
description: Service contains PostgreSQL DBaaS specific
properties
properties:
Expand Down Expand Up @@ -11833,6 +11834,7 @@ spec:
- guaranteed
type: string
tls:
default: {}
description: TLS settings for the instance.
properties:
enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
ingress_annotations: |
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
cert-manager.io/cluster-issuer: letsencrypt-staging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
isOpenshift: 'false'
maintenanceSA: helm-based-service-maintenance
mode: standalone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
ingress_annotations: |
cert-manager.io/cluster-issuer: letsencrypt-staging
nginx.ingress.kubernetes.io/enable-cors: "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
emailAlertingSmtpUsername: appcat@appuio.cloud
externalDatabaseConnectionsEnabled: 'true'
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
initContainers: '{"clusterReconciliationCycle": {"limits": {"cpu": "300m",
"memory": "200Mi"}, "requests": {"cpu": "100m", "memory": "100Mi"}}, "pgbouncerAuthFile":
{"limits": {"cpu": "300m", "memory": "500Mi"}, "requests": {"cpu": "100m",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
isOpenshift: 'false'
maintenanceSA: helm-based-service-maintenance
ownerGroup: vshn.appcat.vshn.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
- --secure-port=9443
- --tls-cert-file=/apiserver.local.config/certificates/tls.crt
- --tls-private-key-file=/apiserver.local.config/certificates/tls.key
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
env:
- name: PLANS_NAMESPACE
value: syn-appcat
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
envFrom:
- secretRef:
name: appcat-sla-reports-creds
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
name: sla-reporter
resources:
limits:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
value: 'true'
- name: APPCAT_SLI_VSHNMARIADB
value: 'true'
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
argocd.argoproj.io/sync-wave: '-40'
name: function-appcat
spec:
package: ghcr.io/vshn/appcat:v4.116.0-func
package: ghcr.io/vshn/appcat:v4.116.1-func
runtimeConfigRef:
name: function-appcat
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
- --secure-port=9443
- --tls-cert-file=/apiserver.local.config/certificates/tls.crt
- --tls-private-key-file=/apiserver.local.config/certificates/tls.key
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
value: 'false'
- name: APPCAT_SLI_VSHNMARIADB
value: 'false'
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion tests/golden/dev/appcat/appcat/10_function_appcat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
argocd.argoproj.io/sync-wave: '-40'
name: function-appcat
spec:
package: ghcr.io/vshn/appcat:v4.116.0-func
package: ghcr.io/vshn/appcat:v4.116.1-func
runtimeConfigRef:
name: function-appcat
2 changes: 2 additions & 0 deletions tests/golden/dev/appcat/appcat/20_xrd_vshn_keycloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11719,6 +11719,7 @@ spec:
type: boolean
type: object
service:
default: {}
description: Service contains PostgreSQL DBaaS specific
properties
properties:
Expand Down Expand Up @@ -11847,6 +11848,7 @@ spec:
- guaranteed
type: string
tls:
default: {}
description: TLS settings for the instance.
properties:
enabled:
Expand Down
2 changes: 2 additions & 0 deletions tests/golden/dev/appcat/appcat/20_xrd_vshn_nextcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11705,6 +11705,7 @@ spec:
type: boolean
type: object
service:
default: {}
description: Service contains PostgreSQL DBaaS specific
properties
properties:
Expand Down Expand Up @@ -11833,6 +11834,7 @@ spec:
- guaranteed
type: string
tls:
default: {}
description: TLS settings for the instance.
properties:
enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
ingress_annotations: |
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
cert-manager.io/cluster-issuer: letsencrypt-staging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
isOpenshift: 'false'
maintenanceSA: helm-based-service-maintenance
mode: standalone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
ingress_annotations: |
cert-manager.io/cluster-issuer: letsencrypt-staging
isOpenshift: 'false'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
emailAlertingSmtpUsername: appcat@appuio.cloud
externalDatabaseConnectionsEnabled: 'true'
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
initContainers: '{"clusterReconciliationCycle": {"limits": {"cpu": "300m",
"memory": "200Mi"}, "requests": {"cpu": "100m", "memory": "100Mi"}}, "pgbouncerAuthFile":
{"limits": {"cpu": "300m", "memory": "500Mi"}, "requests": {"cpu": "100m",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ spec:
emailAlertingSmtpHost: smtp.eu.mailgun.org:465
emailAlertingSmtpUsername: appcat@appuio.cloud
ignoreNamespaceForBilling: vshn-test
imageTag: v4.116.0
imageTag: v4.116.1
isOpenshift: 'false'
maintenanceSA: helm-based-service-maintenance
ownerGroup: vshn.appcat.vshn.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
- --secure-port=9443
- --tls-cert-file=/apiserver.local.config/certificates/tls.crt
- --tls-private-key-file=/apiserver.local.config/certificates/tls.key
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
env:
- name: PLANS_NAMESPACE
value: syn-appcat
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
envFrom:
- secretRef:
name: appcat-sla-reports-creds
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
name: sla-reporter
resources:
limits:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
value: 'true'
- name: APPCAT_SLI_VSHNMARIADB
value: 'true'
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
name: vcluster-kubeconfig
- name: PLANS_NAMESPACE
value: syn-appcat
image: ghcr.io/vshn/appcat:v4.116.0
image: ghcr.io/vshn/appcat:v4.116.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ metadata:
argocd.argoproj.io/sync-wave: '-40'
name: function-appcat
spec:
package: ghcr.io/vshn/appcat:v4.116.0-func
package: ghcr.io/vshn/appcat:v4.116.1-func
runtimeConfigRef:
name: function-appcat
Original file line number Diff line number Diff line change
Expand Up @@ -11719,6 +11719,7 @@ spec:
type: boolean
type: object
service:
default: {}
description: Service contains PostgreSQL DBaaS specific
properties
properties:
Expand Down Expand Up @@ -11847,6 +11848,7 @@ spec:
- guaranteed
type: string
tls:
default: {}
description: TLS settings for the instance.
properties:
enabled:
Expand Down
Loading

0 comments on commit 7fffab9

Please sign in to comment.