Skip to content

Commit

Permalink
Merge pull request #51 from vshn/fix/no-acr-params
Browse files Browse the repository at this point in the history
Stop referencing APPUiO Cloud Reporting parameters
  • Loading branch information
glrf authored Feb 28, 2023
2 parents 4108784 + 2dec9a0 commit 4f33c07
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 113 deletions.
3 changes: 3 additions & 0 deletions component/class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ parameters:
=_metadata:
multi_instance: true

namespace: appuio-cloud-reporting
database: {}

secrets:
exoscale:
credentials:
Expand Down
51 changes: 25 additions & 26 deletions component/component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local kap = import 'lib/kapitan.libjsonnet';
local inv = kap.inventory();
local params = inv.parameters.billing_collector_cloudservices;
local paramsACR = inv.parameters.appuio_cloud_reporting;
local kube = import 'lib/kube.libjsonnet';
local com = import 'lib/commodore.libjsonnet';
local collectorImage = '%(registry)s/%(repository)s:%(tag)s' % params.images.collector;
Expand All @@ -22,7 +21,7 @@ local secret(key) = [
if params.secrets[key][s] != null then
kube.Secret(s + alias_suffix) {
metadata+: {
namespace: paramsACR.namespace,
namespace: params.namespace,
},
} + com.makeMergeable(params.secrets[key][s])
for s in std.objectFields(params.secrets[key])
Expand All @@ -33,7 +32,7 @@ local cronjob(name, args, schedule) = {
apiVersion: 'batch/v1',
metadata: {
name: name,
namespace: paramsACR.namespace,
namespace: params.namespace,
labels+: labels,
},
spec: {
Expand Down Expand Up @@ -77,7 +76,7 @@ local cronjob(name, args, schedule) = {
},
{
name: 'ACR_DB_URL',
value: 'postgres://$(username):$(password)@%(host)s:%(port)s/%(name)s?%(parameters)s' % paramsACR.database,
value: 'postgres://$(username):$(password)@%(host)s:%(port)s/%(name)s?%(parameters)s' % params.database,
},
],
resources: {},
Expand All @@ -95,29 +94,29 @@ local cronjob(name, args, schedule) = {
assert params.exoscale.enabled != params.cloudscale.enabled : 'only one of the components can be enabled: cloudscale or exoscale. not both and not neither.';

(if params.exoscale.enabled then {
local secrets = params.secrets['exoscale'],
assert secrets != null : 'secrets must be set.',
assert secrets.credentials != null : 'secrets.credentials must be set.',
assert secrets.credentials.stringData != null : 'secrets.credentials.stringData must be set.',
assert secrets.credentials.stringData.EXOSCALE_API_KEY != null : 'secrets.credentials.stringData.EXOSCALE_API_KEY must be set.',
assert secrets.credentials.stringData.EXOSCALE_API_SECRET != null : 'secrets.credentials.stringData.EXOSCALE_API_SECRET must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_URL != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_URL must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN must be set.',
local secrets = params.secrets.exoscale,
assert secrets != null : 'secrets must be set.',
assert secrets.credentials != null : 'secrets.credentials must be set.',
assert secrets.credentials.stringData != null : 'secrets.credentials.stringData must be set.',
assert secrets.credentials.stringData.EXOSCALE_API_KEY != null : 'secrets.credentials.stringData.EXOSCALE_API_KEY must be set.',
assert secrets.credentials.stringData.EXOSCALE_API_SECRET != null : 'secrets.credentials.stringData.EXOSCALE_API_SECRET must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_URL != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_URL must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN must be set.',

secrets: std.filter(function(it) it != null, secret('exoscale')),
objectStorageCronjob: cronjob(alias + '-objectstorage', ['exoscale', 'objectstorage'], params.exoscale.objectStorage.schedule),
[if params.exoscale.dbaas.enabled then 'dbaasCronjob']: cronjob(alias + '-dbaas', ['exoscale', 'dbaas'], params.exoscale.dbaas.schedule),
} else {})
secrets: std.filter(function(it) it != null, secret('exoscale')),
objectStorageCronjob: cronjob(alias + '-objectstorage', [ 'exoscale', 'objectstorage' ], params.exoscale.objectStorage.schedule),
[if params.exoscale.dbaas.enabled then 'dbaasCronjob']: cronjob(alias + '-dbaas', [ 'exoscale', 'dbaas' ], params.exoscale.dbaas.schedule),
} else {})
+
(if params.cloudscale.enabled then {
local secrets = params.secrets['cloudscale'],
assert secrets != null : 'secrets must be set.',
assert secrets.credentials != null : 'secrets.credentials must be set.',
assert secrets.credentials.stringData != null : 'secrets.credentials.stringData must be set.',
assert secrets.credentials.stringData.CLOUDSCALE_API_TOKEN != null : 'secrets.credentials.stringData.CLOUDSCALE_API_TOKEN must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_URL != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_URL must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN must be set.',
local secrets = params.secrets.cloudscale,
assert secrets != null : 'secrets must be set.',
assert secrets.credentials != null : 'secrets.credentials must be set.',
assert secrets.credentials.stringData != null : 'secrets.credentials.stringData must be set.',
assert secrets.credentials.stringData.CLOUDSCALE_API_TOKEN != null : 'secrets.credentials.stringData.CLOUDSCALE_API_TOKEN must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_URL != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_URL must be set.',
assert secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN != null : 'secrets.credentials.stringData.KUBERNETES_SERVER_TOKEN must be set.',

secrets: std.filter(function(it) it != null, secret('cloudscale')),
[if params.cloudscale.objectStorage.enabled then 'objectStorageCronjob']: cronjob(alias + '-objectstorage', ['cloudscale', 'objectstorage'], params.cloudscale.objectStorage.schedule),
} else {})
secrets: std.filter(function(it) it != null, secret('cloudscale')),
[if params.cloudscale.objectStorage.enabled then 'objectStorageCronjob']: cronjob(alias + '-objectstorage', [ 'cloudscale', 'objectstorage' ], params.cloudscale.objectStorage.schedule),
} else {})
4 changes: 1 addition & 3 deletions component/tests/billing-collector-cloudservices.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
parameters:
appuio_cloud_reporting:
namespace: 'appuio-cloud-reporting'
billing_collector_cloudservices:
database:
name: 'reporting'
host: 'reporting-db.appuio-reporting.svc'
parameters: 'sslmode=disable'
password: 'passw0rd'
port: 5432
billing_collector_cloudservices:
exoscale:
enabled: true
dbaas:
Expand Down
4 changes: 1 addition & 3 deletions component/tests/cloudscale-metrics-collector.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
parameters:
appuio_cloud_reporting:
namespace: 'appuio-cloud-reporting'
billing_collector_cloudservices:
database:
name: 'reporting'
host: 'reporting-db.appuio-reporting.svc'
parameters: 'sslmode=disable'
password: 'passw0rd'
port: 5432
billing_collector_cloudservices:
cloudscale:
enabled: true
objectStorage:
Expand Down
4 changes: 1 addition & 3 deletions component/tests/collector-cloudscale-lpg-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ applications:
- metrics-collector as collector-cloudscale-lpg-2

parameters:
appuio_cloud_reporting:
namespace: 'appuio-cloud-reporting'
billing_collector_cloudservices:
database:
name: 'reporting'
host: 'reporting-db.appuio-reporting.svc'
parameters: 'sslmode=disable'
password: 'passw0rd'
port: 5432
billing_collector_cloudservices:
exoscale:
enabled: true
4 changes: 1 addition & 3 deletions component/tests/exoscale-metrics-collector.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
parameters:
appuio_cloud_reporting:
namespace: 'appuio-cloud-reporting'
billing_collector_cloudservices:
database:
name: 'reporting'
host: 'reporting-db.appuio-reporting.svc'
parameters: 'sslmode=disable'
password: 'passw0rd'
port: 5432
billing_collector_cloudservices:
exoscale:
enabled: true
dbaas:
Expand Down
26 changes: 26 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ The parent key for all of them is `metrics_collector`.
See xref:how-tos/installation.adoc[Installation] for a full example.
== `namespace`
[horizontal]
type:: string
default:: `${_instance}`
The namespace in which to deploy this component.
== `database`
[horizontal]
type:: dictionary
default::
+
[source,yaml]
----
host: null
port: 5432
name: appuio-cloud-reporting
username: appuio-cloud-reporting
password: null
parameters: ''
----
Dictionary managing the connection to the reporting database.
== `images`
[horizontal]
Expand Down
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module github.com/vshn/billing-collector-cloudservices
go 1.19

require (
github.com/appuio/appuio-cloud-reporting v0.7.1
github.com/appuio/appuio-cloud-reporting v0.10.0
github.com/cloudscale-ch/cloudscale-go-sdk/v2 v2.1.0
github.com/exoscale/egoscale v0.90.1
github.com/go-logr/logr v1.2.3
github.com/go-logr/zapr v1.2.3
github.com/google/uuid v1.3.0
github.com/jackc/pgx/v4 v4.17.2
github.com/jackc/pgx/v4 v4.18.1
github.com/jmoiron/sqlx v1.3.5
github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.24.1
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.24.4
github.com/vshn/provider-cloudscale v0.5.0
github.com/vshn/provider-exoscale v0.8.1
go.uber.org/zap v1.24.0
Expand Down Expand Up @@ -49,12 +49,12 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgconn v1.14.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.13.0 // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.0 // indirect
Expand All @@ -71,7 +71,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/common v0.40.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
Expand All @@ -80,12 +80,12 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
Loading

0 comments on commit 4f33c07

Please sign in to comment.