diff --git a/download-from-github-repo/.helmignore b/download-from-github-repo/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/download-from-github-repo/.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/download-from-github-repo/Chart.yaml b/download-from-github-repo/Chart.yaml new file mode 100644 index 0000000..88f8605 --- /dev/null +++ b/download-from-github-repo/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +appVersion: 0.1.0 +description: Download a file from a github repo +name: download-from-github-repo +type: application +version: 0.1.0 diff --git a/download-from-github-repo/templates/NOTES.txt b/download-from-github-repo/templates/NOTES.txt new file mode 100644 index 0000000..e69de29 diff --git a/download-from-github-repo/templates/_helpers.tpl b/download-from-github-repo/templates/_helpers.tpl new file mode 100644 index 0000000..388acfc --- /dev/null +++ b/download-from-github-repo/templates/_helpers.tpl @@ -0,0 +1,71 @@ +{{/* vim: set syntax=helm: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "download-from-github-repo.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "download-from-github-repo.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "download-from-github-repo.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "download-from-github-repo.labels" -}} +helm.sh/chart: {{ include "download-from-github-repo.chart" . }} +{{ include "download-from-github-repo.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "download-from-github-repo.selectorLabels" -}} +app.kubernetes.io/name: {{ include "download-from-github-repo.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "download-from-github-repo.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "download-from-github-repo.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Name of the job +*/}} +{{- define "download-from-github-repo.jobName" -}} +{{ include "download-from-github-repo.fullname" . }} +{{- end }} + diff --git a/download-from-github-repo/templates/job.yaml b/download-from-github-repo/templates/job.yaml new file mode 100644 index 0000000..1506de8 --- /dev/null +++ b/download-from-github-repo/templates/job.yaml @@ -0,0 +1,103 @@ +# vim: set filetype=helm: +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "download-from-github-repo.jobName" . }} + labels: + {{- include "download-from-github-repo.labels" . | nindent 4 }} +spec: + backoffLimit: 1 + completions: 1 + parallelism: 1 + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "download-from-github-repo.selectorLabels" . | nindent 8 }} + spec: + restartPolicy: Never + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "download-from-github-repo.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + volumes: + {{- if .Values.job.persistence }} + - name: work + persistentVolumeClaim: + claimName: {{ .Values.job.persistence.pvcName }} + {{- else }} + - name: work + emptyDir: {} + {{- end }}{{/* if .Values.job.persistence */}} + initContainers: + - name: download + image: "{{ .Values.job.download.image.repository }}:{{ .Values.job.download.image.tag }}" + imagePullPolicy: {{ .Values.job.download.image.pullPolicy }} + securityContext: + {{- toYaml .Values.securityContext | nindent 10 }} + env: + {{- with .Values.githubRepo }} + - name: repoName + value: {{ .name }} + - name: accessToken + valueFrom: + secretKeyRef: + name: {{ .accessToken.secretName }} + key: {{ .accessToken.key }} + - name: repoTag + value: {{ .tag }} + {{- end }}{{/* .Values.githubRepo */}} + - name: filePath + value: {{ .Values.job.filePath }} + - name: outputFilePath + value: {{ .Values.job.outputFilePath }} + - name: apiUrl + # https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28 + value: >- + https://$(accessToken)@api.github.com/repos/$(repoName)/contents/$(filePath)?ref=$(repoTag) + command: [ "sh", "-u", "-e" ] + args: + - -c + - >- + curl -f -v --create-dirs --output ${outputFilePath} $(curl -f -v "${apiUrl}"| jq -r .download_url) + workingDir: /work + volumeMounts: + - name: work + mountPath: /work + resources: {{- toYaml .Values.resources | nindent 10 }} + containers: + - name: process + image: "{{ .Values.job.process.image.repository }}:{{ .Values.job.process.image.tag }}" + imagePullPolicy: {{ .Values.job.process.image.pullPolicy }} + securityContext: + {{- toYaml .Values.securityContext | nindent 10 }} + env: + - name: outputFilePath + value: {{ .Values.job.outputFilePath }} + {{- with .Values.job.process.extraEnv }} + {{- toYaml . | nindent 8 }} + {{- end }}{{/* with .Values.job.process.extraEnv */}} + command: {{- toYaml (.Values.job.process.command) | nindent 8 }} + workingDir: /work + volumeMounts: + - name: work + mountPath: /work + resources: {{- toYaml .Values.resources | nindent 10 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/download-from-github-repo/templates/serviceaccount.yaml b/download-from-github-repo/templates/serviceaccount.yaml new file mode 100644 index 0000000..78728be --- /dev/null +++ b/download-from-github-repo/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "download-from-github-repo.serviceAccountName" . }} + labels: + {{- include "download-from-github-repo.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/download-from-github-repo/values.yaml b/download-from-github-repo/values.yaml new file mode 100644 index 0000000..471922a --- /dev/null +++ b/download-from-github-repo/values.yaml @@ -0,0 +1,75 @@ +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: false + annotations: {} + name: "" + +podAnnotations: {} + +podSecurityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + seccompProfile: + type: RuntimeDefault + +securityContext: + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + runAsNonRoot: true + allowPrivilegeEscalation: false + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} +tolerations: [] +affinity: {} + +githubRepo: + name: NowhereLand/helloworld + tag: main + # a personal access token with read permissions on the repo + accessToken: + secretName: github-access-token + key: token + +job: + # path to file (relative to github repo) + filePath: path/to/1.xt + outputFilePath: out/1.txt + #persistence: + # pvcName: + download: + image: + repository: ghcr.io/opertusmundi/curl-jq + pullPolicy: IfNotPresent + tag: "8-alpine" + process: + image: + repository: alpine + pullPolicy: IfNotPresent + tag: "3.19" + extraEnv: [] + #- name: foo + # value: Bar + command: + - sh + - -c + - >- + stat ${outputFilePath} +