feat(infra): Add check-warp-deploy cron job (#4370)
### Description - add helm chart, helper functions and boilerplate to support check-warp-deploy cron job ### Drive-by changes - refactor check-deploy to call `getGovernor` ### Testing Manualpull/4399/head
parent
24c8188e55
commit
70830ffb3e
@ -0,0 +1,13 @@ |
||||
import { CheckWarpDeployConfig } from '../../../../src/config/funding.js'; |
||||
import { environment } from '../chains.js'; |
||||
|
||||
export const checkWarpDeployConfig: CheckWarpDeployConfig = { |
||||
docker: { |
||||
repo: 'gcr.io/abacus-labs-dev/hyperlane-monorepo', |
||||
tag: '36f7e14-20240823-160646', |
||||
}, |
||||
namespace: environment, |
||||
cronSchedule: '0 15 * * *', // set to 3pm utc every day
|
||||
prometheusPushGateway: |
||||
'http://prometheus-prometheus-pushgateway.monitoring.svc.cluster.local:9091', |
||||
}; |
@ -0,0 +1,6 @@ |
||||
apiVersion: v2 |
||||
name: check-warp-deploy |
||||
description: Check warp deploy |
||||
type: application |
||||
version: 0.1.0 |
||||
appVersion: '1.16.0' |
@ -0,0 +1,42 @@ |
||||
{{/* |
||||
Expand the name of the chart. |
||||
*/}} |
||||
{{- define "hyperlane.name" -}} |
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} |
||||
{{- end }} |
||||
|
||||
{{/* |
||||
Create chart name and version as used by the chart label. |
||||
*/}} |
||||
{{- define "hyperlane.chart" -}} |
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} |
||||
{{- end }} |
||||
|
||||
{{/* |
||||
Common labels |
||||
*/}} |
||||
{{- define "hyperlane.labels" -}} |
||||
helm.sh/chart: {{ include "hyperlane.chart" . }} |
||||
hyperlane/deployment: {{ .Values.hyperlane.runEnv | quote }} |
||||
hyperlane/context: "hyperlane" |
||||
{{ include "hyperlane.selectorLabels" . }} |
||||
{{- if .Chart.AppVersion }} |
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} |
||||
{{- end }} |
||||
app.kubernetes.io/managed-by: {{ .Release.Service }} |
||||
{{- end }} |
||||
|
||||
{{/* |
||||
Selector labels |
||||
*/}} |
||||
{{- define "hyperlane.selectorLabels" -}} |
||||
app.kubernetes.io/name: {{ include "hyperlane.name" . }} |
||||
app.kubernetes.io/instance: {{ .Release.Name }} |
||||
{{- end }} |
||||
|
||||
{{/* |
||||
The name of the ClusterSecretStore |
||||
*/}} |
||||
{{- define "hyperlane.cluster-secret-store.name" -}} |
||||
{{- default "external-secrets-gcp-cluster-secret-store" .Values.externalSecrets.clusterSecretStore }} |
||||
{{- end }} |
@ -0,0 +1,32 @@ |
||||
apiVersion: batch/v1 |
||||
kind: CronJob |
||||
metadata: |
||||
name: check-warp-deploy |
||||
spec: |
||||
schedule: "{{ .Values.cronjob.schedule }}" |
||||
successfulJobsHistoryLimit: {{ .Values.cronjob.successfulJobsHistoryLimit }} |
||||
failedJobsHistoryLimit: {{ .Values.cronjob.failedJobsHistoryLimit }} |
||||
concurrencyPolicy: Forbid |
||||
jobTemplate: |
||||
spec: |
||||
backoffLimit: 0 |
||||
activeDeadlineSeconds: 14400 |
||||
template: |
||||
spec: |
||||
restartPolicy: Never |
||||
containers: |
||||
- name: check-warp-deploy |
||||
image: {{ .Values.image.repository }}:{{ .Values.image.tag }} |
||||
imagePullPolicy: IfNotPresent |
||||
command: |
||||
- ./node_modules/.bin/tsx |
||||
- ./typescript/infra/scripts/check/check-warp-deploy.ts |
||||
- -e |
||||
- {{ .Values.hyperlane.runEnv }} |
||||
- --pushMetrics |
||||
env: |
||||
- name: PROMETHEUS_PUSH_GATEWAY |
||||
value: {{ .Values.infra.prometheusPushGateway }} |
||||
envFrom: |
||||
- secretRef: |
||||
name: check-warp-deploy-env-var-secret |
@ -0,0 +1,45 @@ |
||||
apiVersion: external-secrets.io/v1beta1 |
||||
kind: ExternalSecret |
||||
metadata: |
||||
name: check-warp-deploy-env-var-external-secret |
||||
labels: |
||||
{{- include "hyperlane.labels" . | nindent 4 }} |
||||
spec: |
||||
secretStoreRef: |
||||
name: {{ include "hyperlane.cluster-secret-store.name" . }} |
||||
kind: ClusterSecretStore |
||||
refreshInterval: "1h" |
||||
# The secret that will be created |
||||
target: |
||||
name: check-warp-deploy-env-var-secret |
||||
template: |
||||
type: Opaque |
||||
metadata: |
||||
labels: |
||||
{{- include "hyperlane.labels" . | nindent 10 }} |
||||
annotations: |
||||
update-on-redeploy: "{{ now }}" |
||||
data: |
||||
GCP_SECRET_OVERRIDES_ENABLED: "true" |
||||
GCP_SECRET_OVERRIDE_HYPERLANE_{{ .Values.hyperlane.runEnv | upper }}_KEY_DEPLOYER: {{ print "'{{ .deployer_key | toString }}'" }} |
||||
{{/* |
||||
* For each network, create an environment variable with the RPC endpoint. |
||||
* The templating of external-secrets will use the data section below to know how |
||||
* to replace the correct value in the created secret. |
||||
*/}} |
||||
{{- range .Values.hyperlane.chains }} |
||||
GCP_SECRET_OVERRIDE_{{ $.Values.hyperlane.runEnv | upper }}_RPC_ENDPOINTS_{{ . | upper }}: {{ printf "'{{ .%s_rpcs | toString }}'" . }} |
||||
{{- end }} |
||||
data: |
||||
- secretKey: deployer_key |
||||
remoteRef: |
||||
key: {{ printf "hyperlane-%s-key-deployer" .Values.hyperlane.runEnv }} |
||||
{{/* |
||||
* For each network, load the secret in GCP secret manager with the form: environment-rpc-endpoint-network, |
||||
* and associate it with the secret key networkname_rpc. |
||||
*/}} |
||||
{{- range .Values.hyperlane.chains }} |
||||
- secretKey: {{ printf "%s_rpcs" . }} |
||||
remoteRef: |
||||
key: {{ printf "%s-rpc-endpoints-%s" $.Values.hyperlane.runEnv . }} |
||||
{{- end }} |
@ -0,0 +1,12 @@ |
||||
image: |
||||
repository: gcr.io/hyperlane-labs-dev/hyperlane-monorepo |
||||
tag: |
||||
hyperlane: |
||||
runEnv: mainnet3 |
||||
chains: [] |
||||
cronjob: |
||||
schedule: '0 15 * * *' |
||||
successfulJobsHistoryLimit: 1 |
||||
failedJobsHistoryLimit: 1 |
||||
externalSecrets: |
||||
clusterSecretStore: |
@ -0,0 +1,85 @@ |
||||
import { Contexts } from '../../config/contexts.js'; |
||||
import { AgentContextConfig } from '../../src/config/agent/agent.js'; |
||||
import { CheckWarpDeployConfig } from '../../src/config/funding.js'; |
||||
import { HelmCommand, helmifyValues } from '../../src/utils/helm.js'; |
||||
import { execCmd } from '../../src/utils/utils.js'; |
||||
import { assertCorrectKubeContext } from '../agent-utils.js'; |
||||
import { getConfigsBasedOnArgs } from '../core-utils.js'; |
||||
|
||||
async function main() { |
||||
const { agentConfig, envConfig } = await getConfigsBasedOnArgs(); |
||||
if (agentConfig.context != Contexts.Hyperlane) |
||||
throw new Error( |
||||
`Invalid context ${agentConfig.context}, must be ${Contexts.Hyperlane}`, |
||||
); |
||||
|
||||
await assertCorrectKubeContext(envConfig); |
||||
|
||||
if (!envConfig.checkWarpDeployConfig) { |
||||
throw new Error('No checkWarpDeployConfig found'); |
||||
} |
||||
|
||||
await runCheckWarpDeployHelmCommand( |
||||
HelmCommand.InstallOrUpgrade, |
||||
agentConfig, |
||||
envConfig.checkWarpDeployConfig, |
||||
); |
||||
} |
||||
|
||||
main() |
||||
.then(() => console.log('Deploy successful!')) |
||||
.catch(console.error); |
||||
|
||||
async function runCheckWarpDeployHelmCommand( |
||||
helmCommand: HelmCommand, |
||||
agentConfig: AgentContextConfig, |
||||
config: CheckWarpDeployConfig, |
||||
) { |
||||
const values = getCheckWarpDeployHelmValues(agentConfig, config); |
||||
|
||||
if (helmCommand === HelmCommand.InstallOrUpgrade) { |
||||
// Delete secrets to avoid them being stale
|
||||
try { |
||||
await execCmd( |
||||
`kubectl delete secrets --namespace ${agentConfig.namespace} --selector app.kubernetes.io/instance=check-warp-deploy`, |
||||
{}, |
||||
false, |
||||
false, |
||||
); |
||||
} catch (e) { |
||||
console.error(e); |
||||
} |
||||
} |
||||
|
||||
return execCmd( |
||||
`helm ${helmCommand} check-warp-deploy ./helm/check-warp-deploy --namespace ${ |
||||
config.namespace |
||||
} ${values.join(' ')}`,
|
||||
{}, |
||||
false, |
||||
true, |
||||
); |
||||
} |
||||
|
||||
function getCheckWarpDeployHelmValues( |
||||
agentConfig: AgentContextConfig, |
||||
config: CheckWarpDeployConfig, |
||||
) { |
||||
const values = { |
||||
cronjob: { |
||||
schedule: config.cronSchedule, |
||||
}, |
||||
hyperlane: { |
||||
runEnv: agentConfig.runEnv, |
||||
chains: agentConfig.environmentChainNames, |
||||
}, |
||||
infra: { |
||||
prometheusPushGateway: config.prometheusPushGateway, |
||||
}, |
||||
image: { |
||||
repository: config.docker.repo, |
||||
tag: config.docker.tag, |
||||
}, |
||||
}; |
||||
return helmifyValues(values); |
||||
} |
Loading…
Reference in new issue