Skip to content

Commit 9e42119

Browse files
authored
Merge pull request #158 from bcgov/bugfix/helm-hpa
Various Helm Chart maintenance updates
2 parents 5ceb942 + 1ede154 commit 9e42119

File tree

11 files changed

+78
-55
lines changed

11 files changed

+78
-55
lines changed

app/config/custom-environment-variables.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"basicAuth": {
33
"enabled": "BASICAUTH_ENABLED",
4-
"username": "BASICAUTH_USERNAME",
5-
"password": "BASICAUTH_PASSWORD"
4+
"password": "BASICAUTH_PASSWORD",
5+
"username": "BASICAUTH_USERNAME"
66
},
77
"db": {
88
"enabled": "DB_ENABLED",
99
"database": "DB_DATABASE",
1010
"host": "DB_HOST",
11-
"username": "DB_USERNAME",
1211
"password": "DB_PASSWORD",
13-
"port": "DB_PORT"
12+
"poolMin": "DB_POOL_MIN",
13+
"poolMax": "DB_POOL_MAX",
14+
"port": "DB_PORT",
15+
"username": "DB_USERNAME"
1416
},
1517
"keycloak": {
1618
"enabled": "KC_ENABLED",

app/config/default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"database": "coms",
44
"host": "localhost",
55
"port": "5432",
6+
"poolMin": "2",
7+
"poolMax": "10",
68
"username": "app"
79
},
810
"objectStorage": {

app/knexfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ module.exports = {
5353
directory: __dirname + '/src/db/migrations'
5454
},
5555
pool: {
56-
min: 2,
57-
max: 10
56+
min: parseInt(config.get('db.poolMin')),
57+
max: parseInt(config.get('db.poolMax'))
5858
// This shouldn't be here: https://github.com/knex/knex/issues/3455#issuecomment-535554401
5959
// propagateCreateError: false
6060
},

app/src/components/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ module.exports = Object.freeze({
3232
URL: 'url'
3333
},
3434

35+
/**
36+
* Generic email regex modified to require domain of at least 2 characters
37+
* @see {@link https://emailregex.com/}
38+
*/
39+
EMAILREGEX: '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]{2,})+$',
40+
3541
/** Maximum Content Length supported by S3 CopyObjectCommand */
3642
MAXCOPYOBJECTLENGTH: 5 * 1024 * 1024 * 1024,
3743

app/src/validators/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { Joi: baseJoi } = require('express-validation');
22

3-
const { Permissions } = require('../components/constants');
3+
const { EMAILREGEX, Permissions } = require('../components/constants');
44

55
/**
66
* @constant Joi
@@ -39,7 +39,7 @@ const type = {
3939
truthy: Joi.boolean()
4040
.truthy('true', 1, '1', 't', 'yes', 'y', 'false', 0, '0', 'f', 'no', 'n'),
4141

42-
email: Joi.string().max(255).email(),
42+
email: Joi.string().pattern(new RegExp(EMAILREGEX)).max(255),
4343

4444
uuidv4: Joi.string().guid({
4545
version: 'uuidv4'

app/tests/unit/validators/common.spec.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const crypto = require('crypto');
22
const jestJoi = require('jest-joi');
33
expect.extend(jestJoi.matchers);
44

5-
const { Permissions } = require('../../../src/components/constants');
5+
const { EMAILREGEX, Permissions } = require('../../../src/components/constants');
66
const { scheme, type } = require('../../../src/validators/common');
77

88
describe('type', () => {
@@ -50,7 +50,6 @@ describe('type', () => {
5050

5151
describe('email', () => {
5252
const model = type.email.describe();
53-
5453
it('is a string', () => {
5554
expect(model).toBeTruthy();
5655
expect(model.type).toEqual('string');
@@ -60,14 +59,18 @@ describe('type', () => {
6059
expect(Array.isArray(model.rules)).toBeTruthy();
6160
expect(model.rules).toHaveLength(2);
6261
expect(model.rules).toEqual(expect.arrayContaining([
63-
expect.objectContaining(
64-
{
65-
'args': {
66-
'limit': 255
67-
},
68-
'name': 'max'
62+
expect.objectContaining({
63+
'args': {
64+
'regex': new RegExp(EMAILREGEX).toString()
65+
},
66+
'name': 'pattern'
67+
}),
68+
expect.objectContaining({
69+
'args': {
70+
'limit': 255
6971
},
70-
{ 'name': 'email' })
72+
'name': 'max'
73+
})
7174
]));
7275
});
7376

charts/coms/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: common-object-management-service
33
# This is the chart version. This version number should be incremented each time you make changes
44
# to the chart and its templates, including the app version.
55
# Versions are expected to follow Semantic Versioning (https://semver.org/)
6-
version: 0.0.12
6+
version: 0.0.13
77
kubeVersion: ">= 1.13.0"
88
description: A microservice for managing access control to S3 Objects
99
# A chart can be either an 'application' or a 'library' chart.

charts/coms/templates/deploymentconfig.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
{{ $dbHostName := .Values.config.configMap.DB_HOST }}
2+
{{ $dbSecretName := printf "%s-%s" (include "coms.fullname" .) "passphrase" }}
3+
{{- if .Values.patroni.enabled }}
4+
{{ $dbHostName = include "patroni.fullname" .Subcharts.patroni }}
5+
{{ $dbSecretName = include "patroni.fullname" .Subcharts.patroni }}
6+
{{- end }}
7+
18
{{- define "coms.connectsTo" -}}
29
apiVersion: apps/v1
310
kind: StatefulSet
@@ -40,19 +47,19 @@ spec:
4047
valueFrom:
4148
secretKeyRef:
4249
key: app-db-name
43-
name: {{ include "patroni.fullname" .Subcharts.patroni }}
50+
name: {{ $dbSecretName }}
4451
- name: DB_HOST
45-
value: {{ include "patroni.fullname" .Subcharts.patroni }}
52+
value: {{ $dbHostName }}
4653
- name: DB_USERNAME
4754
valueFrom:
4855
secretKeyRef:
4956
key: app-db-username
50-
name: {{ include "patroni.fullname" .Subcharts.patroni }}
57+
name: {{ $dbSecretName }}
5158
- name: DB_PASSWORD
5259
valueFrom:
5360
secretKeyRef:
5461
key: app-db-password
55-
name: {{ include "patroni.fullname" .Subcharts.patroni }}
62+
name: {{ $dbSecretName }}
5663
{{- end }}
5764
type: Rolling
5865
template:
@@ -115,19 +122,19 @@ spec:
115122
valueFrom:
116123
secretKeyRef:
117124
key: app-db-name
118-
name: {{ include "patroni.fullname" .Subcharts.patroni }}
125+
name: {{ $dbSecretName }}
119126
- name: DB_HOST
120-
value: {{ include "patroni.fullname" .Subcharts.patroni }}
127+
value: {{ $dbHostName }}
121128
- name: DB_USERNAME
122129
valueFrom:
123130
secretKeyRef:
124131
key: app-db-username
125-
name: {{ include "patroni.fullname" .Subcharts.patroni }}
132+
name: {{ $dbSecretName }}
126133
- name: DB_PASSWORD
127134
valueFrom:
128135
secretKeyRef:
129136
key: app-db-password
130-
name: {{ include "patroni.fullname" .Subcharts.patroni }}
137+
name: {{ $dbSecretName }}
131138
{{- end }}
132139
{{- if or .Values.features.oidcAuth .Values.config.configMap.KC_ENABLED }}
133140
- name: KC_CLIENTID

charts/coms/templates/hpa.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- if .Values.autoscaling.enabled }}
22
---
3-
apiVersion: autoscaling/v2beta2
3+
apiVersion: autoscaling/v2
44
kind: HorizontalPodAutoscaler
55
metadata:
66
name: {{ include "coms.fullname" . }}

charts/coms/templates/secret.yaml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
{{- $bPassword := (randAlphaNum 32) | b64enc }}
2-
{{- $bUsername := (randAlphaNum 32) | b64enc }}
3-
{{- $pPassword := (randAlphaNum 32) | b64enc }}
4-
{{- $pUsername := (randAlphaNum 32) | b64enc }}
1+
{{- $baPassword := (randAlphaNum 32) }}
2+
{{- $baUsername := (randAlphaNum 32) }}
3+
{{- $dbPassword := (randAlphaNum 32) }}
4+
{{- $dbUsername := (randAlphaNum 32) }}
55

6-
{{- $bSecretName := printf "%s-%s" (include "coms.fullname" .) "basicauth" }}
7-
{{- $bSecret := (lookup "v1" "Secret" .Release.Namespace $bSecretName ) }}
8-
{{- $kSecretName := printf "%s-%s" (include "coms.fullname" .) "keycloak" }}
9-
{{- $kSecret := (lookup "v1" "Secret" .Release.Namespace $kSecretName ) }}
10-
{{- $oSecretName := printf "%s-%s" (include "coms.fullname" .) "objectstorage" }}
11-
{{- $oSecret := (lookup "v1" "Secret" .Release.Namespace $oSecretName ) }}
12-
{{- $pSecretName := printf "%s-%s" (include "coms.fullname" .) "passphrase" }}
13-
{{- $pSecret := (lookup "v1" "Secret" .Release.Namespace $pSecretName ) }}
6+
{{- $baSecretName := printf "%s-%s" (include "coms.fullname" .) "basicauth" }}
7+
{{- $baSecret := (lookup "v1" "Secret" .Release.Namespace $baSecretName ) }}
8+
{{- $dbSecretName := printf "%s-%s" (include "coms.fullname" .) "passphrase" }}
9+
{{- $dbSecret := (lookup "v1" "Secret" .Release.Namespace $dbSecretName ) }}
10+
{{- $kcSecretName := printf "%s-%s" (include "coms.fullname" .) "keycloak" }}
11+
{{- $kcSecret := (lookup "v1" "Secret" .Release.Namespace $kcSecretName ) }}
12+
{{- $osSecretName := printf "%s-%s" (include "coms.fullname" .) "objectstorage" }}
13+
{{- $osSecret := (lookup "v1" "Secret" .Release.Namespace $osSecretName ) }}
1414

15-
{{- if not $bSecret }}
15+
{{- if not $baSecret }}
1616
---
1717
apiVersion: v1
1818
kind: Secret
@@ -21,14 +21,14 @@ metadata:
2121
annotations:
2222
"helm.sh/resource-policy": keep
2323
{{- end }}
24-
name: {{ $bSecretName }}
24+
name: {{ $baSecretName }}
2525
labels: {{ include "coms.labels" . | nindent 4 }}
2626
type: kubernetes.io/basic-auth
2727
data:
28-
password: {{ .Values.basicAuthSecretOverride.password | default $bPassword | quote }}
29-
username: {{ .Values.basicAuthSecretOverride.username | default $bUsername | quote }}
28+
password: {{ .Values.basicAuthSecretOverride.password | default $baPassword | b64enc | quote }}
29+
username: {{ .Values.basicAuthSecretOverride.username | default $baUsername | b64enc | quote }}
3030
{{- end }}
31-
{{- if not $pSecret }}
31+
{{- if not $dbSecret }}
3232
---
3333
apiVersion: v1
3434
kind: Secret
@@ -37,14 +37,14 @@ metadata:
3737
annotations:
3838
"helm.sh/resource-policy": keep
3939
{{- end }}
40-
name: {{ $pSecretName }}
40+
name: {{ $dbSecretName }}
4141
labels: {{ include "coms.labels" . | nindent 4 }}
4242
type: kubernetes.io/basic-auth
4343
data:
44-
password: {{ .Values.dbSecretOverride.password | default $pPassword | quote }}
45-
username: {{ .Values.dbSecretOverride.username | default $pUsername | quote }}
44+
password: {{ .Values.dbSecretOverride.password | default $dbPassword | b64enc | quote }}
45+
username: {{ .Values.dbSecretOverride.username | default $dbUsername | b64enc | quote }}
4646
{{- end }}
47-
{{- if and (not $oSecret) (and .Values.objectStorageSecretOverride.password .Values.objectStorageSecretOverride.username) }}
47+
{{- if and (not $kcSecret) (and .Values.keycloakSecretOverride.password .Values.keycloakSecretOverride.username) }}
4848
---
4949
apiVersion: v1
5050
kind: Secret
@@ -53,14 +53,14 @@ metadata:
5353
annotations:
5454
"helm.sh/resource-policy": keep
5555
{{- end }}
56-
name: {{ $oSecretName }}
56+
name: {{ $kcSecretName }}
5757
labels: {{ include "coms.labels" . | nindent 4 }}
5858
type: kubernetes.io/basic-auth
5959
data:
60-
password: {{ .Values.objectStorageSecretOverride.password | quote }}
61-
username: {{ .Values.objectStorageSecretOverride.username | quote }}
60+
password: {{ .Values.keycloakSecretOverride.password | b64enc | quote }}
61+
username: {{ .Values.keycloakSecretOverride.username | b64enc | quote }}
6262
{{- end }}
63-
{{- if and (not $kSecret) (and .Values.keycloakSecretOverride.password .Values.keycloakSecretOverride.username) }}
63+
{{- if and (not $osSecret) (and .Values.objectStorageSecretOverride.password .Values.objectStorageSecretOverride.username) }}
6464
---
6565
apiVersion: v1
6666
kind: Secret
@@ -69,10 +69,10 @@ metadata:
6969
annotations:
7070
"helm.sh/resource-policy": keep
7171
{{- end }}
72-
name: {{ $kSecretName }}
72+
name: {{ $osSecretName }}
7373
labels: {{ include "coms.labels" . | nindent 4 }}
7474
type: kubernetes.io/basic-auth
7575
data:
76-
password: {{ .Values.keycloakSecretOverride.password | quote }}
77-
username: {{ .Values.keycloakSecretOverride.username | quote }}
76+
password: {{ .Values.objectStorageSecretOverride.password | b64enc | quote }}
77+
username: {{ .Values.objectStorageSecretOverride.username | b64enc | quote }}
7878
{{- end }}

0 commit comments

Comments
 (0)