diff --git a/cronjob/Chart.lock b/cronjob/Chart.lock new file mode 100644 index 0000000..7cb26ae --- /dev/null +++ b/cronjob/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: workflow-lib + repository: file://../workflow-lib + version: 0.1.0 +digest: sha256:a825bc58a89b9828010f616699d3b7a9bbddb768148dbc81e7365bcfd3f674de +generated: "2024-12-11T18:01:18.461727+08:00" diff --git a/cronjob/Chart.yaml b/cronjob/Chart.yaml index dd4938d..e0c5742 100644 --- a/cronjob/Chart.yaml +++ b/cronjob/Chart.yaml @@ -1,6 +1,11 @@ -apiVersion: v1 +apiVersion: v2 description: Helm chart with simple cronjob template name: cronjob version: 1.1.0 appVersion: 1.0.0 tillerVersion: ">=2.14.3" + +dependencies: + - name: workflow-lib + version: 0.1.0 + repository: file://../workflow-lib \ No newline at end of file diff --git a/cronjob/charts/workflow-lib-0.1.0.tgz b/cronjob/charts/workflow-lib-0.1.0.tgz new file mode 100644 index 0000000..c680e1d Binary files /dev/null and b/cronjob/charts/workflow-lib-0.1.0.tgz differ diff --git a/cronjob/templates/cronjob.yaml b/cronjob/templates/cronjob.yaml index 2b84803..f813ccc 100644 --- a/cronjob/templates/cronjob.yaml +++ b/cronjob/templates/cronjob.yaml @@ -35,7 +35,7 @@ spec: workflowTemplateRef: name: po-{{ .Values.name }} {{- else }} - {{- include "cronjob.argo_cron_workflow" . | nindent 4 }} + {{- include "workflow-lib.argo_cron_workflow" . | nindent 4 }} {{- end }} {{- else }} {{ template "cronjob.k8s_cronjob" . }} diff --git a/cronjob/templates/workflowtemplate.yaml b/cronjob/templates/workflowtemplate.yaml index 5127f2c..449b545 100644 --- a/cronjob/templates/workflowtemplate.yaml +++ b/cronjob/templates/workflowtemplate.yaml @@ -8,6 +8,6 @@ metadata: labels: businessid: {{ required "businessid must be provided" .Values.businessid | quote }} spec: - {{ include "cronjob.argo_cron_workflow" . | nindent 2 }} + {{ include "workflow-lib.argo_cron_workflow" . | nindent 2 }} {{- end }} {{- end }} \ No newline at end of file diff --git a/workflow-lib/.helmignore b/workflow-lib/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/workflow-lib/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/workflow-lib/Chart.yaml b/workflow-lib/Chart.yaml new file mode 100644 index 0000000..f03b33c --- /dev/null +++ b/workflow-lib/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: workflow-lib +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: library + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/cronjob/templates/_argo_cron_workflow.tpl b/workflow-lib/templates/_argo_cron_workflow.tpl similarity index 93% rename from cronjob/templates/_argo_cron_workflow.tpl rename to workflow-lib/templates/_argo_cron_workflow.tpl index 8dfeea3..fff2556 100644 --- a/cronjob/templates/_argo_cron_workflow.tpl +++ b/workflow-lib/templates/_argo_cron_workflow.tpl @@ -1,4 +1,4 @@ -{{- define "cronjob.argo_cron_workflow" -}} +{{- define "workflow-lib.argo_cron_workflow" -}} podMetadata: labels: name: {{ .Values.name }} @@ -120,23 +120,23 @@ templates: {{- if .Values.steps }} {{- range .Values.steps }} - - {{- include "cronjob.argo_cron_workflow.step_template" . | nindent 8 }} + - {{- include "workflow-lib.argo_cron_workflow.step_template" . | nindent 8 }} {{- end }} {{- else }} {{- /* if no steps, use single step */}} {{- $defaultValue := merge (fromJson "{\"name\":\"entry\",\"steps\":[[{\"name\":\"step1\",\"template\":\"template\"}]]}") $.Values }} - - {{- include "cronjob.argo_cron_workflow.step_template" $defaultValue | nindent 8 }} + - {{- include "workflow-lib.argo_cron_workflow.step_template" $defaultValue | nindent 8 }} {{- end }} {{- if .Values.containers }} {{- range .Values.containers }} {{ $value := list . $.Release.Namespace $.Values.name }} - - {{- include "cronjob.argo_cron_workflow.container_template" $value | nindent 8}} + - {{- include "workflow-lib.argo_cron_workflow.container_template" $value | nindent 8}} {{- end }} {{- else }} {{- $defaultValue := merge (fromJson "{\"name\":\"template\"}") $.Values }} {{- $value := list $defaultValue $.Release.Namespace $.Values.name }} - - {{- include "cronjob.argo_cron_workflow.container_template" $value | nindent 8 }} + - {{- include "workflow-lib.argo_cron_workflow.container_template" $value | nindent 8 }} {{- end }} # The template of exist-handler if any .Values.exitNotifications config is set @@ -188,15 +188,15 @@ templates: {{- end }} # If .Values.exitNotifications.slackApp is set, Slack app notification template will be loaded {{- if .Values.exitNotifications.slackApp }} - {{ include "cronjob._exit_handler_slack_app" . | nindent 2 }} + {{ include "workflow-lib._exit_handler_slack_app" . | nindent 2 }} {{- end }} # If .Values.exitNotifications.newRelic is set, New Relic notification template will be loaded {{- if .Values.exitNotifications.newRelic }} - {{ include "cronjob._exit_handler_newrelic" . | nindent 2 }} + {{ include "workflow-lib._exit_handler_newrelic" . | nindent 2 }} {{- end }} # If .Values.exitNotifications.healthcheckIo is set, Healthcheck IO notification template will be loaded {{- if .Values.exitNotifications.healthcheckIo }} - {{ include "cronjob._exit_handler_healthcheck_io" . | nindent 2 }} + {{ include "workflow-lib._exit_handler_healthcheck_io" . | nindent 2 }} {{- end }} {{- end }} diff --git a/cronjob/templates/_argo_cron_workflow_container_template.tpl b/workflow-lib/templates/_argo_cron_workflow_container_template.tpl similarity index 83% rename from cronjob/templates/_argo_cron_workflow_container_template.tpl rename to workflow-lib/templates/_argo_cron_workflow_container_template.tpl index 8c79c41..935c8b1 100644 --- a/cronjob/templates/_argo_cron_workflow_container_template.tpl +++ b/workflow-lib/templates/_argo_cron_workflow_container_template.tpl @@ -1,4 +1,4 @@ -{{- define "cronjob.argo_cron_workflow.container_template" -}} +{{- define "workflow-lib.argo_cron_workflow.container_template" -}} {{- $input := index . 0 -}} {{- $namespace := index . 1 -}} {{- $workflowName := index . 2 -}} @@ -17,7 +17,7 @@ inputs: {{ toYaml . | nindent 2 }} outputs: {{ toYaml . | nindent 2 }} {{- end }} container: - image: {{ template "cronjob.argo_cron_workflow.image" $input.image }} + image: {{ template "workflow-lib.argo_cron_workflow.image" $input.image }} {{- with $input.command }} command: {{- toYaml . | nindent 4 }} {{- end }} @@ -29,7 +29,7 @@ container: resources: {{- toYaml $input.resources | nindent 4 }} {{- else }} # default settings on resources - resources: {{- include "cronjob.argo_cron_workflow.default_resource" . | nindent 4 }} + resources: {{- include "workflow-lib.argo_cron_workflow.default_resource" . | nindent 4 }} {{- end }} {{- with $input.securityContext }} securityContext: {{ toYaml . | nindent 4 }} @@ -62,7 +62,7 @@ container: {{- end }} {{- end -}} -{{- define "cronjob.argo_cron_workflow.default_resource" -}} +{{- define "workflow-lib.argo_cron_workflow.default_resource" -}} limits: memory: "2Gi" cpu: "1" @@ -71,6 +71,6 @@ requests: memory: "1Gi" {{- end -}} -{{- define "cronjob.argo_cron_workflow.image" -}} +{{- define "workflow-lib.argo_cron_workflow.image" -}} '{{ required "image.repository must be provided" .repository }}:{{ required "image.tag must be provided" .tag }}' {{- end -}} \ No newline at end of file diff --git a/cronjob/templates/_argo_cron_workflow_step_template.tpl b/workflow-lib/templates/_argo_cron_workflow_step_template.tpl similarity index 88% rename from cronjob/templates/_argo_cron_workflow_step_template.tpl rename to workflow-lib/templates/_argo_cron_workflow_step_template.tpl index 8870d9b..c396a2d 100644 --- a/cronjob/templates/_argo_cron_workflow_step_template.tpl +++ b/workflow-lib/templates/_argo_cron_workflow_step_template.tpl @@ -1,4 +1,4 @@ -{{- define "cronjob.argo_cron_workflow.step_template" -}} +{{- define "workflow-lib.argo_cron_workflow.step_template" -}} name: {{ .name }} {{- with .inputs }} inputs: {{ toYaml . | nindent 2 }} diff --git a/cronjob/templates/_exit_handler_healthcheck_io.tpl b/workflow-lib/templates/_exit_handler_healthcheck_io.tpl similarity index 93% rename from cronjob/templates/_exit_handler_healthcheck_io.tpl rename to workflow-lib/templates/_exit_handler_healthcheck_io.tpl index ff9d14f..07ce06b 100644 --- a/cronjob/templates/_exit_handler_healthcheck_io.tpl +++ b/workflow-lib/templates/_exit_handler_healthcheck_io.tpl @@ -1,4 +1,4 @@ -{{- define "cronjob._exit_handler_healthcheck_io" -}} +{{- define "workflow-lib._exit_handler_healthcheck_io" -}} {{- $healthcheckIo := .Values.exitNotifications.healthcheckIo | default dict -}} - name: notice-healthcheck-io-succeeded # For cronjob health check, as the schedule may different therefore each cronjob will have different uuid container: diff --git a/cronjob/templates/_exit_handler_newrelic.tpl b/workflow-lib/templates/_exit_handler_newrelic.tpl similarity index 95% rename from cronjob/templates/_exit_handler_newrelic.tpl rename to workflow-lib/templates/_exit_handler_newrelic.tpl index b7cf9f1..dce2ed3 100644 --- a/cronjob/templates/_exit_handler_newrelic.tpl +++ b/workflow-lib/templates/_exit_handler_newrelic.tpl @@ -1,4 +1,4 @@ -{{- define "cronjob._exit_handler_newrelic" -}} +{{- define "workflow-lib._exit_handler_newrelic" -}} {{- $newRelic := .Values.exitNotifications.newRelic | default dict -}} {{- $image := $newRelic.image | default dict -}} - name: notice-newrelic-failed diff --git a/cronjob/templates/_exit_handler_slack_app.tpl b/workflow-lib/templates/_exit_handler_slack_app.tpl similarity index 99% rename from cronjob/templates/_exit_handler_slack_app.tpl rename to workflow-lib/templates/_exit_handler_slack_app.tpl index 5340e8d..d6b2bf5 100644 --- a/cronjob/templates/_exit_handler_slack_app.tpl +++ b/workflow-lib/templates/_exit_handler_slack_app.tpl @@ -1,4 +1,4 @@ -{{- define "cronjob._exit_handler_slack_app" -}} +{{- define "workflow-lib._exit_handler_slack_app" -}} {{- $slackApp := .Values.exitNotifications.slackApp | default dict -}} {{- $sendOnSuccess := list nil true "true" | has $slackApp.sendOnSuccess -}} {{- $sendOnFailure := list nil true "true" | has $slackApp.sendOnFailure -}}