Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cronjob Deployment Configs #1433

Merged
merged 25 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a6b3865
feat: first pass of the telemetry cronjob yaml
MacQSL Nov 18, 2024
1537d38
fix: patched missing env from dev
MacQSL Nov 18, 2024
bc6b7fb
fix: missing env variable
MacQSL Nov 18, 2024
b5c0460
doc: updated readme + included imagePullPolicy
MacQSL Nov 18, 2024
b2f6228
fix: empty image name
MacQSL Nov 18, 2024
3b114f3
fix: attempting to use imagePullPolicy
MacQSL Nov 18, 2024
0edb371
feat: added trigger for imageStreamTag
MacQSL Nov 18, 2024
5771d0d
feat: added suffix to image
MacQSL Nov 18, 2024
d119cff
feat: added full path for image registry
MacQSL Nov 18, 2024
c20bd64
feat: added env variable for cronjob schedule
MacQSL Nov 18, 2024
59dfea3
feat: added suspend flag for cronjob
MacQSL Nov 19, 2024
4fb3be9
feat: updated forbid -> "forbid"
MacQSL Nov 19, 2024
1d0b4e3
fix: using boolean for suspend prop
MacQSL Nov 19, 2024
21a281d
fix: validating suspend true succeeds
MacQSL Nov 19, 2024
146566a
chore: attempting wrapping in double quotes
MacQSL Nov 19, 2024
bcfbc8b
feat: hardcoding boolean value
MacQSL Nov 19, 2024
77f4fd5
feat: attempting invalid cron schedule
MacQSL Nov 19, 2024
fb152e4
fix: attempting to use boolean casting
MacQSL Nov 19, 2024
3018486
fix: wrapping in string
MacQSL Nov 19, 2024
633de0c
${{DISABLED}}
MacQSL Nov 19, 2024
9588693
bad commit message
MacQSL Nov 19, 2024
619a773
feat: added cronjobs to clean step
MacQSL Nov 19, 2024
20cf00c
Merge branch 'SIMSBIOHUB-627' of https://github.com/bcgov/biohubbc in…
MacQSL Nov 20, 2024
320fa34
fix: dropped deprecated code
MacQSL Nov 20, 2024
be17992
feat: updated cronjob command
MacQSL Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/.pipeline/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ const phases = {
dbName: `${dbName}`,
phase: 'dev',
changeId: deployChangeId,
telemetryCronjobSchedule: '0 0 * * *', // Daily at midnight
telemetryCronjobDisabled: !isStaticDeployment,
suffix: `-dev-${deployChangeId}`,
instance: `${name}-dev-${deployChangeId}`,
version: `${deployChangeId}-${changeId}`,
Expand Down Expand Up @@ -114,6 +116,8 @@ const phases = {
dbName: `${dbName}`,
phase: 'test',
changeId: deployChangeId,
telemetryCronjobSchedule: '0 0 * * *', // Daily at midnight
telemetryCronjobDisabled: !isStaticDeployment,
suffix: `-test`,
instance: `${name}-test`,
version: `${version}`,
Expand Down Expand Up @@ -157,6 +161,8 @@ const phases = {
dbName: `${dbName}-spi`,
phase: 'test-spi',
changeId: deployChangeId,
telemetryCronjobSchedule: '0 0 * * *', // Daily at midnight
telemetryCronjobDisabled: !isStaticDeployment,
suffix: `-test-spi`,
instance: `${name}-spi-test-spi`,
version: `${version}`,
Expand Down Expand Up @@ -200,6 +206,8 @@ const phases = {
dbName: `${dbName}`,
phase: 'prod',
changeId: deployChangeId,
telemetryCronjobSchedule: '0 0 * * *', // Daily at midnight
telemetryCronjobDisabled: !isStaticDeployment,
suffix: `-prod`,
instance: `${name}-prod`,
version: `${version}`,
Expand Down
4 changes: 4 additions & 0 deletions api/.pipeline/lib/api.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ const apiDeploy = async (settings) => {
objects.push(
...oc.processDeploymentTemplate(`${templatesLocalBaseUrl}/api.dc.yaml`, {
param: {
NAMESPACE: phases[phase].namespace,
NAME: phases[phase].name,
SUFFIX: phases[phase].suffix,
VERSION: phases[phase].tag,
HOST: phases[phase].host,
APP_HOST: phases[phase].appHost,
CHANGE_ID: phases.build.changeId || changeId,
// Cronjobs
TELEMETRY_CRONJOB_SCHEDULE: phases[phase].telemetryCronjobSchedule,
TELEMETRY_CRONJOB_DISABLED: phases[phase].telemetryCronjobDisabled,
// Node
NODE_ENV: phases[phase].nodeEnv,
NODE_OPTIONS: phases[phase].nodeOptions,
Expand Down
2 changes: 1 addition & 1 deletion api/.pipeline/lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const clean = (settings) => {
namespace: phaseObj.namespace
});

oc.raw('delete', ['all,pvc,secrets,Secrets,secret,configmap,endpoints,Endpoints'], {
oc.raw('delete', ['all,pvc,secrets,Secrets,secret,configmap,endpoints,Endpoints,cronjobs,Cronjobs'], {
selector: `app=${phaseObj.instance},env-id=${phaseObj.changeId},!shared,github-repo=${oc.git.repository},github-owner=${oc.git.owner}`,
wait: 'true',
namespace: phaseObj.namespace
Expand Down
6 changes: 6 additions & 0 deletions api/.pipeline/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ The pipeline code builds and deploys all pods/images/storage/etc needed to deplo
- Create ObjectStore Secret

The included templates under `prereqs` can be imported via the "Import YAML" page in OpenShift.

## Telemetry Cronjob

How to manually trigger cronjob?

- `oc create job --from=cronjob/biohubbc-telemetry-cronjob-<suffix> <name of job>`
118 changes: 117 additions & 1 deletion api/.pipeline/templates/api.dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ metadata:
labels:
build: biohubbc-api
parameters:
- name: NAMESPACE
description: Openshift namespace name
value: ''
- name: BASE_IMAGE_REGISTRY_URL
description: The base image registry URL
value: image-registry.openshift-image-registry.svc:5000
- name: NAME
value: biohubbc-api
- name: SUFFIX
Expand Down Expand Up @@ -76,6 +82,10 @@ parameters:
- name: DB_SERVICE_NAME
description: 'Database service name associated with deployment'
required: true
- name: DB_PORT
description: 'Database port'
required: true
value: '5432'
# Keycloak
- name: KEYCLOAK_HOST
description: Key clock login url
Expand Down Expand Up @@ -195,6 +205,22 @@ parameters:
value: '1'
- name: REPLICAS_MAX
value: '1'
# Telemetry
- name: TELEMETRY_CRONJOB_SCHEDULE
description: The schedule for the telemetry cronjob
value: '0 0 * * *' # 12am
- name: TELEMETRY_CRONJOB_DISABLED
description: Boolean flag to disable the cronjob, only static deployments should run on schedule.
value: 'true'
- name: TELEMETRY_SECRET
description: The name of the Openshift Biohubbc telemetry secret
value: biohubbc-telemetry
- name: LOTEK_API_HOST
description: The host URL for Lotek webservice API
value: https://webservice.lotek.com
- name: VECTRONIC_API_HOST
description: The host URL for Vectronic webservice API
value: https://api.vectronic-wildlife.com
objects:
- kind: ImageStream
apiVersion: image.openshift.io/v1
Expand Down Expand Up @@ -316,7 +342,7 @@ objects:
key: database-name
name: ${DB_SERVICE_NAME}
- name: DB_PORT
value: '5432'
value: ${DB_PORT}
# Keycloak
- name: KEYCLOAK_HOST
value: ${KEYCLOAK_HOST}
Expand Down Expand Up @@ -537,6 +563,96 @@ objects:
status:
ingress: null

- kind: CronJob
apiVersion: batch/v1
metadata:
name: biohubbc-telemetry-cronjob${SUFFIX}
labels:
role: telemetry-cronjob
spec:
schedule: ${TELEMETRY_CRONJOB_SCHEDULE}
suspend: ${{TELEMETRY_CRONJOB_DISABLED}}
concurrencyPolicy: 'Forbid'
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
containers:
- name: api
image: ${BASE_IMAGE_REGISTRY_URL}/${NAMESPACE}/${NAME}:${VERSION}
imagePullPolicy: Always
restartPolicy: 'Never'
terminationGracePeriodSeconds: 30
activeDeadlineSeconds: 220
env:
- name: NODE_ENV
value: ${NODE_ENV}
- name: NODE_OPTIONS
value: ${NODE_OPTIONS}
# Database
- name: TZ
value: ${TZ}
- name: DB_HOST
value: ${DB_SERVICE_NAME}
- name: DB_USER_API
valueFrom:
secretKeyRef:
key: database-user-api
name: ${DB_SERVICE_NAME}
- name: DB_USER_API_PASS
valueFrom:
secretKeyRef:
key: database-user-api-password
name: ${DB_SERVICE_NAME}
- name: DB_DATABASE
valueFrom:
secretKeyRef:
key: database-name
name: ${DB_SERVICE_NAME}
- name: DB_PORT
value: ${DB_PORT}
# Telemetry
- name: LOTEK_API_HOST
value: ${LOTEK_API_HOST}
- name: LOTEK_ACCOUNT_USERNAME
valueFrom:
secretKeyRef:
key: lotek_account_username
name: ${TELEMETRY_SECRET}
- name: LOTEK_ACCOUNT_PASSWORD
valueFrom:
secretKeyRef:
key: lotek_account_password
name: ${TELEMETRY_SECRET}
- name: VECTRONIC_API_HOST
value: ${VECTRONIC_API_HOST}
# Logging
- name: LOG_LEVEL
value: ${LOG_LEVEL}
- name: LOG_LEVEL_FILE
value: data/cronjob-logs
- name: LOG_FILE_DIR
value: ${LOG_FILE_DIR}
- name: LOG_FILE_NAME
value: sims-telemetry-cronjob-%DATE%.log
- name: LOG_FILE_DATE_PATTERN
value: ${LOG_FILE_DATE_PATTERN}
- name: LOG_FILE_MAX_SIZE
value: ${LOG_FILE_MAX_SIZE}
- name: LOG_FILE_MAX_FILES
value: ${LOG_FILE_MAX_FILES}
# Api Validation
- name: API_RESPONSE_VALIDATION_ENABLED
value: ${API_RESPONSE_VALIDATION_ENABLED}
- name: DATABASE_RESPONSE_VALIDATION_ENABLED
value: ${DATABASE_RESPONSE_VALIDATION_ENABLED}
command: ["npm", "run", "telemetry-cronjob", "--", "--batchSize 1000", "--concurrently 100"]
restartPolicy: Never


# Disable the HPA for now, as it is preferrable to run an exact number of pods (e.g. min:2, max:2)
# - kind: HorizontalPodAutoscaler
# apiVersion: autoscaling/v2
Expand Down
8 changes: 8 additions & 0 deletions api/.pipeline/templates/prereqs/biohubbc-telemetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Secret
apiVersion: v1
metadata:
name: biohubbc-telemetry
data:
lotek_acount_username: <fill in values>
lotek_acount_password: <fill in values>
type: Opaque
Loading