diff --git a/library/common/2101.0.0/.helmignore b/library/common/2101.0.0/.helmignore new file mode 100644 index 0000000000..0e8a0eb36f --- /dev/null +++ b/library/common/2101.0.0/.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/library/common/2101.0.0/Chart.yaml b/library/common/2101.0.0/Chart.yaml new file mode 100644 index 0000000000..9a222c4857 --- /dev/null +++ b/library/common/2101.0.0/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: common +description: A library chart for iX Official Catalog + +# 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: 2101.0.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. +appVersion: v1 diff --git a/library/common/2101.0.0/README.md b/library/common/2101.0.0/README.md new file mode 100644 index 0000000000..f8784843a2 --- /dev/null +++ b/library/common/2101.0.0/README.md @@ -0,0 +1,11 @@ +# Library Chart for iX Official Catalog iX Chart + +**WARNING: THIS CHART IS NOT MEANT TO BE INSTALLED DIRECTLY** + +This is a [Helm Library Chart](https://helm.sh/docs/topics/library_charts/#helm). It's purpose is for grouping common logic between the k8s@home charts. + +Since a lot of charts follow the same pattern this library was built to reduce maintenance cost between the charts that use it and try achieve a goal of being DRY. + +## Introduction + +This chart provides common template helpers which can be used to develop new charts using [Helm](https://helm.sh) package manager. diff --git a/library/common/2101.0.0/templates/_serviceaccount.tpl b/library/common/2101.0.0/templates/_serviceaccount.tpl new file mode 100644 index 0000000000..b96d4009a9 --- /dev/null +++ b/library/common/2101.0.0/templates/_serviceaccount.tpl @@ -0,0 +1,11 @@ +{{/* +Common service account +*/}} +{{- define "common.serviceaccount" -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "common.names.serviceAccountName" . | quote }} + namespace: {{ .Release.Namespace | quote }} + labels: {{- include "common.labels.selectorLabels" . | nindent 4 -}} +{{- end -}} diff --git a/library/common/2101.0.0/templates/classes/_service.tpl b/library/common/2101.0.0/templates/classes/_service.tpl new file mode 100644 index 0000000000..c63ab9b933 --- /dev/null +++ b/library/common/2101.0.0/templates/classes/_service.tpl @@ -0,0 +1,41 @@ +{{/* +This template serves as a blueprint for all Service objects that are created +within the common library. +*/}} +{{- define "common.classes.service" -}} +{{- $values := .commonService -}} +{{- $serviceName := include "common.names.fullname" . -}} +{{- if hasKey $values "nameSuffix" -}} + {{- $serviceName = (printf "%v-%v" $serviceName $values.nameSuffix) -}} +{{ end -}} +{{- $svcType := $values.type | default "" -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ $serviceName }} + labels: + {{- include "common.labels" . | nindent 4 }} + {{- if $values.labels }} + {{ toYaml $values.labels | nindent 4 }} + {{- end }} + {{- if $values.annotations }} + {{- with $values.annotations }} + annotations: + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} +spec: + {{- if (or (eq $svcType "ClusterIP") (empty $svcType)) }} + type: ClusterIP + {{- if $values.clusterIP }} + clusterIP: {{ $values.clusterIP }} + {{end}} + {{- else if eq $svcType "NodePort" }} + type: {{ $svcType }} + {{- else }} + {{- fail "Only ClusterIP and NodePort services are supported in common chart" }} + {{- end }} + {{- include "common.classes.service.ports" (dict "svcType" $svcType "values" $values ) | trim | nindent 2 }} + selector: + {{- include "common.labels.selectorLabels" . | nindent 4 }} +{{- end }} diff --git a/library/common/2101.0.0/templates/classes/_service_ports.tpl b/library/common/2101.0.0/templates/classes/_service_ports.tpl new file mode 100644 index 0000000000..a61900b42a --- /dev/null +++ b/library/common/2101.0.0/templates/classes/_service_ports.tpl @@ -0,0 +1,19 @@ +{{/* +Render all the ports and additionalPorts for a Service object. +*/}} +{{- define "common.classes.service.ports" -}} + {{- $values := .values -}} + {{- $ports := $values.ports -}} + {{- if $ports -}} + ports: + {{- range $_ := $ports }} + - port: {{ .port }} + targetPort: {{ .targetPort | default "http" }} + protocol: {{ .protocol | default "TCP" }} + name: {{ .name | default "http" }} + {{- if (and (eq $.svcType "NodePort") (not (empty .nodePort))) }} + nodePort: {{ .nodePort }} + {{ end }} + {{- end -}} + {{- end -}} +{{- end }} diff --git a/library/common/2101.0.0/templates/lib/chart/_annotations.tpl b/library/common/2101.0.0/templates/lib/chart/_annotations.tpl new file mode 100644 index 0000000000..ad80be1e90 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/chart/_annotations.tpl @@ -0,0 +1,6 @@ +{{/* +Common workload annotations +*/}} +{{- define "common.annotations" -}} +rollme: {{ randAlphaNum 5 | quote }} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/chart/_capabilities.tpl b/library/common/2101.0.0/templates/lib/chart/_capabilities.tpl new file mode 100644 index 0000000000..7a3c13c8b2 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/chart/_capabilities.tpl @@ -0,0 +1,27 @@ +{{/* +Return the appropriate apiVersion for DaemonSet objects. +*/}} +{{- define "common.capabilities.daemonset.apiVersion" -}} +{{- print "apps/v1" -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for Deployment objects. +*/}} +{{- define "common.capabilities.deployment.apiVersion" -}} +{{- print "apps/v1" -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for StatefulSet objects. +*/}} +{{- define "common.capabilities.statefulset.apiVersion" -}} +{{- print "apps/v1" -}} +{{- end -}} + +{{/* +Return the appropriate apiVersion for StatefulSet objects. +*/}} +{{- define "common.capabilities.cronjob.apiVersion" -}} +{{- print "batch/v1beta1" -}} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/chart/_labels.tpl b/library/common/2101.0.0/templates/lib/chart/_labels.tpl new file mode 100644 index 0000000000..f64aead636 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/chart/_labels.tpl @@ -0,0 +1,24 @@ +{{/* +Common labels shared across objects. +*/}} +{{- define "common.labels" -}} +helm.sh/chart: {{ include "common.names.chart" . }} +{{ include "common.labels.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels shared across objects. +*/}} +{{- define "common.labels.selectorLabels" -}} +app.kubernetes.io/name: {{ include "common.names.name" . }} +app.kubernetes.io/instance: {{ include "common.names.releaseName" . }} +{{ if hasKey .Values "extraSelectorLabels" }} +{{ range $selector := .Values.extraSelectorLabels }} +{{ printf "%s: %s" $selector.key $selector.value }} +{{ end }} +{{ end }} +{{- end }} diff --git a/library/common/2101.0.0/templates/lib/chart/_names.tpl b/library/common/2101.0.0/templates/lib/chart/_names.tpl new file mode 100644 index 0000000000..e98c6b4e6f --- /dev/null +++ b/library/common/2101.0.0/templates/lib/chart/_names.tpl @@ -0,0 +1,66 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "common.names.name" -}} +{{- $values := (.common | default dict) -}} +{{- $name := (default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-") }} +{{- if hasKey $values "nameSuffix" -}} + {{- $name = (printf "%v-%v" $name $values.nameSuffix) -}} +{{ end -}} +{{- print $name -}} +{{- 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 "common.names.fullname" -}} +{{- $values := (.common | default dict) -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- $name = (.Release.Name | trunc 63 | trimSuffix "-") }} +{{- else }} +{{- $name = (printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-") }} +{{- end }} +{{- if hasKey $values "nameSuffix" -}} + {{- $name = (printf "%v-%v" $name $values.nameSuffix) -}} +{{ end -}} +{{- print $name -}} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "common.names.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Determine service account name for deployment or statefulset. +*/}} +{{- define "common.names.serviceAccountName" -}} +{{- if .Values.serviceAccountNameOverride }} +{{- .Values.serviceAccountNameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-service-account" (include "common.names.releaseName" .) | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} + + +{{/* +Determine release name +This will add a suffix to the release name if nameSuffix is set +*/}} +{{- define "common.names.releaseName" -}} +{{- $values := (.common | default dict) -}} +{{- if hasKey $values "nameSuffix" -}} + {{- printf "%v-%v" .Release.Name $values.nameSuffix -}} +{{- else -}} + {{- print .Release.Name -}} +{{ end -}} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/containers/_environment.tpl b/library/common/2101.0.0/templates/lib/containers/_environment.tpl new file mode 100644 index 0000000000..9d3862599b --- /dev/null +++ b/library/common/2101.0.0/templates/lib/containers/_environment.tpl @@ -0,0 +1,41 @@ +{{/* +Render environment variable +*/}} +{{- define "common.containers.environmentVariable" -}} +{{- $envVariable := . -}} +{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "name")) -}} +{{- if $envVariable.valueFromSecret -}} +{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "secretName" "secretKey")) -}} +- name: {{ $envVariable.name }} + valueFrom: + secretKeyRef: + name: {{ $envVariable.secretName }} + key: {{ $envVariable.secretKey }} +{{- else -}} +{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "value")) -}} +- name: {{ $envVariable.name }} + value: {{ $envVariable.value }} +{{- end -}} +{{- end -}} + +{{/* +Render environment variables +*/}} +{{- define "common.containers.environmentVariables" -}} +{{- $values := . -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "environmentVariables")) -}} +{{- range $envVariable := $values.environmentVariables -}} +{{- include "common.containers.environmentVariable" $envVariable | nindent 0 -}} +{{- end -}} +{{- end -}} + +{{/* +Render environment variables if present +*/}} +{{- define "common.containers.allEnvironmentVariables" -}} +{{- $values := . -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "environmentVariables")) -}} +{{- if $values.environmentVariables -}} +env: {{- include "common.containers.environmentVariables" $values | nindent 2 -}} +{{- end -}} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/containers/_image.tpl b/library/common/2101.0.0/templates/lib/containers/_image.tpl new file mode 100644 index 0000000000..4a5a368008 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/containers/_image.tpl @@ -0,0 +1,9 @@ +{{/* +Retrieve image configuration for container +*/}} +{{- define "common.containers.imageConfig" -}} +{{- $values := . -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "repository" "tag" "pullPolicy")) -}} +image: "{{ $values.repository }}:{{ $values.tag }}" +imagePullPolicy: {{ $values.pullPolicy }} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/containers/_resource.tpl b/library/common/2101.0.0/templates/lib/containers/_resource.tpl new file mode 100644 index 0000000000..fd4f6eef02 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/containers/_resource.tpl @@ -0,0 +1,10 @@ +{{/* +Retrieve GPU Configuration +*/}} +{{- define "common.containers.gpuConfiguration" -}} +{{- $values := . -}} +{{ if $values.gpuConfiguration }} +resources: + limits: {{- toYaml $values.gpuConfiguration | nindent 4 }} +{{ end }} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/deployments/_utils.tpl b/library/common/2101.0.0/templates/lib/deployments/_utils.tpl new file mode 100644 index 0000000000..b8b2f76ad5 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/deployments/_utils.tpl @@ -0,0 +1,41 @@ +{{/* +Retrieve deployment metadata +*/}} +{{- define "common.deployment.metadata" -}} +metadata: + name: {{ template "common.names.fullname" . }} + labels: {{ include "common.labels.selectorLabels" . | nindent 4 }} +{{- end -}} + + +{{/* +Retrieve replicas/strategy/selector +*/}} +{{- define "common.deployment.common_spec" -}} +replicas: {{ (default 1 .Values.replicas) }} +strategy: + type: {{ (default "Recreate" .Values.updateStrategy ) }} +selector: + matchLabels: {{ include "common.labels.selectorLabels" . | nindent 4 }} +{{- end -}} + + +{{/* +Retrieve deployment pod's metadata +*/}} +{{- define "common.deployment.pod.metadata" -}} +metadata: + name: {{ template "common.names.fullname" . }} + labels: {{ include "common.labels.selectorLabels" . | nindent 4 }} + annotations: {{ include "common.annotations" . | nindent 4 }} +{{- end -}} + + +{{/* +Retrieve common deployment configuration +*/}} +{{- define "common.deployment.common_config" -}} +apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }} +kind: Deployment +{{ include "common.deployment.metadata" . | nindent 0 }} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/networking/_dns.tpl b/library/common/2101.0.0/templates/lib/networking/_dns.tpl new file mode 100644 index 0000000000..c95d374616 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/networking/_dns.tpl @@ -0,0 +1,10 @@ +{{/* +DNS Configuration +*/}} +{{- define "common.networking.dnsConfiguration" }} +dnsPolicy: {{ .Values.dnsPolicy }} +{{- if .Values.dnsConfig }} +dnsConfig: + {{- toYaml .Values.dnsConfig | nindent 2 }} +{{- end }} +{{- end }} diff --git a/library/common/2101.0.0/templates/lib/schema/_utils.tpl b/library/common/2101.0.0/templates/lib/schema/_utils.tpl new file mode 100644 index 0000000000..8577a0b615 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/schema/_utils.tpl @@ -0,0 +1,19 @@ +{{/* +Checks if a list of keys are present in a dictionary +*/}} +{{- define "common.schema.validateKeys" -}} +{{- $values := . -}} +{{- if and (hasKey $values "values") (hasKey $values "checkKeys") -}} +{{- $missingKeys := list -}} +{{- range $values.checkKeys -}} +{{- if eq (hasKey $values.values . ) false -}} +{{- $missingKeys = mustAppend $missingKeys . -}} +{{- end -}} +{{- end -}} +{{- if $missingKeys -}} +{{- fail (printf "Missing %s from dictionary" ($missingKeys | join ", ")) -}} +{{- end -}} +{{- else -}} +{{- fail "A dictionary and list of keys to check must be provided" -}} +{{- end -}} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/storage/_appStorage.tpl b/library/common/2101.0.0/templates/lib/storage/_appStorage.tpl new file mode 100644 index 0000000000..0651870eb1 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/storage/_appStorage.tpl @@ -0,0 +1,72 @@ +{{/* +Define appVolumeMounts for container +*/}} +{{- define "common.storage.configureAppVolumeMountsInContainer" -}} +{{- include "common.schema.validateKeys" (dict "values" . "checkKeys" (list "appVolumeMounts")) -}} +{{- $appVolumeMounts := .appVolumeMounts -}} +{{- if $appVolumeMounts -}} +{{ range $name, $avm := $appVolumeMounts }} +{{- if (default true $avm.enabled) -}} +{{ if $avm.containerNameOverride }} +{{ $name = $avm.containerNameOverride }} +{{ end }} +- name: {{ $name }} + mountPath: {{ $avm.mountPath }} + {{ if $avm.subPath }} + subPath: {{ $avm.subPath }} + {{ end }} +{{- end -}} +{{ end }} +{{- end -}} +{{- end -}} + + +{{/* +Define hostPath for appVolumes +*/}} +{{- define "common.storage.configureAppVolumes" -}} +{{- include "common.schema.validateKeys" (dict "values" . "checkKeys" (list "appVolumeMounts")) -}} +{{- $values := . -}} +{{- if $values.appVolumeMounts -}} +{{- range $name, $av := $values.appVolumeMounts -}} +{{ if (default true $av.enabled) }} +- name: {{ $name }} + {{ if or $av.emptyDir $.emptyDirVolumes }} + emptyDir: {} + {{- else -}} + hostPath: + {{ if $av.hostPathEnabled }} + path: {{ required "hostPath not set" $av.hostPath }} + {{ else }} + {{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "ixVolumes")) -}} + {{- include "common.schema.validateKeys" (dict "values" $av "checkKeys" (list "datasetName")) -}} + {{- $volDict := dict "datasetName" $av.datasetName "ixVolumes" $values.ixVolumes -}} + path: {{ include "common.storage.retrieveHostPathFromiXVolume" $volDict }} + {{ end }} + {{ end }} +{{ end }} +{{- end -}} +{{- end -}} +{{- end -}} + + +{{/* +Get all volumes configuration +*/}} +{{- define "common.storage.allAppVolumes" -}} +{{- $appVolumeMounts := .appVolumeMounts -}} +{{- if $appVolumeMounts -}} +volumes: {{- include "common.storage.configureAppVolumes" . | nindent 2 -}} +{{- end -}} +{{- end -}} + + +{{/* +Get all container volume moutns configuration +*/}} +{{- define "common.storage.allContainerVolumeMounts" -}} +{{- $appVolumeMounts := .appVolumeMounts -}} +{{- if $appVolumeMounts -}} +volumeMounts: {{- include "common.storage.configureAppVolumeMountsInContainer" . | nindent 2 -}} +{{- end -}} +{{- end -}} diff --git a/library/common/2101.0.0/templates/lib/storage/_ixvolumes.tpl b/library/common/2101.0.0/templates/lib/storage/_ixvolumes.tpl new file mode 100644 index 0000000000..f45b9d8d96 --- /dev/null +++ b/library/common/2101.0.0/templates/lib/storage/_ixvolumes.tpl @@ -0,0 +1,11 @@ +{{/* +Retrieve host path from ix volumes based on dataset name +*/}} +{{- define "common.storage.retrieveHostPathFromiXVolume" -}} +{{- range $index, $hostPathConfiguration := $.ixVolumes }} +{{- $dsName := base $hostPathConfiguration.hostPath -}} +{{- if eq $.datasetName $dsName -}} +{{- $hostPathConfiguration.hostPath -}} +{{- end -}} +{{- end }} +{{- end -}} diff --git a/test/ipfs/1.0.1/Chart.yaml b/test/ipfs/1.0.1/Chart.yaml index fe0a145769..867b84777b 100644 --- a/test/ipfs/1.0.1/Chart.yaml +++ b/test/ipfs/1.0.1/Chart.yaml @@ -12,3 +12,7 @@ sources: - https://github.com/ipfs/go-ipfs - https://hub.docker.com/r/ipfs/go-ipfs upstream_version: 0.8.0-rc1 +dependencies: + - name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 diff --git a/test/ipfs/1.0.1/charts/common-2101.0.0.tgz b/test/ipfs/1.0.1/charts/common-2101.0.0.tgz new file mode 100644 index 0000000000..3a22457ea6 Binary files /dev/null and b/test/ipfs/1.0.1/charts/common-2101.0.0.tgz differ diff --git a/test/ipfs/1.0.1/default_values.yaml b/test/ipfs/1.0.1/default_values.yaml new file mode 100644 index 0000000000..407c7a3732 --- /dev/null +++ b/test/ipfs/1.0.1/default_values.yaml @@ -0,0 +1,27 @@ +## Set default image, imageTag, and imagePullPolicy. mode is used to indicate the +## +image: + repository: ipfs/go-ipfs + tag: v0.8.0-rc1 + pullPolicy: IfNotPresent + +## Additional arguments to pass to ipfs binary +extraArgs: [] + +updateStrategy: Recreate + +service: + swarmPort: 9401 + apiPort: 9501 + gatewayPort: 9080 + +environment: + +appVolumeMounts: + staging: + emptyDir: true + mountPath: "/export" + data: + emptyDir: true + mountPath: "/data/ipfs" + diff --git a/test/ipfs/1.0.1/questions.yaml b/test/ipfs/1.0.1/questions.yaml index 02d188240f..b6fe95c464 100644 --- a/test/ipfs/1.0.1/questions.yaml +++ b/test/ipfs/1.0.1/questions.yaml @@ -67,7 +67,7 @@ questions: - value: "Recreate" description: "Kill existing pods before creating new ones" - - variable: environment + - variable: environmentVariables label: "IPFS image environment" group: "IPFS Configuration" schema: @@ -121,75 +121,79 @@ questions: default: 9880 required: true - - - variable: ipfsDataHostPathEnabled - label: "Configure Host Path for IPFS data" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: ipfsDataHostPath - label: "Specify HostPath for IPFS data" - schema: - type: hostpath - - - variable: ipfsDataVolume - label: "IPFS Data Volume Defaults" + - variable: appVolumeMounts + label: "IPFS Storage" group: "Storage" schema: type: dict - $ref: - - "normalize/ixVolume" - show_if: [["ipfsDataHostPathEnabled", "=", false]] attrs: - - variable: mountPath - label: "Mount Path" - description: "Path where the volume will be mounted inside the pod" + - variable: staging + label: "Staging Volume" schema: - type: path - editable: false - default: "/data/ipfs" - - variable: datasetName - label: "IPFS Data Dataset Name" + type: dict + attrs: + - variable: datasetName + label: "IPFS Staging Volume Dataset Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-ipfs-staging" + editable: false + - variable: mountPath + label: "IPFS Staging Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: false + default: "/export" + - variable: hostPathEnabled + label: "Enable Host Path for IPFS Staging Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for IPFS Staging Volume" + schema: + type: hostpath + required: true + - variable: data + label: "Data Volume" schema: - type: string - default: "ix-ipfs-data" - editable: false - - - variable: ipfsStagingHostPathEnabled - label: "Configure Host Path for IPFS staging data" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: ipfsStagingHostPath - label: "Specify HostPath for IPFS staging data" - schema: - type: hostpath - - - variable: ipfsStagingVolume - label: "IPFS Staging Volume Defaults" - group: "Storage" - schema: - type: dict - $ref: - - "normalize/ixVolume" - show_if: [["ipfsStagingHostPathEnabled", "=", false]] - attrs: - - variable: mountPath - label: "Mount Path" - description: "Path where the volume will be mounted inside the pod" - schema: - type: path - editable: false - default: "/export" - - variable: datasetName - label: "IPFS Staging Dataset Name" - schema: - type: string - default: "ix-ipfs-staging" - editable: false + type: dict + attrs: + - variable: datasetName + label: "IPFS Data Volume Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-ipfs-data" + editable: false + - variable: mountPath + label: "IPFS Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: false + default: "/data/ipfs" + - variable: hostPathEnabled + label: "Enable Host Path for IPFS Data Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for IPFS Data Volume" + schema: + type: hostpath + required: true diff --git a/test/ipfs/1.0.1/requirements.lock b/test/ipfs/1.0.1/requirements.lock new file mode 100644 index 0000000000..114aabb0a7 --- /dev/null +++ b/test/ipfs/1.0.1/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 +digest: sha256:6ab46f958de11ae6a24d8f7e18417aa9852a8d968d5b0cc94ffa4700449931d6 +generated: "2021-02-04T01:15:55.312886+05:00" diff --git a/test/ipfs/1.0.1/templates/_helpers.tpl b/test/ipfs/1.0.1/templates/_helpers.tpl deleted file mode 100644 index 3324203697..0000000000 --- a/test/ipfs/1.0.1/templates/_helpers.tpl +++ /dev/null @@ -1,67 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "ipfs.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 "ipfs.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 "ipfs.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Return the appropriate apiVersion for deployment. -*/}} -{{- define "ipfs.deployment.apiVersion" -}} -{{- print "apps/v1" -}} -{{- end -}} - -{{/* -Return the appropriate apiVersion for statefulset. -*/}} -{{- define "ipfs.statefulset.apiVersion" -}} -{{- print "apps/v1" -}} -{{- end -}} - -{{/* -Determine secret name. -*/}} -{{- define "ipfs.secretName" -}} -{{- include "ipfs.fullname" . -}} -{{- end -}} - -{{/* -Determine service account name for deployment or statefulset. -*/}} -{{- define "ipfs.serviceAccountName" -}} -{{- (include "ipfs.fullname" .) | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Determine name for scc role and rolebinding -*/}} -{{- define "ipfs.sccRoleName" -}} -{{- printf "%s-%s" "scc" (include "ipfs.fullname" .) | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/test/ipfs/1.0.1/templates/_storage.tpl b/test/ipfs/1.0.1/templates/_storage.tpl deleted file mode 100644 index 994f15f661..0000000000 --- a/test/ipfs/1.0.1/templates/_storage.tpl +++ /dev/null @@ -1,35 +0,0 @@ -{{/* -Retrieve host path from ix volumes based on dataset name -*/}} -{{- define "retrieveHostPathFromiXVolume" -}} -{{- range $index, $hostPathConfiguration := $.ixVolumes }} -{{- $dsName := base $hostPathConfiguration.hostPath -}} -{{- if eq $.datasetName $dsName -}} -{{- $hostPathConfiguration.hostPath -}} -{{- end -}} -{{- end }} -{{- end -}} - -{{/* -Retrieve host path for ipfs -*/}} -{{- define "configuredHostPathData" -}} -{{- if .Values.ipfsDataHostPathEnabled -}} -{{- .Values.ipfsDataHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.ipfsDataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve host path for ipfs -*/}} -{{- define "configuredHostPathStaging" -}} -{{- if .Values.ipfsStagingHostPathEnabled -}} -{{- .Values.ipfsStagingHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.ipfsStagingVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} diff --git a/test/ipfs/1.0.1/templates/deployment.yaml b/test/ipfs/1.0.1/templates/deployment.yaml index af4963cca5..c830a17a16 100644 --- a/test/ipfs/1.0.1/templates/deployment.yaml +++ b/test/ipfs/1.0.1/templates/deployment.yaml @@ -1,101 +1,52 @@ -{{ $scheme := "http" }} -apiVersion: {{ template "ipfs.deployment.apiVersion" . }} +apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }} kind: Deployment metadata: - name: {{ template "ipfs.fullname" . }} - labels: - app: {{ template "ipfs.name" . }} - chart: {{ template "ipfs.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + name: {{ template "common.names.fullname" . }} + labels: {{ include "common.labels" . | nindent 4 }} spec: strategy: type: {{ .Values.updateStrategy }} selector: - matchLabels: - app: {{ template "ipfs.name" . }} - release: {{ .Release.Name }} + matchLabels: {{ include "common.labels.selectorLabels" . | nindent 6 }} template: metadata: - name: {{ template "ipfs.fullname" . }} - labels: - app: {{ template "ipfs.name" . }} - release: {{ .Release.Name }} + name: {{ template "common.names.fullname" . }} + labels: {{ include "common.labels.selectorLabels" . | nindent 8 }} spec: - serviceAccountName: {{ include "ipfs.serviceAccountName" . | quote }} + serviceAccountName: {{ include "common.names.serviceAccountName" . | quote }} initContainers: - name: init-init - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} command: ['/bin/sh', '-c', '[ ! -e /data/ipfs/config ] && (/usr/local/bin/ipfs init ; chown -R 1000:100 /data/ipfs) ; exit 0'] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} - name: init-api - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - command: ['/usr/local/bin/ipfs', 'config', 'Addresses.API', "/ip4/0.0.0.0/tcp/{{ .Values.service.apiPort}}"] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + command: ['/usr/local/bin/ipfs', 'config', 'Addresses.API', "/ip4/0.0.0.0/tcp/9501"] + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} - name: init-gateway - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - command: ['/usr/local/bin/ipfs', 'config', 'Addresses.Gateway', "/ip4/0.0.0.0/tcp/{{ .Values.service.gatewayPort}}"] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + command: ['/usr/local/bin/ipfs', 'config', 'Addresses.Gateway', "/ip4/0.0.0.0/tcp/9080"] + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} - name: init-swarm - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - command: ['/usr/local/bin/ipfs', 'config', '--json', 'Addresses.Swarm', "[\"/ip4/0.0.0.0/tcp/{{ .Values.service.swarmPort}}\",\"/ip4/0.0.0.0/tcp/{{ .Values.service.swarmPort}}/quic\"]" ] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + command: ['/usr/local/bin/ipfs', 'config', '--json', 'Addresses.Swarm', "[\"/ip4/0.0.0.0/tcp/9401\",\"/ip4/0.0.0.0/tcp/9401/quic\"]" ] + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} - name: init-access-origin - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} command: ['/usr/local/bin/ipfs', 'config', '--json', 'API.HTTPHeaders.Access-Control-Allow-Origin', "[\"*\"]" ] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} - name: init-access-methods - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} command: ['/usr/local/bin/ipfs', 'config', '--json', 'API.HTTPHeaders.Access-Control-Allow-Methods', "[\"PUT\",\"POST\"]" ] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} - name: init-chown - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} command: ['chown', '1000:100', '/data/ipfs/config'] - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} containers: - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - volumeMounts: - - name: data - mountPath: /data/ipfs - - name: staging - mountPath: /export + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} ports: - name: swarm containerPort: 9401 @@ -103,29 +54,5 @@ spec: containerPort: 9501 - name: gateway containerPort: 9880 - {{- if .Values.environment }} - env: - {{- range $envVariable := .Values.environment }} - {{- if and $envVariable.name $envVariable.value }} - - name: {{ $envVariable.name }} - value: {{ $envVariable.value | quote }} - {{- else }} - {{- fail "Please specify name/value for environment variable" }} - {{- end }} - {{- end}} - {{- end }} - volumes: - - name: data - {{- if .Values.emptyDirVolumes }} - emptyDir: {} - {{- else }} - hostPath: - path: {{ template "configuredHostPathData" . }} - {{- end }} - - name: staging - {{- if .Values.emptyDirVolumes }} - emptyDir: {} - {{- else }} - hostPath: - path: {{ template "configuredHostPathStaging" . }} - {{- end }} +{{ include "common.containers.allEnvironmentVariables" .Values | nindent 10 }} +{{ include "common.storage.allAppVolumes" .Values | nindent 6 }} diff --git a/test/ipfs/1.0.1/templates/service.yaml b/test/ipfs/1.0.1/templates/service.yaml index ad352427e8..4cc9718639 100644 --- a/test/ipfs/1.0.1/templates/service.yaml +++ b/test/ipfs/1.0.1/templates/service.yaml @@ -1,31 +1,8 @@ -{{ $scheme := "http" }} -apiVersion: v1 -kind: Service -metadata: - name: {{ template "ipfs.fullname" . }} - labels: - app: {{ template "ipfs.name" . }} - chart: {{ template "ipfs.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} -spec: - type: "NodePort" - ports: - - name: swarm - port: {{ .Values.service.swarmPort }} - protocol: TCP - nodePort: {{ .Values.service.swarmPort }} - targetPort: 9401 - - name: api - port: {{ .Values.service.apiPort }} - protocol: TCP - nodePort: {{ .Values.service.apiPort }} - targetPort: 9501 - - name: gateway - port: {{ .Values.service.gatewayPort }} - protocol: TCP - nodePort: {{ .Values.service.gatewayPort }} - targetPort: 9880 - selector: - app: {{ template "ipfs.name" . }} - release: {{ .Release.Name }} +{{ $svc := .Values.service }} +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "swarm" "port" $svc.swarmPort "nodePort" $svc.swarmPort "targetPort" 9401) }} +{{ $ports = mustAppend $ports (dict "name" "api" "port" $svc.apiPort "nodePort" $svc.apiPort "targetPort" 9501) }} +{{ $ports = mustAppend $ports (dict "name" "gateway" "port" $svc.gatewayPort "nodePort" $svc.gatewayPort "targetPort" 9880) }} +{{ $params := . }} +{{ $_ := set $params "commonService" (dict "type" "NodePort" "ports" $ports ) }} +{{ include "common.classes.service" $params }} diff --git a/test/ipfs/1.0.1/templates/serviceaccount.yaml b/test/ipfs/1.0.1/templates/serviceaccount.yaml index 05d1db5bbe..12bd3f4a39 100644 --- a/test/ipfs/1.0.1/templates/serviceaccount.yaml +++ b/test/ipfs/1.0.1/templates/serviceaccount.yaml @@ -1,9 +1 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "ipfs.serviceAccountName" . | quote }} - namespace: {{ .Release.Namespace | quote }} - labels: - app: {{ template "ipfs.name" . }} - chart: {{ template "ipfs.chart" . }} - release: "{{ .Release.Name }}" +{{ include "common.serviceaccount" . }} diff --git a/test/ipfs/1.0.1/test_values.yaml b/test/ipfs/1.0.1/test_values.yaml index 7bf4c7840b..65b840021f 100644 --- a/test/ipfs/1.0.1/test_values.yaml +++ b/test/ipfs/1.0.1/test_values.yaml @@ -15,9 +15,13 @@ service: apiPort: 30951 gatewayPort: 30980 -environment: +environmentVariables: [] emptyDirVolumes: true - -ipfsDataHostPathEnabled: false -ipfsStagingHostPathEnabled: false +appVolumeMounts: + staging: + emptyDir: true + mountPath: "/export" + data: + emptyDir: true + mountPath: "/data/ipfs" diff --git a/test/ipfs/1.0.1/values.yaml b/test/ipfs/1.0.1/values.yaml index 6c0c07c715..e69de29bb2 100644 --- a/test/ipfs/1.0.1/values.yaml +++ b/test/ipfs/1.0.1/values.yaml @@ -1,21 +0,0 @@ -## Set default image, imageTag, and imagePullPolicy. mode is used to indicate the -## -image: - repository: ipfs/go-ipfs - tag: v0.8.0-rc1 - pullPolicy: IfNotPresent - -## Additional arguments to pass to ipfs binary -extraArgs: [] - -updateStrategy: Recreate - -service: - swarmPort: 9401 - apiPort: 9501 - gatewayPort: 9080 - -environment: - -ipfsDataHostPathEnabled: false -ipfsStagingHostPathEnabled: false diff --git a/test/ix-chart/2101.0.0/Chart.lock b/test/ix-chart/2101.0.0/Chart.lock new file mode 100644 index 0000000000..f863fc9fbd --- /dev/null +++ b/test/ix-chart/2101.0.0/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 +digest: sha256:6ab46f958de11ae6a24d8f7e18417aa9852a8d968d5b0cc94ffa4700449931d6 +generated: "2021-02-04T01:15:55.365517+05:00" diff --git a/test/ix-chart/2101.0.0/Chart.yaml b/test/ix-chart/2101.0.0/Chart.yaml index 3d45a108e3..2cda32577f 100644 --- a/test/ix-chart/2101.0.0/Chart.yaml +++ b/test/ix-chart/2101.0.0/Chart.yaml @@ -21,3 +21,8 @@ version: 2101.0.0 # 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. appVersion: v1 +dependencies: + - name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 + diff --git a/test/ix-chart/2101.0.0/charts/common-2101.0.0.tgz b/test/ix-chart/2101.0.0/charts/common-2101.0.0.tgz new file mode 100644 index 0000000000..3a22457ea6 Binary files /dev/null and b/test/ix-chart/2101.0.0/charts/common-2101.0.0.tgz differ diff --git a/test/ix-chart/2101.0.0/default_values.yaml b/test/ix-chart/2101.0.0/default_values.yaml new file mode 100644 index 0000000000..af4b34a1d5 --- /dev/null +++ b/test/ix-chart/2101.0.0/default_values.yaml @@ -0,0 +1,37 @@ +# Default values for ix-chart. + +image: + repository: debian + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" + +# Restart / Update policy +updateStrategy: RollingUpdate + +# Container CMD / entrypoint +containerCommand: [] +containerArgs: [] +containerEnvironmentVariables: [] + +# Network related configuration +externalInterfaces: [] +portForwardingList: [] +hostNetwork: false +dnsPolicy: Default +dnsConfig: + nameservers: [] + searches: [] + +# Storage related configuration +hostPathVolumes: [] +volumes: [] + +# Probes +# Liveness Probe +livenessProbe: null + +# Workload type +workloadType: "Deployment" + +gpuConfiguration: {} diff --git a/test/ix-chart/2101.0.0/values.yaml b/test/ix-chart/2101.0.0/values.yaml index af4b34a1d5..e69de29bb2 100644 --- a/test/ix-chart/2101.0.0/values.yaml +++ b/test/ix-chart/2101.0.0/values.yaml @@ -1,37 +0,0 @@ -# Default values for ix-chart. - -image: - repository: debian - pullPolicy: IfNotPresent - # Overrides the image tag whose default is the chart appVersion. - tag: "latest" - -# Restart / Update policy -updateStrategy: RollingUpdate - -# Container CMD / entrypoint -containerCommand: [] -containerArgs: [] -containerEnvironmentVariables: [] - -# Network related configuration -externalInterfaces: [] -portForwardingList: [] -hostNetwork: false -dnsPolicy: Default -dnsConfig: - nameservers: [] - searches: [] - -# Storage related configuration -hostPathVolumes: [] -volumes: [] - -# Probes -# Liveness Probe -livenessProbe: null - -# Workload type -workloadType: "Deployment" - -gpuConfiguration: {} diff --git a/test/minio/1.0.1/templates/_helpers.tpl b/test/minio/1.0.1/templates/_helpers.tpl deleted file mode 100644 index aa82dc8b17..0000000000 --- a/test/minio/1.0.1/templates/_helpers.tpl +++ /dev/null @@ -1,84 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "minio.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 "minio.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 "minio.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Return the appropriate apiVersion for deployment. -*/}} -{{- define "minio.deployment.apiVersion" -}} -{{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.Version -}} -{{- print "apps/v1beta2" -}} -{{- else -}} -{{- print "apps/v1" -}} -{{- end -}} -{{- end -}} - -{{/* -Return the appropriate apiVersion for statefulset. -*/}} -{{- define "minio.statefulset.apiVersion" -}} -{{- if semverCompare "<1.17-0" .Capabilities.KubeVersion.Version -}} -{{- print "apps/v1beta2" -}} -{{- else -}} -{{- print "apps/v1" -}} -{{- end -}} -{{- end -}} - -{{/* -Determine secret name. -*/}} -{{- define "minio.secretName" -}} -{{- include "minio.fullname" . -}} -{{- end -}} - -{{/* -Determine service account name for deployment or statefulset. -*/}} -{{- define "minio.serviceAccountName" -}} -{{- (include "minio.fullname" .) | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Determine name for scc role and rolebinding -*/}} -{{- define "minio.sccRoleName" -}} -{{- printf "%s-%s" "scc" (include "minio.fullname" .) | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Properly format optional additional arguments to Minio binary -*/}} -{{- define "minio.extraArgs" -}} -{{- range .Values.extraArgs -}} -{{ " " }}{{ . }} -{{- end -}} -{{- end -}} diff --git a/test/minio/1.0.1/templates/_storage.tpl b/test/minio/1.0.1/templates/_storage.tpl deleted file mode 100644 index 062eb2cb7c..0000000000 --- a/test/minio/1.0.1/templates/_storage.tpl +++ /dev/null @@ -1,23 +0,0 @@ -{{/* -Retrieve host path from ix volumes based on dataset name -*/}} -{{- define "retrieveHostPathFromiXVolume" -}} -{{- range $index, $hostPathConfiguration := $.ixVolumes }} -{{- $dsName := base $hostPathConfiguration.hostPath -}} -{{- if eq $.datasetName $dsName -}} -{{- $hostPathConfiguration.hostPath -}} -{{- end -}} -{{- end }} -{{- end -}} - -{{/* -Retrieve host path for minio -*/}} -{{- define "configuredMinioHostPath" -}} -{{- if .Values.minioHostPathEnabled -}} -{{- .Values.minioHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.minioDataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} diff --git a/test/minio/1.0.1/templates/deployment.yaml b/test/minio/1.0.1/templates/deployment.yaml deleted file mode 100644 index 407bba80f2..0000000000 --- a/test/minio/1.0.1/templates/deployment.yaml +++ /dev/null @@ -1,71 +0,0 @@ -{{ $scheme := "http" }} -apiVersion: {{ template "minio.deployment.apiVersion" . }} -kind: Deployment -metadata: - name: {{ template "minio.fullname" . }} - labels: - app: {{ template "minio.name" . }} - chart: {{ template "minio.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} -spec: - strategy: - type: {{ .Values.updateStrategy }} - selector: - matchLabels: - app: {{ template "minio.name" . }} - release: {{ .Release.Name }} - template: - metadata: - name: {{ template "minio.fullname" . }} - labels: - app: {{ template "minio.name" . }} - release: {{ .Release.Name }} - annotations: - checksum/secrets: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }} - spec: - serviceAccountName: {{ include "minio.serviceAccountName" . | quote }} - containers: - - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - command: - - "/bin/sh" - - "-ce" - - "/usr/bin/docker-entrypoint.sh minio server /export {{- template "minio.extraArgs" . }}" - volumeMounts: - - name: export - mountPath: /export - ports: - - name: {{ $scheme }} - containerPort: 9000 - env: - - name: MINIO_ACCESS_KEY - valueFrom: - secretKeyRef: - name: {{ template "minio.secretName" . }} - key: accesskey - - name: MINIO_SECRET_KEY - valueFrom: - secretKeyRef: - name: {{ template "minio.secretName" . }} - key: secretkey - {{- range $envVariable := .Values.environmentVariables }} - {{- if and $envVariable.name $envVariable.value }} - - name: {{ $envVariable.name }} - value: {{ $envVariable.value | quote }} - {{- else }} - {{- fail "Please specify name/value for environment variable" }} - {{- end }} - {{- end}} - volumes: - - name: export - {{- if .Values.emptyDirVolumes }} - emptyDir: {} - {{- else }} - hostPath: - path: {{ template "configuredMinioHostPath" . }} - {{- end }} - - name: minio-user - secret: - secretName: {{ template "minio.secretName" . }} diff --git a/test/minio/1.0.1/templates/service.yaml b/test/minio/1.0.1/templates/service.yaml deleted file mode 100644 index 3f0c68b930..0000000000 --- a/test/minio/1.0.1/templates/service.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{ $scheme := "http" }} -apiVersion: v1 -kind: Service -metadata: - name: {{ template "minio.fullname" . }} - labels: - app: {{ template "minio.name" . }} - chart: {{ template "minio.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} -spec: - type: "NodePort" - ports: - - name: {{ $scheme }} - port: {{ .Values.service.nodePort }} - protocol: TCP - nodePort: {{ .Values.service.nodePort }} - targetPort: 9000 - selector: - app: {{ template "minio.name" . }} - release: {{ .Release.Name }} diff --git a/test/minio/1.0.1/templates/serviceaccount.yaml b/test/minio/1.0.1/templates/serviceaccount.yaml deleted file mode 100644 index 2db987867a..0000000000 --- a/test/minio/1.0.1/templates/serviceaccount.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "minio.serviceAccountName" . | quote }} - namespace: {{ .Release.Namespace | quote }} - labels: - app: {{ template "minio.name" . }} - chart: {{ template "minio.chart" . }} - release: "{{ .Release.Name }}" diff --git a/test/minio/1.0.1/.helmignore b/test/minio/1.1.0/.helmignore similarity index 100% rename from test/minio/1.0.1/.helmignore rename to test/minio/1.1.0/.helmignore diff --git a/test/minio/1.0.1/Chart.yaml b/test/minio/1.1.0/Chart.yaml similarity index 72% rename from test/minio/1.0.1/Chart.yaml rename to test/minio/1.1.0/Chart.yaml index 787ff43d43..52ba59d832 100644 --- a/test/minio/1.0.1/Chart.yaml +++ b/test/minio/1.1.0/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: High Performance, Kubernetes Native Object Storage name: minio -version: 1.0.1 +version: 1.1.0 appVersion: master keywords: - storage @@ -13,3 +13,7 @@ sources: - https://github.com/minio/minio - https://github.com/minio/charts upstream_version: 8.0.5 +dependencies: + - name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 diff --git a/test/minio/1.0.1/README.md b/test/minio/1.1.0/README.md similarity index 100% rename from test/minio/1.0.1/README.md rename to test/minio/1.1.0/README.md diff --git a/test/minio/1.0.1/app-readme.md b/test/minio/1.1.0/app-readme.md similarity index 100% rename from test/minio/1.0.1/app-readme.md rename to test/minio/1.1.0/app-readme.md diff --git a/test/minio/1.1.0/charts/common-2101.0.0.tgz b/test/minio/1.1.0/charts/common-2101.0.0.tgz new file mode 100644 index 0000000000..3a22457ea6 Binary files /dev/null and b/test/minio/1.1.0/charts/common-2101.0.0.tgz differ diff --git a/test/minio/1.0.1/values.yaml b/test/minio/1.1.0/default_values.yaml similarity index 85% rename from test/minio/1.0.1/values.yaml rename to test/minio/1.1.0/default_values.yaml index 702573e993..7afa31dc0d 100644 --- a/test/minio/1.0.1/values.yaml +++ b/test/minio/1.1.0/default_values.yaml @@ -15,3 +15,8 @@ service: environment: ## Please refer for comprehensive list https://docs.minio.io/docs/minio-server-configuration-guide.html + +appVolumeMounts: + export: + emptyDir: true + mountPath: "/export" diff --git a/test/minio/1.1.0/migrations/migrate b/test/minio/1.1.0/migrations/migrate new file mode 100755 index 0000000000..f65d82b628 --- /dev/null +++ b/test/minio/1.1.0/migrations/migrate @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +import json +import os +import sys + + +def migrate(values): + values.update({ + 'appVolumeMounts': { + 'export': { + 'hostPathEnabled': values['minioHostPathEnabled'], + **({'hostPath': values['minioHostPath']} if values.get('minioHostPath') else {}) + }, + }, + }) + return values + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + if os.path.exists(sys.argv[1]): + with open(sys.argv[1], 'r') as f: + print(json.dumps(migrate(json.loads(f.read())))) diff --git a/test/minio/1.0.1/questions.yaml b/test/minio/1.1.0/questions.yaml similarity index 73% rename from test/minio/1.0.1/questions.yaml rename to test/minio/1.1.0/questions.yaml index ea803a6911..e4753328ae 100644 --- a/test/minio/1.0.1/questions.yaml +++ b/test/minio/1.1.0/questions.yaml @@ -138,38 +138,44 @@ questions: default: 9000 required: true - - variable: minioHostPathEnabled - label: "Configure Host Path for Minio data" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: minioHostPath - label: "Specify HostPath for Minio data" - schema: - type: hostpath - - - variable: minioDataVolume - label: "Minio Data Volume Defaults" + - variable: appVolumeMounts + label: "Minio Storage" group: "Storage" schema: type: dict - $ref: - - "normalize/ixVolume" - show_if: [["minioHostPathEnabled", "=", false]] attrs: - - variable: mountPath - label: "Minio Data Mount Path" - description: "Path where the volume will be mounted inside the pod" + - variable: export + label: "Data Volume" schema: - type: path - editable: false - default: "/export" - - variable: datasetName - label: "Minio Dataset Name" - schema: - type: string - default: "ix-minio" - editable: false + type: dict + attrs: + - variable: datasetName + label: "Minio Data Volume Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-minio" + editable: false + - variable: mountPath + label: "Minio Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: false + default: "/export" + - variable: hostPathEnabled + label: "Enable Host Path for Minio Data Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Minio Data Volume" + schema: + type: hostpath + required: true diff --git a/test/minio/1.1.0/requirements.lock b/test/minio/1.1.0/requirements.lock new file mode 100644 index 0000000000..74ceebcbc1 --- /dev/null +++ b/test/minio/1.1.0/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 +digest: sha256:6ab46f958de11ae6a24d8f7e18417aa9852a8d968d5b0cc94ffa4700449931d6 +generated: "2021-02-04T01:15:55.416388+05:00" diff --git a/test/minio/1.0.1/templates/NOTES.txt b/test/minio/1.1.0/templates/NOTES.txt similarity index 100% rename from test/minio/1.0.1/templates/NOTES.txt rename to test/minio/1.1.0/templates/NOTES.txt diff --git a/test/minio/1.1.0/templates/_helpers.tpl b/test/minio/1.1.0/templates/_helpers.tpl new file mode 100644 index 0000000000..c769c2fb2a --- /dev/null +++ b/test/minio/1.1.0/templates/_helpers.tpl @@ -0,0 +1,6 @@ +{{/* +Determine secret name. +*/}} +{{- define "minio.secretName" -}} +{{- include "common.names.fullname" . -}} +{{- end -}} diff --git a/test/minio/1.1.0/templates/deployment.yaml b/test/minio/1.1.0/templates/deployment.yaml new file mode 100644 index 0000000000..aed4ad032b --- /dev/null +++ b/test/minio/1.1.0/templates/deployment.yaml @@ -0,0 +1,46 @@ +{{ $scheme := "http" }} +apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }} +kind: Deployment +metadata: + name: {{ template "common.names.fullname" . }} + labels: + app: {{ template "common.names.name" . }} + chart: {{ template "common.names.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ (default 1 .Values.replicas) }} + strategy: + type: {{ (default "Recreate" .Values.updateStrategy ) }} + selector: + matchLabels: + app: {{ template "common.names.name" . }} + release: {{ .Release.Name }} + template: + metadata: + name: {{ template "common.names.fullname" . }} + labels: + app: {{ template "common.names.name" . }} + release: {{ .Release.Name }} + {{- include "common.labels.selectorLabels" . | nindent 8 }} + annotations: {{ include "common.annotations" . | nindent 8 }} + spec: + serviceAccountName: {{ include "common.names.serviceAccountName" . | quote }} + containers: + - name: {{ .Chart.Name }} + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} + command: + - "/bin/sh" + - "-ce" + - "/usr/bin/docker-entrypoint.sh minio server /export {{ (.Values.extraArgs | default list) | join " " }}" + ports: + - name: {{ $scheme }} + containerPort: 9000 + env: + {{ $secretName := (include "minio.secretName" .) }} + {{ $envList := (default list .Values.environment) }} + {{ $envList = mustAppend $envList (dict "name" "MINIO_ACCESS_KEY" "valueFromSecret" true "secretName" $secretName "secretKey" "accesskey") }} + {{ $envList = mustAppend $envList (dict "name" "MINIO_SECRET_KEY" "valueFromSecret" true "secretName" $secretName "secretKey" "secretkey") }} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }} +{{ include "common.storage.allAppVolumes" .Values | nindent 6 }} diff --git a/test/minio/1.0.1/templates/secrets.yaml b/test/minio/1.1.0/templates/secrets.yaml similarity index 71% rename from test/minio/1.0.1/templates/secrets.yaml rename to test/minio/1.1.0/templates/secrets.yaml index c62e183a35..f44495e5e1 100644 --- a/test/minio/1.0.1/templates/secrets.yaml +++ b/test/minio/1.1.0/templates/secrets.yaml @@ -2,11 +2,7 @@ apiVersion: v1 kind: Secret metadata: name: {{ template "minio.secretName" . }} - labels: - app: {{ template "minio.name" . }} - chart: {{ template "minio.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + labels: {{ include "common.labels" . | nindent 4 }} type: Opaque data: accesskey: {{ if .Values.accessKey }}{{ .Values.accessKey | toString | b64enc | quote }}{{ else }}{{ randAlphaNum 20 | b64enc | quote }}{{ end }} diff --git a/test/minio/1.1.0/templates/service.yaml b/test/minio/1.1.0/templates/service.yaml new file mode 100644 index 0000000000..34e44be851 --- /dev/null +++ b/test/minio/1.1.0/templates/service.yaml @@ -0,0 +1,10 @@ +{{ $svc := .Values.service }} +{{ $selectors := list }} +{{ $selectors = mustAppend $selectors (dict "key" "app" "value" (include "common.names.name" .) ) }} +{{ $selectors = mustAppend $selectors (dict "key" "release" "value" .Release.Name ) }} +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "http" "port" $svc.nodePort "nodePort" $svc.nodePort "targetPort" 9000) }} +{{ $params := . }} +{{ $_ := set $params "commonService" (dict "type" "NodePort" "ports" $ports ) }} +{{ $_1 := set .Values "extraSelectorLabels" $selectors }} +{{ include "common.classes.service" $params }} diff --git a/test/minio/1.1.0/templates/serviceaccount.yaml b/test/minio/1.1.0/templates/serviceaccount.yaml new file mode 100644 index 0000000000..12bd3f4a39 --- /dev/null +++ b/test/minio/1.1.0/templates/serviceaccount.yaml @@ -0,0 +1 @@ +{{ include "common.serviceaccount" . }} diff --git a/test/minio/1.0.1/test_values.yaml b/test/minio/1.1.0/test_values.yaml similarity index 81% rename from test/minio/1.0.1/test_values.yaml rename to test/minio/1.1.0/test_values.yaml index 464cfbfa87..383d0bbdd5 100644 --- a/test/minio/1.0.1/test_values.yaml +++ b/test/minio/1.1.0/test_values.yaml @@ -13,7 +13,11 @@ updateStrategy: RollingUpdate service: nodePort: 32001 -environment: +environmentVariables: [] ## Please refer for comprehensive list https://docs.minio.io/docs/minio-server-configuration-guide.html emptyDirVolumes: true +appVolumeMounts: + export: + emptyDir: true + mountPath: "/export" diff --git a/test/nextcloud/1.1.0/templates/_backup.tpl b/test/minio/1.1.0/values.yaml similarity index 100% rename from test/nextcloud/1.1.0/templates/_backup.tpl rename to test/minio/1.1.0/values.yaml diff --git a/test/nextcloud/1.1.0/templates/_helpers.tpl b/test/nextcloud/1.1.0/templates/_helpers.tpl deleted file mode 100644 index 43114be492..0000000000 --- a/test/nextcloud/1.1.0/templates/_helpers.tpl +++ /dev/null @@ -1,114 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "nextcloud.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 "nextcloud.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 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). -*/}} -{{- define "nextcloud.mariadb.fullname" -}} -{{- printf "%s-%s" .Release.Name "mariadb" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - - -{{/* -Create a default fully qualified redis app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "nextcloud.redis.fullname" -}} -{{- printf "%s-%s" .Release.Name "redis" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "nextcloud.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Retrieve host path from ix volumes based on dataset name -*/}} -{{- define "retrieveHostPathFromiXVolume" -}} -{{- range $index, $hostPathConfiguration := $.ixVolumes }} -{{- $dsName := base $hostPathConfiguration.hostPath -}} -{{- if eq $.datasetName $dsName -}} -{{- $hostPathConfiguration.hostPath -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve host path defined in volume -*/}} -{{- define "configuredHostPath" -}} -{{- if .Values.emptyDirVolumes -}} -{{- printf "" -}} -{{- else if .Values.nextcloudDataHostPathEnabled -}} -{{- required "Please specify a host path for nextcloud" .Values.nextcloudHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.nextcloudDataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve backup postgresql host path defined in volume -*/}} -{{- define "configuredBackupPostgresHostPath" -}} -{{- if .Values.emptyDirVolumes -}} -{{- printf "" -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.postgresBackupVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve postgresql data host path defined in volume -*/}} -{{- define "configuredPostgresHostPath" -}} -{{- if .Values.emptyDirVolumes -}} -{{- printf "" -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.postgresDataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "nextcloud.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nextcloud.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end }} - -{{/* -Nextcloud service account -*/}} -{{- define "nextcloud.serviceAccountName" -}} -{{- printf "%s-service-account" .Release.Name -}} -{{- end -}} diff --git a/test/nextcloud/1.1.0/templates/_postgres.tpl b/test/nextcloud/1.1.0/templates/_postgres.tpl deleted file mode 100644 index 038a680c80..0000000000 --- a/test/nextcloud/1.1.0/templates/_postgres.tpl +++ /dev/null @@ -1,28 +0,0 @@ -{{/* -Get Nextloud Postgres Database Name -*/}} -{{- define "postgres.DatabaseName" -}} -{{- print "nextcloud" -}} -{{- end -}} - -{{/* -Postgres Selector labels -*/}} -{{- define "nextcloud.postgres.selectorLabels" -}} -app.kubernetes.io/name: {{ include "nextcloud.name" . }}-postgres -app.kubernetes.io/instance: {{ .Release.Name }}-postgres -{{- end }} - -{{- define "postgres.imageName" -}} -{{- print "postgres:13.1" -}} -{{- end -}} - -{{/* -Retrieve postgres backup name -This will return a unique name based on revision and chart numbers specified. -*/}} -{{- define "postgres.backupName" -}} -{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}} -{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}} -{{- end }} - diff --git a/test/nextcloud/1.1.0/templates/_upgrade.tpl b/test/nextcloud/1.1.0/templates/_upgrade.tpl deleted file mode 100644 index eb0ae1e660..0000000000 --- a/test/nextcloud/1.1.0/templates/_upgrade.tpl +++ /dev/null @@ -1,21 +0,0 @@ -{{/* -Retrieve previous chart version from which we are upgrading to a newer chart version -*/}} -{{- define "tn.chart.old_version" -}} -{{- if .Values.ixChartContext.is_upgrade -}} -{{- .Values.ixChartContext.upgradeMetadata.oldChartVersion -}} -{{- else -}} -{{- fail "A chart upgrade is not taking place" -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve new chart version to which we are upgrading from an old chart version -*/}} -{{- define "tn.chart.new_version" -}} -{{- if .Values.ixChartContext.is_upgrade -}} -{{- .Values.ixChartContext.upgradeMetadata.newChartVersion -}} -{{- else -}} -{{- fail "A chart upgrade is not taking place" -}} -{{- end -}} -{{- end -}} diff --git a/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml b/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml deleted file mode 100644 index 3f6c6dc366..0000000000 --- a/test/nextcloud/1.1.0/templates/backup-postgres-hook.yaml +++ /dev/null @@ -1,57 +0,0 @@ -{{- if .Values.ixChartContext.isUpgrade -}} -apiVersion: batch/v1 -kind: Job -metadata: - name: "pre-upgrade-hook2" - annotations: - "helm.sh/hook": pre-upgrade - "helm.sh/hook-weight": "1" - "helm.sh/hook-delete-policy": hook-succeeded - rollme: {{ randAlphaNum 5 | quote }} -spec: - template: - metadata: - name: "pre-upgrade-hook2" - spec: - restartPolicy: Never - serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" - containers: - - name: {{ .Chart.Name }}-postgres-backup - image: {{ template "postgres.imageName" . }} - imagePullPolicy: {{ .Values.image.pullPolicy }} - env: - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - name: db-details - key: db-user - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: db-details - key: db-password - - name: BACKUP_NAME - value: {{ template "postgres.backupName" . }} - volumeMounts: - - name: postgres-data - mountPath: /var/lib/postgresql/data - - name: postgres-backup - mountPath: /postgres_backups - - name: backup-script-configmap - mountPath: /bin/backup_entrypoint.sh - readOnly: true - subPath: entrypoint.sh - command: - - "/bin/backup_entrypoint.sh" - volumes: - - name: postgres-data - hostPath: - path: {{ template "configuredPostgresHostPath" . }} - - name: postgres-backup - hostPath: - path: {{ template "configuredBackupPostgresHostPath" . }} - - name: backup-script-configmap - configMap: - defaultMode: 0700 - name: "postgres-backup-hook-config-map" -{{- end -}} diff --git a/test/nextcloud/1.1.0/templates/deployment.yaml b/test/nextcloud/1.1.0/templates/deployment.yaml deleted file mode 100644 index a4cfd7c2d7..0000000000 --- a/test/nextcloud/1.1.0/templates/deployment.yaml +++ /dev/null @@ -1,113 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ template "nextcloud.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "nextcloud.name" . }} - helm.sh/chart: {{ include "nextcloud.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} - app.kubernetes.io/component: app - {{- if .Values.deploymentAnnotations }} - annotations: -{{ toYaml .Values.deploymentAnnotations | indent 4 }} - {{- end }} -spec: - replicas: 1 - strategy: - type: {{ .Values.nextcloud.strategy }} - selector: - matchLabels: - app.kubernetes.io/name: {{ include "nextcloud.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/component: app - template: - metadata: - labels: - app.kubernetes.io/name: {{ include "nextcloud.name" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/component: app - annotations: - rollme: {{ randAlphaNum 5 | quote }} - spec: - {{- if .Values.image.pullSecrets }} - imagePullSecrets: - {{- range .Values.image.pullSecrets }} - - name: {{ . }} - {{- end}} - {{- end }} - initContainers: - - name: init-postgresdb - image: {{ template "postgres.imageName" . }} - command: ['sh', '-c', "until pg_isready -h {{ template "nextcloud.fullname" . }}-postgres; do echo waiting for postgres; sleep 2; done"] - imagePullPolicy: {{ .Values.image.pullPolicy }} - containers: - - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - env: - - name: POSTGRES_HOST - value: {{ template "nextcloud.fullname" . }}-postgres:5432 - - name: POSTGRES_DB - value: {{ template "postgres.DatabaseName" . }} - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - name: db-details - key: db-user - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: db-details - key: db-password - - name: NEXTCLOUD_ADMIN_USER - valueFrom: - secretKeyRef: - name: {{ template "nextcloud.fullname" . }} - key: nextcloud-username - - name: NEXTCLOUD_ADMIN_PASSWORD - valueFrom: - secretKeyRef: - name: {{ template "nextcloud.fullname" . }} - key: nextcloud-password - - name: NEXTCLOUD_TRUSTED_DOMAINS - value: {{ .Values.nextcloud.host }} - - name: NEXTCLOUD_DATA_DIR - value: {{ .Values.nextcloud.datadir | quote }} - ports: - - name: http - containerPort: 80 - protocol: TCP - volumeMounts: - - name: nextcloud-data - mountPath: /var/www/ - subPath: "root" - - name: nextcloud-data - mountPath: /var/www/html - subPath: "html" - - name: nextcloud-data - mountPath: {{ .Values.nextcloud.datadir }} - subPath: "data" - - name: nextcloud-data - mountPath: /var/www/html/config - subPath: "config" - - name: nextcloud-data - mountPath: /var/www/html/custom_apps - subPath: "custom_apps" - - name: nextcloud-data - mountPath: /var/www/tmp - subPath: "tmp" - - name: nextcloud-data - mountPath: /var/www/html/themes - subPath: "themes" - volumes: - - name: nextcloud-data - {{- if ne (include "configuredHostPath" .) "" }} - hostPath: - path: {{ template "configuredHostPath" . }} - {{- else }} - emptyDir: {} - {{- end }} - # Will mount configuration files as www-data (id: 33) for nextcloud - securityContext: - fsGroup: 33 diff --git a/test/nextcloud/1.1.0/templates/postgres-deployment.yaml b/test/nextcloud/1.1.0/templates/postgres-deployment.yaml deleted file mode 100644 index 47ce936339..0000000000 --- a/test/nextcloud/1.1.0/templates/postgres-deployment.yaml +++ /dev/null @@ -1,64 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ template "nextcloud.fullname" . }}-postgres - labels: - helm.sh/chart: {{ include "nextcloud.chart" . }} - {{- include "nextcloud.postgres.selectorLabels" . | nindent 4 }} - app.kubernetes.io/managed-by: {{ .Release.Service }} - app.kubernetes.io/component: database -spec: - replicas: 1 - strategy: - type: {{ .Values.nextcloud.strategy }} - selector: - matchLabels: - {{- include "nextcloud.postgres.selectorLabels" . | nindent 6 }} - app.kubernetes.io/component: database - template: - metadata: - labels: - {{- include "nextcloud.postgres.selectorLabels" . | nindent 8 }} - app.kubernetes.io/component: database - annotations: - rollme: {{ randAlphaNum 5 | quote }} - spec: - containers: - - name: {{ .Chart.Name }}-postgres - image: {{ template "postgres.imageName" . }} - imagePullPolicy: {{ .Values.image.pullPolicy }} - env: - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - name: db-details - key: db-user - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: db-details - key: db-password - volumeMounts: - - name: postgres-data - mountPath: /var/lib/postgresql/data - - name: postgres-backup - mountPath: /postgres_backups - ports: - - name: postgres-tcp - containerPort: 5432 - protocol: TCP - volumes: - - name: postgres-data - {{- if ne (include "configuredPostgresHostPath" .) "" }} - hostPath: - path: {{ template "configuredPostgresHostPath" . }} - {{- else }} - emptyDir: {} - {{- end }} - - name: postgres-backup - {{- if ne (include "configuredBackupPostgresHostPath" .) "" }} - hostPath: - path: {{ template "configuredBackupPostgresHostPath" . }} - {{- else }} - emptyDir: {} - {{- end }} diff --git a/test/nextcloud/1.1.0/templates/postgres-service.yaml b/test/nextcloud/1.1.0/templates/postgres-service.yaml deleted file mode 100644 index 4d2837e4d5..0000000000 --- a/test/nextcloud/1.1.0/templates/postgres-service.yaml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "nextcloud.fullname" . }}-postgres - labels: - app.kubernetes.io/name: {{ include "nextcloud.name" . }}-postgres - helm.sh/chart: {{ include "nextcloud.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} - app.kubernetes.io/component: app -spec: - type: ClusterIP - ports: - - port: 5432 - protocol: TCP - name: postgres-tcp - selector: - {{- include "nextcloud.postgres.selectorLabels" . | nindent 4 }} diff --git a/test/nextcloud/1.1.0/templates/service.yaml b/test/nextcloud/1.1.0/templates/service.yaml deleted file mode 100644 index 3e2287d196..0000000000 --- a/test/nextcloud/1.1.0/templates/service.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "nextcloud.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "nextcloud.name" . }} - helm.sh/chart: {{ include "nextcloud.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} - app.kubernetes.io/component: app -spec: - type: NodePort - ports: - - port: 80 - targetPort: http - protocol: TCP - name: http - nodePort: {{ default "" .Values.service.nodePort}} - selector: - {{- include "nextcloud.selectorLabels" . | nindent 4 }} diff --git a/test/nextcloud/1.1.0/values.yaml b/test/nextcloud/1.1.0/values.yaml deleted file mode 100644 index b60ae4172f..0000000000 --- a/test/nextcloud/1.1.0/values.yaml +++ /dev/null @@ -1,17 +0,0 @@ -## Official nextcloud image version -## ref: https://hub.docker.com/r/library/nextcloud/tags/ -## -image: - repository: nextcloud - tag: 19.0.3-apache - pullPolicy: IfNotPresent - -nextcloud: - host: nextcloud.kube.home - username: admin - password: changeme - datadir: /var/www/html/data - strategy: "Recreate" - -service: - nodePort: 9001 diff --git a/test/nextcloud/1.1.0/.helmignore b/test/nextcloud/1.2.0/.helmignore similarity index 100% rename from test/nextcloud/1.1.0/.helmignore rename to test/nextcloud/1.2.0/.helmignore diff --git a/test/nextcloud/1.2.0/Chart.lock b/test/nextcloud/1.2.0/Chart.lock new file mode 100644 index 0000000000..7d79320192 --- /dev/null +++ b/test/nextcloud/1.2.0/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 +digest: sha256:6ab46f958de11ae6a24d8f7e18417aa9852a8d968d5b0cc94ffa4700449931d6 +generated: "2021-02-04T01:15:55.262077+05:00" diff --git a/test/nextcloud/1.1.0/Chart.yaml b/test/nextcloud/1.2.0/Chart.yaml similarity index 78% rename from test/nextcloud/1.1.0/Chart.yaml rename to test/nextcloud/1.2.0/Chart.yaml index df04f529d5..4639feeae2 100644 --- a/test/nextcloud/1.1.0/Chart.yaml +++ b/test/nextcloud/1.2.0/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: nextcloud -version: 1.1.0 +version: 1.2.0 appVersion: 19.0.3 description: A file sharing server that puts the control and security of your own data back into your hands. keywords: @@ -15,3 +15,8 @@ sources: - https://github.com/nextcloud/docker - https://github.com/nextcloud/helm upstream_version: 2.3.2 +dependencies: + - name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 + diff --git a/test/nextcloud/1.1.0/README.md b/test/nextcloud/1.2.0/README.md similarity index 100% rename from test/nextcloud/1.1.0/README.md rename to test/nextcloud/1.2.0/README.md diff --git a/test/nextcloud/1.1.0/app-readme.md b/test/nextcloud/1.2.0/app-readme.md similarity index 100% rename from test/nextcloud/1.1.0/app-readme.md rename to test/nextcloud/1.2.0/app-readme.md diff --git a/test/nextcloud/1.2.0/charts/common-2101.0.0.tgz b/test/nextcloud/1.2.0/charts/common-2101.0.0.tgz new file mode 100644 index 0000000000..3a22457ea6 Binary files /dev/null and b/test/nextcloud/1.2.0/charts/common-2101.0.0.tgz differ diff --git a/test/nextcloud/1.1.0/test_values.yaml b/test/nextcloud/1.2.0/default_values.yaml similarity index 66% rename from test/nextcloud/1.1.0/test_values.yaml rename to test/nextcloud/1.2.0/default_values.yaml index 13feb4fc96..6de7de5f74 100644 --- a/test/nextcloud/1.1.0/test_values.yaml +++ b/test/nextcloud/1.2.0/default_values.yaml @@ -13,16 +13,18 @@ nextcloud: datadir: /var/www/html/data strategy: "Recreate" -postgresql: - backupVolume: - mountPath: "/postgres_backups" - datasetName: "ix-postgres_backups" - dataVolume: - mountPath: "/var/lib/postgresql/data" - datasetName: "ix-postgres_data" - service: - nodePort: 31000 + nodePort: 9001 -emptyDirVolumes: true -ixChartContext: {} +appVolumeMounts: + nextcloud-data: + emptyDir: true + mountPath: "/var/www" + +postgresAppVolumeMounts: + postgres-data: + emptyDir: true + mountPath: "/var/lib/postgresql/data" + postgres-backup: + emptyDir: true + mountPath: "/postgres_backups" diff --git a/test/nextcloud/1.2.0/migrations/migrate b/test/nextcloud/1.2.0/migrations/migrate new file mode 100755 index 0000000000..1977bf3806 --- /dev/null +++ b/test/nextcloud/1.2.0/migrations/migrate @@ -0,0 +1,26 @@ +#!/usr/bin/python3 +import json +import os +import sys + + +def migrate(values): + values.update({ + 'appVolumeMounts': { + 'nextcloud-data': { + 'hostPathEnabled': values['nextcloudDataHostPathEnabled'], + **({'hostPath': values['nextcloudHostPath']} if values.get('nextcloudHostPath') else {}) + }, + }, + 'updateStrategy': values.get('nextcloud').get('strategy', 'Recreate'), + }) + return values + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + if os.path.exists(sys.argv[1]): + with open(sys.argv[1], 'r') as f: + print(json.dumps(migrate(json.loads(f.read())))) diff --git a/test/nextcloud/1.1.0/questions.yaml b/test/nextcloud/1.2.0/questions.yaml similarity index 51% rename from test/nextcloud/1.1.0/questions.yaml rename to test/nextcloud/1.2.0/questions.yaml index 545fe5647b..e8e485abce 100644 --- a/test/nextcloud/1.1.0/questions.yaml +++ b/test/nextcloud/1.2.0/questions.yaml @@ -9,6 +9,8 @@ groups: description: "Configure nextcloud container parameters" - name: "Postgresql Configuration" description: "Configure Postgresql for nextcloud" + - name: "Scaling/Upgrade Policy" + description: "Configure how pods are replaced when configuration is upgraded" portals: web_portal: @@ -94,16 +96,20 @@ questions: type: path default: "/var/www/html/data" required: true - - variable: strategy - label: "Nextcloud update strategy" - schema: - type: string - default: "Recreate" - enum: - - value: "RollingUpdate" - description: "Create new pods and then kill old ones" - - value: "Recreate" - description: "Kill existing pods before creating new ones" + + # Update strategy + - variable: updateStrategy + description: "Upgrade Policy" + label: "Update Strategy" + group: "Scaling/Upgrade Policy" + schema: + type: string + default: "Recreate" + enum: + - value: "RollingUpdate" + description: "Create new pods and then kill old ones" + - value: "Recreate" + description: "Kill existing pods before creating new ones" - variable: service description: "Nextcloud Service Configuration" @@ -122,80 +128,92 @@ questions: default: 9001 required: true - - variable: nextcloudDataHostPathEnabled - label: "Configure Host Path for Nextcloud data" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: nextcloudHostPath - label: "Specify HostPath for Nextcloud data" - schema: - type: hostpath - - - variable: nextcloudDataVolume - label: "Nextcloud Data Volume Defaults" + - variable: appVolumeMounts + label: "Nextcloud Storage" group: "Storage" schema: type: dict - $ref: - - "normalize/ixVolume" - show_if: [["nextcloudDataHostPathEnabled", "=", false]] attrs: - - variable: mountPath - label: "Nextcloud Data Mount Path" - description: "Path where the volume will be mounted inside the pod" + - variable: nextcloud-data + label: "Nextcloud Data Volume" schema: - type: path - editable: false - default: "/var/www" - - variable: datasetName - label: "Nextcloud Dataset Name" - schema: - type: string - default: "ix-nextcloud_data" - editable: false + type: dict + attrs: + - variable: datasetName + label: "Nextcloud Data Volume Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-nextcloud_data" + editable: false + - variable: mountPath + label: "Nextcloud Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: false + default: "/var/www" + - variable: hostPathEnabled + label: "Enable Host Path for Nextcloud Data Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Nextcloud Data Volume" + schema: + type: hostpath + required: true - - variable: postgresBackupVolume - label: "Postgres Backup Volume Defaults" + - variable: postgresAppVolumeMounts + label: "Postgres Storage" group: "Storage" schema: type: dict - $ref: - - "normalize/ixVolume" + hidden: true attrs: - - variable: mountPath - label: "Postgres Backup Mount Path" + - variable: postgres-data + label: "Postgres Data Volume" schema: - type: path - editable: false - default: "/postgres_backups" - - variable: datasetName - label: "Postgres Backup Dataset Name" + type: dict + attrs: + - variable: datasetName + label: "Postgres Data Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_data" + editable: false + - variable: mountPath + label: "Postgresql Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/var/lib/postgresql/data" + - variable: postgres-backup + label: "Postgres Backup Volume" schema: - type: string - default: "ix-postgres_backups" - editable: false - - - variable: postgresDataVolume - label: "Postgresql Data Volume Defaults" - group: "Storage" - schema: - type: dict - $ref: - - "normalize/ixVolume" - attrs: - - variable: mountPath - label: "Postgres Mount Path" - schema: - type: path - editable: false - default: "/var/lib/postgresql/data" - - variable: datasetName - label: "Postgres Dataset Name" - schema: - type: string - default: "ix-postgres_data" - editable: false + type: dict + attrs: + - variable: datasetName + label: "Postgres Backup Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_backups" + editable: false + - variable: mountPath + label: "Postgresql Backup Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/postgres_backups" diff --git a/test/nextcloud/1.1.0/templates/NOTES.txt b/test/nextcloud/1.2.0/templates/NOTES.txt similarity index 100% rename from test/nextcloud/1.1.0/templates/NOTES.txt rename to test/nextcloud/1.2.0/templates/NOTES.txt diff --git a/test/nextcloud/1.2.0/templates/_postgres.tpl b/test/nextcloud/1.2.0/templates/_postgres.tpl new file mode 100644 index 0000000000..0cdfc8b015 --- /dev/null +++ b/test/nextcloud/1.2.0/templates/_postgres.tpl @@ -0,0 +1,49 @@ +{{/* +Get Nextloud Postgres Database Name +*/}} +{{- define "postgres.DatabaseName" -}} +{{- print "nextcloud" -}} +{{- end -}} + + +{{- define "postgres.imageName" -}} +{{- print "postgres:13.1" -}} +{{- end -}} + + +{{/* +Retrieve postgres backup name +This will return a unique name based on revision and chart numbers specified. +*/}} +{{- define "postgres.backupName" -}} +{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}} +{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}} +{{- end }} + + +{{/* +Retrieve postgres credentials for environment variables configuration +*/}} +{{- define "postgres.envVariableConfiguration" -}} +{{ $envList := list }} +{{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user") }} +{{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password") }} +{{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) }} +{{- end -}} + + +{{/* +Retrieve postgres volume configuration +*/}} +{{- define "postgres.volumeConfiguration" -}} +{{ include "common.storage.configureAppVolumes" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts "emptyDirVolumes" .Values.emptyDirVolumes "ixVolumes" .Values.ixVolumes) | nindent 0 }} +{{- end -}} + + +{{/* +Retrieve postgres volume mounts configuration +*/}} +{{- define "postgres.volumeMountsConfiguration" -}} +{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts ) | nindent 0 }} +{{- end -}} + diff --git a/test/nextcloud/1.1.0/templates/backup-postgres-config.yaml b/test/nextcloud/1.2.0/templates/backup-postgres-config.yaml similarity index 100% rename from test/nextcloud/1.1.0/templates/backup-postgres-config.yaml rename to test/nextcloud/1.2.0/templates/backup-postgres-config.yaml diff --git a/test/nextcloud/1.2.0/templates/backup-postgres-hook.yaml b/test/nextcloud/1.2.0/templates/backup-postgres-hook.yaml new file mode 100644 index 0000000000..175b0f2617 --- /dev/null +++ b/test/nextcloud/1.2.0/templates/backup-postgres-hook.yaml @@ -0,0 +1,39 @@ +{{- if .Values.ixChartContext.isUpgrade -}} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +apiVersion: batch/v1 +kind: Job +metadata: + name: "pre-upgrade-hook2" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded + rollme: {{ randAlphaNum 5 | quote }} +spec: + template: + metadata: + name: "pre-upgrade-hook2" + spec: + restartPolicy: Never + serviceAccountName: "{{ template "common.names.serviceAccountName" . }}" + containers: + - name: {{ .Chart.Name }}-postgres-backup + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} + - name: BACKUP_NAME + value: {{ template "postgres.backupName" . }} + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + - name: backup-script-configmap + mountPath: /bin/backup_entrypoint.sh + readOnly: true + subPath: entrypoint.sh + command: + - "/bin/backup_entrypoint.sh" + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} + - name: backup-script-configmap + configMap: + defaultMode: 0700 + name: "postgres-backup-hook-config-map" +{{- end -}} diff --git a/test/nextcloud/1.2.0/templates/deployment.yaml b/test/nextcloud/1.2.0/templates/deployment.yaml new file mode 100644 index 0000000000..ba954a825c --- /dev/null +++ b/test/nextcloud/1.2.0/templates/deployment.yaml @@ -0,0 +1,54 @@ +{{ $postgres_values := (. | mustDeepCopy) }} +{{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }} +{{ include "common.deployment.common_config" . | nindent 0 }} +spec: {{ include "common.deployment.common_spec" . | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" . | nindent 4 }} + spec: + initContainers: + - name: init-postgresdb + image: {{ template "postgres.imageName" . }} + command: ['sh', '-c', "until pg_isready -h {{ template "common.names.fullname" $postgres_values }}; do echo waiting for postgres; sleep 2; done"] + imagePullPolicy: {{ .Values.image.pullPolicy }} + containers: + - name: {{ .Chart.Name }} + {{ include "common.containers.imageConfig" .Values.image | nindent 8 }} + env: {{ include "postgres.envVariableConfiguration" $postgres_values | nindent 10 }} + {{ $envList := list }} + {{ $secretName := (include "common.names.fullname" .) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_HOST" "value" (printf "%s:5432" (include "common.names.fullname" $postgres_values))) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }} + {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_DATA_DIR" "value" .Values.nextcloud.datadir) }} + {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_TRUSTED_DOMAINS" "value" .Values.nextcloud.host) }} + {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_USER" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-username") }} + {{ $envList = mustAppend $envList (dict "name" "NEXTCLOUD_ADMIN_PASSWORD" "valueFromSecret" true "secretName" $secretName "secretKey" "nextcloud-password") }} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }} + ports: + - name: http + containerPort: 80 + protocol: TCP + volumeMounts: + - name: nextcloud-data + mountPath: /var/www/ + subPath: "root" + - name: nextcloud-data + mountPath: /var/www/html + subPath: "html" + - name: nextcloud-data + mountPath: {{ .Values.nextcloud.datadir }} + subPath: "data" + - name: nextcloud-data + mountPath: /var/www/html/config + subPath: "config" + - name: nextcloud-data + mountPath: /var/www/html/custom_apps + subPath: "custom_apps" + - name: nextcloud-data + mountPath: /var/www/tmp + subPath: "tmp" + - name: nextcloud-data + mountPath: /var/www/html/themes + subPath: "themes" +{{ include "common.storage.allAppVolumes" .Values | nindent 6 }} + # Will mount configuration files as www-data (id: 33) for nextcloud + securityContext: + fsGroup: 33 diff --git a/test/nextcloud/1.1.0/templates/nuke-deployments-hook.yaml b/test/nextcloud/1.2.0/templates/nuke-deployments-hook.yaml similarity index 67% rename from test/nextcloud/1.1.0/templates/nuke-deployments-hook.yaml rename to test/nextcloud/1.2.0/templates/nuke-deployments-hook.yaml index 7307db6c1d..218ea00220 100644 --- a/test/nextcloud/1.1.0/templates/nuke-deployments-hook.yaml +++ b/test/nextcloud/1.2.0/templates/nuke-deployments-hook.yaml @@ -1,4 +1,6 @@ {{- if .Values.ixChartContext.isUpgrade -}} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} apiVersion: batch/v1 kind: Job metadata: @@ -14,9 +16,9 @@ spec: name: "pre-upgrade-hook1" spec: restartPolicy: Never - serviceAccountName: "{{ template "nextcloud.serviceAccountName" . }}" + serviceAccountName: "{{ template "common.names.serviceAccountName" . }}" containers: - name: kubectl image: "bitnami/kubectl:1.19" - command: ["kubectl", "delete" , "deployment", "{{ template "nextcloud.fullname" . }}", "{{ template "nextcloud.fullname" . }}-postgres"] + command: ["kubectl", "delete" , "deployment", "{{ template "common.names.fullname" . }}", "{{ template "common.names.fullname" $values }}"] {{- end -}} diff --git a/test/nextcloud/1.2.0/templates/postgres-deployment.yaml b/test/nextcloud/1.2.0/templates/postgres-deployment.yaml new file mode 100644 index 0000000000..c325ee8ced --- /dev/null +++ b/test/nextcloud/1.2.0/templates/postgres-deployment.yaml @@ -0,0 +1,17 @@ +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +{{ include "common.deployment.common_config" $values | nindent 0 }} +spec: {{ include "common.deployment.common_spec" $values | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" $values | nindent 4 }} + spec: + containers: + - name: {{ .Chart.Name }}-postgres + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + ports: + - name: postgres-tcp + containerPort: 5432 + protocol: TCP + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} diff --git a/test/nextcloud/1.1.0/templates/postgres-secret.yaml b/test/nextcloud/1.2.0/templates/postgres-secret.yaml similarity index 100% rename from test/nextcloud/1.1.0/templates/postgres-secret.yaml rename to test/nextcloud/1.2.0/templates/postgres-secret.yaml diff --git a/test/nextcloud/1.2.0/templates/postgres-service.yaml b/test/nextcloud/1.2.0/templates/postgres-service.yaml new file mode 100644 index 0000000000..c6603fd62b --- /dev/null +++ b/test/nextcloud/1.2.0/templates/postgres-service.yaml @@ -0,0 +1,6 @@ +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "postgres-tcp" "port" 5432 "targetPort" 5432) }} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +{{ $_1 := set $values "commonService" (dict "type" "ClusterIP" "ports" $ports ) }} +{{ include "common.classes.service" $values }} diff --git a/test/nextcloud/1.1.0/templates/secrets.yaml b/test/nextcloud/1.2.0/templates/secrets.yaml similarity index 53% rename from test/nextcloud/1.1.0/templates/secrets.yaml rename to test/nextcloud/1.2.0/templates/secrets.yaml index 687560016d..eb992940b3 100644 --- a/test/nextcloud/1.1.0/templates/secrets.yaml +++ b/test/nextcloud/1.2.0/templates/secrets.yaml @@ -1,12 +1,8 @@ apiVersion: v1 kind: Secret metadata: - name: {{ template "nextcloud.fullname" . }} - labels: - app.kubernetes.io/name: {{ include "nextcloud.name" . }} - helm.sh/chart: {{ include "nextcloud.chart" . }} - app.kubernetes.io/instance: {{ .Release.Name }} - app.kubernetes.io/managed-by: {{ .Release.Service }} + name: {{ template "common.names.fullname" . }} + labels: {{ include "common.labels" . | nindent 4 }} type: Opaque data: nextcloud-username: {{ .Values.nextcloud.username | b64enc | quote }} diff --git a/test/nextcloud/1.2.0/templates/service.yaml b/test/nextcloud/1.2.0/templates/service.yaml new file mode 100644 index 0000000000..ead1523381 --- /dev/null +++ b/test/nextcloud/1.2.0/templates/service.yaml @@ -0,0 +1,6 @@ +{{ $svc := .Values.service }} +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "http" "port" 80 "nodePort" $svc.nodePort) }} +{{ $params := . }} +{{ $_ := set $params "commonService" (dict "type" "NodePort" "ports" $ports ) }} +{{ include "common.classes.service" $params }} diff --git a/test/nextcloud/1.1.0/templates/serviceaccount.yaml b/test/nextcloud/1.2.0/templates/serviceaccount.yaml similarity index 75% rename from test/nextcloud/1.1.0/templates/serviceaccount.yaml rename to test/nextcloud/1.2.0/templates/serviceaccount.yaml index c25bd439fd..48213465b0 100644 --- a/test/nextcloud/1.1.0/templates/serviceaccount.yaml +++ b/test/nextcloud/1.2.0/templates/serviceaccount.yaml @@ -1,8 +1,4 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: "{{ template "nextcloud.serviceAccountName" . }}" - namespace: {{ .Release.Namespace }} +{{ include "common.serviceaccount" . | nindent 0 }} --- @@ -12,7 +8,7 @@ metadata: name: "{{ .Release.Name }}-service-account-role-binding" subjects: - kind: ServiceAccount - name: "{{ template "nextcloud.serviceAccountName" . }}" + name: "{{ template "common.names.serviceAccountName" . }}" namespace: {{ .Release.Namespace }} roleRef: kind: Role diff --git a/test/nextcloud/1.2.0/test_values.yaml b/test/nextcloud/1.2.0/test_values.yaml new file mode 100644 index 0000000000..340b234bce --- /dev/null +++ b/test/nextcloud/1.2.0/test_values.yaml @@ -0,0 +1,43 @@ +## Official nextcloud image version +## ref: https://hub.docker.com/r/library/nextcloud/tags/ +## +image: + repository: nextcloud + tag: 19.0.3-apache + pullPolicy: IfNotPresent + +nextcloud: + host: nextcloud.kube.home + username: admin + password: changeme + datadir: /var/www/html/data + +updateStrategy: "Recreate" + +postgresql: + backupVolume: + mountPath: "/postgres_backups" + datasetName: "ix-postgres_backups" + dataVolume: + mountPath: "/var/lib/postgresql/data" + datasetName: "ix-postgres_data" + +service: + nodePort: 31000 + +emptyDirVolumes: true +ixChartContext: {} +environmentVariables: [] + +appVolumeMounts: + nextcloud-data: + emptyDir: true + mountPath: "/var/www" + +postgresAppVolumeMounts: + postgres-data: + emptyDir: true + mountPath: "/var/lib/postgresql/data" + postgres-backup: + emptyDir: true + mountPath: "/postgres_backups" diff --git a/test/nextcloud/1.2.0/values.yaml b/test/nextcloud/1.2.0/values.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/plex/1.0.1/questions.yaml b/test/plex/1.0.1/questions.yaml deleted file mode 100644 index 2107548760..0000000000 --- a/test/plex/1.0.1/questions.yaml +++ /dev/null @@ -1,262 +0,0 @@ -groups: - - name: "Container Images" - description: "Image to be used for container" - - name: "Container Entrypoint" - description: "Configuration of the executable that will be run when the container is started" - - name: "Container Environment Variables" - description: "Set the environment that will be visible to the container" - - name: "Networking" - description: "Configure networking for container" - - name: "Storage" - description: "Persist and share data that is separate from the lifecycle of the container" - - name: "Plex Configuration" - description: "Configure plex deployment" - - name: "Workload Details" - description: "Configure how workload should be deployed" - - name: "Scaling/Upgrade Policy" - description: "Configure how pods are replaced when configuration is upgraded" - - name: "Restart Policy" - description: "Configure when pod should be restarted in case of failure" - - name: "Resource Reservation" - description: "Specify resources to be allocated to workload" - -portals: - web_portal: - protocols: - - "http" - host: - - "$node_ip" - ports: - - "$variable-plexServiceTCP.port" - path: "/web" - -questions: - # Image related - - variable: image - description: "Docker Image Details" - label: "Docker Image" - group: "Container Images" - schema: - type: dict - required: true - attrs: - - variable: repository - description: "Docker image repository" - label: "Image repository" - schema: - type: string - required: true - default: "plexinc/pms-docker" - - variable: tag - description: "Tag to use for specified image" - label: "Image Tag" - schema: - type: string - default: "1.20.2.3402-0fec14d92" - - variable: pullPolicy - description: "Docker Image Pull Policy" - label: "Image Pull Policy" - schema: - type: string - default: "IfNotPresent" - enum: - - value: "IfNotPresent" - description: "Only pull image if not present on host" - - value: "Always" - description: "Always pull image even if present on host" - - value: "Never" - description: "Never pull image even if it's not present on host" - - - variable: claimToken - label: "Plex Claim Token" - group: "Plex Configuration" - description: "The claim token for the server to obtain a real server token. If not provided, server is will not be automatically logged in. If server is already logged in, this parameter is ignored. You can obtain a claim token to login your server to your plex account by visiting https://www.plex.tv/claim." - schema: - type: string - default: "" - - - variable: hostNetwork - label: "Configure Host Network" - group: "Networking" - schema: - type: boolean - default: false - - - variable: environmentVariables - label: "Environment Variables for Plex" - group: "Plex Configuration" - schema: - type: list - default: [] - items: - - variable: environmentVariable - label: "Environment Variable" - schema: - type: dict - attrs: - - variable: name - label: "Name" - schema: - type: string - - variable: value - label: "Value" - schema: - type: string - - - variable: timezone - label: "Plex container timezone" - group: "Plex Configuration" - schema: - type: string - default: "Etc/UTC" - $ref: - - "definitions/timezone" - - # Update strategy - - variable: strategyType - description: "Upgrade Policy" - label: "Update Strategy" - group: "Scaling/Upgrade Policy" - schema: - type: string - default: "Recreate" - enum: - - value: "RollingUpdate" - description: "Create new pods and then kill old ones" - - value: "Recreate" - description: "Kill existing pods before creating new ones" - - # Port configuration - - variable: plexServiceTCP - label: "Configure Plex TCP Service" - group: "Networking" - schema: - type: dict - attrs: - - variable: port - label: "Port to expose for Plex UI" - schema: - type: int - min: 9000 - max: 65535 - default: 32400 - - - variable: transcodeHostPathEnabled - label: "Configure Host Path for Transcode" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: transcodeHostPath - label: "Specify HostPath for Transcode" - schema: - type: hostpath - required: true - - - variable: transcodeVolume - label: "Transcode Volume Defaults" - group: "Storage" - schema: - type: dict - show_if: [["transcodeHostPathEnabled", "=", false]] - $ref: - - "normalize/ixVolume" - attrs: - - variable: mountPath - label: "Mount Path" - description: "Path where the volume will be mounted inside the pod" - schema: - type: path - editable: false - default: "/transcode" - - variable: datasetName - label: "Transcode Dataset Name" - schema: - type: string - default: "ix-plex_transcode" - editable: false - - - variable: dataHostPathEnabled - label: "Configure Host Path for Data" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: dataHostPath - label: "Specify HostPath for Data" - schema: - type: hostpath - required: true - - - variable: dataVolume - label: "Data Volume Defaults" - group: "Storage" - schema: - type: dict - show_if: [["dataHostPathEnabled", "=", false]] - $ref: - - "normalize/ixVolume" - attrs: - - variable: mountPath - label: "Mount Path" - description: "Path where the volume will be mounted inside the pod" - schema: - type: path - editable: false - default: "/data" - - variable: datasetName - label: "Data Dataset Name" - schema: - type: string - default: "ix-plex_data" - editable: false - - - variable: configHostPathEnabled - label: "Configure Host Path for Config" - group: "Storage" - schema: - type: boolean - default: false - show_subquestions_if: true - subquestions: - - variable: configHostPath - label: "Specify HostPath for Config" - schema: - type: hostpath - required: true - - - variable: configVolume - label: "Configuration Volume Defaults" - group: "Storage" - schema: - type: dict - show_if: [["configHostPathEnabled", "=", false]] - $ref: - - "normalize/ixVolume" - attrs: - - variable: mountPath - label: "Mount Path" - description: "Path where the volume will be mounted inside the pod" - schema: - type: path - editable: false - default: "/config" - - variable: datasetName - label: "Configuration Dataset Name" - schema: - type: string - default: "ix-plex_config" - editable: false - - # Specify GPU configuration - - variable: gpuConfiguration - label: "GPU Configuration" - group: "Resource Reservation" - schema: - type: dict - $ref: - - "definitions/gpuConfiguration" diff --git a/test/plex/1.0.1/templates/_helpers.tpl b/test/plex/1.0.1/templates/_helpers.tpl deleted file mode 100644 index 18ddff7f7e..0000000000 --- a/test/plex/1.0.1/templates/_helpers.tpl +++ /dev/null @@ -1,81 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "plex.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 "plex.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 "plex.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "plex.labels" -}} -helm.sh/chart: {{ include "plex.chart" . }} -{{ include "plex.selectorLabels" . }} -{{- if .Chart.AppVersion }} -app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} -{{- end }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "plex.selectorLabels" -}} -app.kubernetes.io/name: {{ include "plex.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Create the name of the service account to use -*/}} -{{- define "plex.serviceAccountName" -}} -{{- if .Values.serviceAccount.create -}} - {{ default (include "plex.fullname" .) .Values.serviceAccount.name }} -{{- else -}} - {{ default "default" .Values.serviceAccount.name }} -{{- end -}} -{{- end -}} - -{{/* -abstract: | - Joins a list of values into a comma separated string -values: | - test: - - foo - - bar -usage: | - {{ include "joinListWithComma" .Values.test }} -return: | - foo,bar -*/}} - -{{- define "joinListWithComma" -}} -{{- $local := dict "first" true -}} -{{- range $k, $v := . -}}{{- if not $local.first -}},{{- end -}}{{- $v -}}{{- $_ := set $local "first" false -}}{{- end -}} -{{- end -}} \ No newline at end of file diff --git a/test/plex/1.0.1/templates/_storage.tpl b/test/plex/1.0.1/templates/_storage.tpl deleted file mode 100644 index ef34fcb041..0000000000 --- a/test/plex/1.0.1/templates/_storage.tpl +++ /dev/null @@ -1,50 +0,0 @@ -{{/* -Retrieve host path from ix volumes based on dataset name -*/}} -{{- define "retrieveHostPathFromiXVolume" -}} -{{- range $index, $hostPathConfiguration := $.ixVolumes }} -{{- $dsName := base $hostPathConfiguration.hostPath -}} -{{- if eq $.datasetName $dsName -}} -{{- $hostPathConfiguration.hostPath -}} -{{- end -}} -{{- end }} -{{- end -}} - -{{/* -Retrieve host path for transcode -Let's please remove the redundancy -*/}} -{{- define "configuredHostPathTranscode" -}} -{{- if .Values.transcodeHostPathEnabled -}} -{{- .Values.transcodeHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.transcodeVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve host path for data -Let's please remove the redundancy -*/}} -{{- define "configuredHostPathData" -}} -{{- if .Values.dataHostPathEnabled -}} -{{- .Values.dataHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.dataVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} - -{{/* -Retrieve host path for transcode -Let's please remove the redundancy -*/}} -{{- define "configuredHostPathConfig" -}} -{{- if .Values.configHostPathEnabled -}} -{{- .Values.configHostPath -}} -{{- else -}} -{{- $volDict := dict "datasetName" $.Values.configVolume.datasetName "ixVolumes" $.Values.ixVolumes -}} -{{- include "retrieveHostPathFromiXVolume" $volDict -}} -{{- end -}} -{{- end -}} diff --git a/test/plex/1.0.1/templates/deployment.yaml b/test/plex/1.0.1/templates/deployment.yaml deleted file mode 100644 index 1344cf8f3d..0000000000 --- a/test/plex/1.0.1/templates/deployment.yaml +++ /dev/null @@ -1,139 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "plex.fullname" . }} - labels: - {{- include "plex.labels" . | nindent 4 }} -spec: - replicas: 1 - revisionHistoryLimit: 3 - strategy: - type: {{ .Values.strategyType }} - selector: - matchLabels: - {{- include "plex.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "plex.selectorLabels" . | nindent 8 }} - annotations: - rollme: {{ randAlphaNum 5 | quote }} - spec: - {{- if .Values.hostNetwork }} - hostNetwork: {{ .Values.hostNetwork }} - dnsPolicy: ClusterFirstWithHostNet - {{- end }} - containers: - - name: {{ .Chart.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - name: pms - protocol: TCP - containerPort: 32400 - {{- if .Values.hostNetwork }} - hostPort: {{ .Values.plexServiceTCP.port }} - {{- end }} - - name: plex-dlna - protocol: TCP - containerPort: 32469 - - name: plex-dlna-udp - protocol: UDP - containerPort: 1900 - - name: plex-gdm1 - protocol: UDP - containerPort: 32410 - - name: plex-gdm2 - protocol: UDP - containerPort: 32412 - - name: plex-gdm3 - protocol: UDP - containerPort: 32413 - - name: plex-gdm4 - protocol: UDP - containerPort: 32414 - env: - - name: TZ - value: "{{ .Values.timezone }}" - # TODO: move this to a secret? - - name: PLEX_CLAIM - value: "{{ .Values.claimToken }}" - # plex env vars - - name: PMS_INTERNAL_ADDRESS - value: http://{{ template "plex.fullname" . }}:32400 - - name: PMS_IMAGE - value: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - - name: KUBE_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace -# Extra ENV Values supplied by user -{{- range $envVariable := .Values.environmentVariables }} - {{- if and $envVariable.name $envVariable.value }} - - name: {{ $envVariable.name }} - value: {{ $envVariable.value | quote }} - {{- else }} - {{- fail "Please specify name/value for environment variable" }} - {{- end }} -{{- end}} - readinessProbe: - httpGet: - path: /identity - port: 32400 - failureThreshold: 5 - periodSeconds: 15 - livenessProbe: - httpGet: - path: /identity - port: 32400 - failureThreshold: 5 - periodSeconds: 15 - startupProbe: - httpGet: - path: /identity - port: 32400 - initialDelaySeconds: 5 - failureThreshold: 40 - periodSeconds: 15 - volumeMounts: - - name: data - mountPath: /data - - name: config - mountPath: /config - - name: transcode - mountPath: /transcode - - name: shared - mountPath: /shared - - name: shared-logs - mountPath: "/config/Library/Application Support/Plex Media Server/Logs" - {{- if .Values.gpuConfiguration }} - resources: - limits: - {{- toYaml .Values.gpuConfiguration | nindent 14 }} - {{- end }} - volumes: - - name: data - {{- if .Values.emptyDirVolumes }} - emptyDir: {} - {{- else }} - hostPath: - path: {{ template "configuredHostPathData" . }} - {{- end }} - - name: config - {{- if .Values.emptyDirVolumes }} - emptyDir: {} - {{- else }} - hostPath: - path: {{ template "configuredHostPathConfig" . }} - {{- end }} - - name: transcode - {{- if .Values.emptyDirVolumes }} - emptyDir: {} - {{- else }} - hostPath: - path: {{ template "configuredHostPathTranscode" . }} - {{- end }} - - name: shared - emptyDir: {} - - name: shared-logs - emptyDir: {} diff --git a/test/plex/1.0.1/templates/service-tcp.yaml b/test/plex/1.0.1/templates/service-tcp.yaml deleted file mode 100644 index 48a69eef18..0000000000 --- a/test/plex/1.0.1/templates/service-tcp.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - {{- if .Values.hostNetwork }} - name: {{ include "plex.fullname" . }}-tcp-cluster-ip - {{- else }} - name: {{ include "plex.fullname" . }}-tcp - {{- end }} - labels: - {{- include "plex.labels" . | nindent 4 }} -spec: - {{- if .Values.hostNetwork }} - type: ClusterIP - {{- else }} - type: NodePort - {{- end }} - ports: - - name: pms - port: {{ .Values.plexServiceTCP.port }} - protocol: TCP - targetPort: pms - {{- if eq .Values.hostNetwork false }} - nodePort: {{.Values.plexServiceTCP.port}} - {{- end }} - - name: http - port: 80 - targetPort: pms - - name: https - port: 443 - targetPort: pms - - name: plex-dlna - port: 1900 - targetPort: plex-dlna - selector: - {{- include "plex.selectorLabels" . | nindent 4 }} diff --git a/test/plex/1.0.1/templates/service-udp.yaml b/test/plex/1.0.1/templates/service-udp.yaml deleted file mode 100644 index e13ae5658a..0000000000 --- a/test/plex/1.0.1/templates/service-udp.yaml +++ /dev/null @@ -1,31 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "plex.fullname" . }}-udp - labels: - {{- include "plex.labels" . | nindent 4 }} -spec: - type: ClusterIP - ports: - - name: plex-dlna-udp - port: 1900 - protocol: UDP - targetPort: plex-dlna-udp - - name: plex-gdm1 - port: 32410 - protocol: UDP - targetPort: plex-gdm1 - - name: plex-gdm2 - port: 32412 - protocol: UDP - targetPort: plex-gdm2 - - name: plex-gdm3 - port: 32413 - protocol: UDP - targetPort: plex-gdm3 - - name: plex-gdm4 - port: 32414 - protocol: UDP - targetPort: plex-gdm4 - selector: - {{- include "plex.selectorLabels" . | nindent 4 }} diff --git a/test/plex/1.0.1/.helmignore b/test/plex/1.1.0/.helmignore similarity index 100% rename from test/plex/1.0.1/.helmignore rename to test/plex/1.1.0/.helmignore diff --git a/test/plex/1.1.0/Chart.lock b/test/plex/1.1.0/Chart.lock new file mode 100644 index 0000000000..1bb2d56e4b --- /dev/null +++ b/test/plex/1.1.0/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 +digest: sha256:6ab46f958de11ae6a24d8f7e18417aa9852a8d968d5b0cc94ffa4700449931d6 +generated: "2021-02-04T01:15:55.470042+05:00" diff --git a/test/plex/1.0.1/Chart.yaml b/test/plex/1.1.0/Chart.yaml similarity index 73% rename from test/plex/1.0.1/Chart.yaml rename to test/plex/1.1.0/Chart.yaml index 961dda9c20..2d82d67bc3 100644 --- a/test/plex/1.0.1/Chart.yaml +++ b/test/plex/1.1.0/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: 1.20.2.3402 description: Plex Media Server name: plex -version: 1.0.1 +version: 1.1.0 keywords: - plex home: https://plex.tv/ @@ -11,3 +11,8 @@ sources: - https://hub.docker.com/r/plexinc/pms-docker/ - https://github.com/k8s-at-home/charts/tree/master/charts/plex upstream_version: 2.1.0 +dependencies: + - name: common + repository: file://../../../library/common/2101.0.0 + version: 2101.0.0 + diff --git a/test/plex/1.0.1/README.md b/test/plex/1.1.0/README.md similarity index 100% rename from test/plex/1.0.1/README.md rename to test/plex/1.1.0/README.md diff --git a/test/plex/1.0.1/app-readme.md b/test/plex/1.1.0/app-readme.md similarity index 100% rename from test/plex/1.0.1/app-readme.md rename to test/plex/1.1.0/app-readme.md diff --git a/test/plex/1.1.0/charts/common-2101.0.0.tgz b/test/plex/1.1.0/charts/common-2101.0.0.tgz new file mode 100644 index 0000000000..3a22457ea6 Binary files /dev/null and b/test/plex/1.1.0/charts/common-2101.0.0.tgz differ diff --git a/test/plex/1.0.1/values.yaml b/test/plex/1.1.0/default_values.yaml similarity index 86% rename from test/plex/1.0.1/values.yaml rename to test/plex/1.1.0/default_values.yaml index f1a1754a54..12b8b12cc6 100644 --- a/test/plex/1.0.1/values.yaml +++ b/test/plex/1.1.0/default_values.yaml @@ -50,17 +50,13 @@ timezone: "Etc/UTC" # TMPDIR: /transcode # upgrade strategy type (e.g. Recreate or RollingUpdate) -strategyType: Recreate +updateStrategy: Recreate plexServiceTCP: port: 32400 hostNetwork: false -transcodeHostPathEnabled: false -dataHostPathEnabled: false -configHostPathEnabled: false - proxy: # This allows to set a proxy environment variable, which PMS uses to fetch the token and assets like movie cover enabled: false @@ -69,3 +65,20 @@ proxy: # noproxy: "localhost,127.0.0.1,10.96.0.0/12,10.244.0.0/12" gpuConfiguration: {} + +appVolumeMounts: + transcode: + emptyDir: true + mountPath: "/transcode" + data: + emptyDir: true + mountPath: "/data" + config: + emptyDir: true + mountPath: "/config" + shared: + emptyDir: true + mountPath: "shared" + shared-logs: + emptyDir: true + mountPath: "/config/Library/Application Support/Plex Media Server/Logs" diff --git a/test/plex/1.1.0/migrations/migrate b/test/plex/1.1.0/migrations/migrate new file mode 100755 index 0000000000..a93c1d9f47 --- /dev/null +++ b/test/plex/1.1.0/migrations/migrate @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +import json +import os +import sys + + +def migrate(values): + values.update({ + 'appVolumeMounts': { + 'transcode': { + 'hostPathEnabled': values['transcodeHostPathEnabled'], + **({'hostPath': values['transcodeHostPath']} if values.get('transcodeHostPath') else {}) + }, + 'config': { + 'hostPathEnabled': values['configHostPathEnabled'], + **({'hostPath': values['configHostPath']} if values.get('configHostPath') else {}) + }, + 'data': { + 'hostPathEnabled': values['dataHostPathEnabled'], + **({'hostPath': values['dataHostPath']} if values.get('dataHostPath') else {}) + }, + }, + 'updateStrategy': values.get('strategyType', 'Recreate'), + }) + return values + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + if os.path.exists(sys.argv[1]): + with open(sys.argv[1], 'r') as f: + print(json.dumps(migrate(json.loads(f.read())))) diff --git a/test/plex/1.1.0/questions.yaml b/test/plex/1.1.0/questions.yaml new file mode 100644 index 0000000000..37649228de --- /dev/null +++ b/test/plex/1.1.0/questions.yaml @@ -0,0 +1,301 @@ +groups: + - name: "Container Images" + description: "Image to be used for container" + - name: "Container Entrypoint" + description: "Configuration of the executable that will be run when the container is started" + - name: "Container Environment Variables" + description: "Set the environment that will be visible to the container" + - name: "Networking" + description: "Configure networking for container" + - name: "Storage" + description: "Persist and share data that is separate from the lifecycle of the container" + - name: "Plex Configuration" + description: "Configure plex deployment" + - name: "Workload Details" + description: "Configure how workload should be deployed" + - name: "Scaling/Upgrade Policy" + description: "Configure how pods are replaced when configuration is upgraded" + - name: "Restart Policy" + description: "Configure when pod should be restarted in case of failure" + - name: "Resource Reservation" + description: "Specify resources to be allocated to workload" + +portals: + web_portal: + protocols: + - "http" + host: + - "$node_ip" + ports: + - "$variable-plexServiceTCP.port" + path: "/web" + +questions: + # Image related + - variable: image + description: "Docker Image Details" + label: "Docker Image" + group: "Container Images" + schema: + type: dict + required: true + attrs: + - variable: repository + description: "Docker image repository" + label: "Image repository" + schema: + type: string + required: true + default: "plexinc/pms-docker" + - variable: tag + description: "Tag to use for specified image" + label: "Image Tag" + schema: + type: string + default: "1.20.2.3402-0fec14d92" + - variable: pullPolicy + description: "Docker Image Pull Policy" + label: "Image Pull Policy" + schema: + type: string + default: "IfNotPresent" + enum: + - value: "IfNotPresent" + description: "Only pull image if not present on host" + - value: "Always" + description: "Always pull image even if present on host" + - value: "Never" + description: "Never pull image even if it's not present on host" + + - variable: claimToken + label: "Plex Claim Token" + group: "Plex Configuration" + description: "The claim token for the server to obtain a real server token. If not provided, server is will not be automatically logged in. If server is already logged in, this parameter is ignored. You can obtain a claim token to login your server to your plex account by visiting https://www.plex.tv/claim." + schema: + type: string + default: "" + + - variable: hostNetwork + label: "Configure Host Network" + group: "Networking" + schema: + type: boolean + default: false + + - variable: environmentVariables + label: "Environment Variables for Plex" + group: "Plex Configuration" + schema: + type: list + default: [] + items: + - variable: environmentVariable + label: "Environment Variable" + schema: + type: dict + attrs: + - variable: name + label: "Name" + schema: + type: string + - variable: value + label: "Value" + schema: + type: string + + - variable: timezone + label: "Plex container timezone" + group: "Plex Configuration" + schema: + type: string + default: "Etc/UTC" + $ref: + - "definitions/timezone" + + # Update strategy + - variable: updateStrategy + description: "Upgrade Policy" + label: "Update Strategy" + group: "Scaling/Upgrade Policy" + schema: + type: string + default: "Recreate" + enum: + - value: "RollingUpdate" + description: "Create new pods and then kill old ones" + - value: "Recreate" + description: "Kill existing pods before creating new ones" + + # Port configuration + - variable: plexServiceTCP + label: "Configure Plex TCP Service" + group: "Networking" + schema: + type: dict + attrs: + - variable: port + label: "Port to expose for Plex UI" + schema: + type: int + min: 9000 + max: 65535 + default: 32400 + + # Specify GPU configuration + - variable: gpuConfiguration + label: "GPU Configuration" + group: "Resource Reservation" + schema: + type: dict + $ref: + - "definitions/gpuConfiguration" + + - variable: appVolumeMounts + label: "Plex Storage" + group: "Storage" + schema: + type: dict + attrs: + - variable: transcode + label: "Transcode Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Plex Transcode Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-plex_transcode" + hidden: true + editable: false + - variable: mountPath + label: "Plex Transcode Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: false + default: "/transcode" + - variable: hostPathEnabled + label: "Enable Host Path for Plex Transcode Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Plex Transcode Volume" + schema: + type: hostpath + required: true + - variable: data + label: "Data Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Plex Data Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-plex_data" + editable: false + hidden: true + - variable: mountPath + label: "Plex Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: false + default: "/data" + - variable: hostPathEnabled + label: "Enable Host Path for Plex Data Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Plex Data Volume" + schema: + type: hostpath + required: true + - variable: config + label: "Config Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Plex Config Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-plex_config" + editable: false + hidden: true + - variable: mountPath + label: "Plex Config Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + hidden: true + default: "/config" + - variable: hostPathEnabled + label: "Enable Host Path for Plex Config Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Plex Config Volume" + schema: + type: hostpath + required: true + - variable: shared + label: "Shared Volume" + schema: + type: dict + hidden: true + attrs: + - variable: emptyDir + label: "Temporary Volume" + schema: + type: boolean + default: true + editable: false + - variable: mountPath + label: "Plex Shared Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/shared" + - variable: shared-logs + label: "Shared Logs Volume" + schema: + type: dict + hidden: true + attrs: + - variable: emptyDir + label: "Temporary Volume" + schema: + type: boolean + default: true + editable: false + - variable: mountPath + label: "Plex Shared Logs Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/config/Library/Application Support/Plex Media Server/Logs" diff --git a/test/plex/1.0.1/templates/NOTES.txt b/test/plex/1.1.0/templates/NOTES.txt similarity index 100% rename from test/plex/1.0.1/templates/NOTES.txt rename to test/plex/1.1.0/templates/NOTES.txt diff --git a/test/plex/1.1.0/templates/deployment.yaml b/test/plex/1.1.0/templates/deployment.yaml new file mode 100644 index 0000000000..6f3283aa64 --- /dev/null +++ b/test/plex/1.1.0/templates/deployment.yaml @@ -0,0 +1,69 @@ +{{ include "common.deployment.common_config" . | nindent 0 }} +spec: {{ include "common.deployment.common_spec" . | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" . | nindent 4 }} + spec: + {{- if .Values.hostNetwork }} + hostNetwork: {{ .Values.hostNetwork }} + dnsPolicy: ClusterFirstWithHostNet + {{- end }} + containers: + - name: {{ .Chart.Name }} + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + {{ include "common.storage.allContainerVolumeMounts" .Values | nindent 10 }} + {{ include "common.containers.gpuConfiguration" .Values | nindent 10 }} + ports: + - name: pms + protocol: TCP + containerPort: 32400 + {{- if .Values.hostNetwork }} + hostPort: {{ .Values.plexServiceTCP.port }} + {{- end }} + - name: plex-dlna + protocol: TCP + containerPort: 32469 + - name: plex-dlna-udp + protocol: UDP + containerPort: 1900 + - name: plex-gdm1 + protocol: UDP + containerPort: 32410 + - name: plex-gdm2 + protocol: UDP + containerPort: 32412 + - name: plex-gdm3 + protocol: UDP + containerPort: 32413 + - name: plex-gdm4 + protocol: UDP + containerPort: 32414 + env: + - name: KUBE_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + {{ $envList := (default list .Values.environmentVariables) }} + {{ $envList = mustAppend $envList (dict "name" "TZ" "value" .Values.timezone) }} + {{ $envList = mustAppend $envList (dict "name" "PLEX_CLAIM" "value" .Values.claimToken) }} + {{ $envList = mustAppend $envList (dict "name" "PMS_INTERNAL_ADDRESS" "value" (printf "http://%s:32400" (include "common.names.fullname" .))) }} + {{ $envList = mustAppend $envList (dict "name" "PMS_IMAGE" "value" (printf "%s:%s" .Values.image.repository .Values.image.tag))}} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }} + readinessProbe: + httpGet: + path: /identity + port: 32400 + failureThreshold: 5 + periodSeconds: 15 + livenessProbe: + httpGet: + path: /identity + port: 32400 + failureThreshold: 5 + periodSeconds: 15 + startupProbe: + httpGet: + path: /identity + port: 32400 + initialDelaySeconds: 5 + failureThreshold: 40 + periodSeconds: 15 +{{ include "common.storage.allAppVolumes" .Values | nindent 6 }} diff --git a/test/plex/1.1.0/templates/service-tcp.yaml b/test/plex/1.1.0/templates/service-tcp.yaml new file mode 100644 index 0000000000..4fec88260b --- /dev/null +++ b/test/plex/1.1.0/templates/service-tcp.yaml @@ -0,0 +1,16 @@ +{{ $svc := .Values.plexServiceTCP }} +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "pms" "port" $svc.port "nodePort" $svc.port "targetPort" "pms") }} +{{ $ports = mustAppend $ports (dict "name" "http" "port" 80 "targetPort" "pms") }} +{{ $ports = mustAppend $ports (dict "name" "https" "port" 443 "targetPort" "pms") }} +{{ $ports = mustAppend $ports (dict "name" "plex-dlna" "port" 1900 "targetPort" "plex-dlna") }} +{{ $params := . }} +{{ $_ := set $params "commonService" (dict "ports" $ports ) }} +{{ if .Values.hostNetwork }} +{{ $_ := set $params.commonService "nameSuffix" "tcp-cluster-ip" }} +{{ $_1 := set $params.commonService "type" "ClusterIP" }} +{{ else }} +{{ $_ := set $params.commonService "nameSuffix" "tcp" }} +{{ $_1 := set $params.commonService "type" "NodePort" }} +{{ end }} +{{ include "common.classes.service" $params }} diff --git a/test/plex/1.1.0/templates/service-udp.yaml b/test/plex/1.1.0/templates/service-udp.yaml new file mode 100644 index 0000000000..5a84addc99 --- /dev/null +++ b/test/plex/1.1.0/templates/service-udp.yaml @@ -0,0 +1,9 @@ +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "plex-dlna-udp" "port" 1900 "protocol" "UDP" "targetPort" "plex-dlna-udp") }} +{{ $ports = mustAppend $ports (dict "name" "plex-gdm1" "port" 32410 "protocol" "UDP" "targetPort" "plex-gdm1") }} +{{ $ports = mustAppend $ports (dict "name" "plex-gdm2" "port" 32412 "protocol" "UDP" "targetPort" "plex-gdm2") }} +{{ $ports = mustAppend $ports (dict "name" "plex-gdm3" "port" 32413 "protocol" "UDP" "targetPort" "plex-gdm3") }} +{{ $ports = mustAppend $ports (dict "name" "plex-gdm4" "port" 32414 "protocol" "UDP" "targetPort" "plex-gdm4") }} +{{ $params := . }} +{{ $_ := set $params "commonService" (dict "type" "ClusterIP" "ports" $ports "nameSuffix" "udp" ) }} +{{ include "common.classes.service" $params }} diff --git a/test/plex/1.0.1/test_values.yaml b/test/plex/1.1.0/test_values.yaml similarity index 83% rename from test/plex/1.0.1/test_values.yaml rename to test/plex/1.1.0/test_values.yaml index 53802c93f1..cfb8ac7e36 100644 --- a/test/plex/1.0.1/test_values.yaml +++ b/test/plex/1.1.0/test_values.yaml @@ -50,16 +50,31 @@ timezone: "Etc/UTC" # TMPDIR: /transcode # upgrade strategy type (e.g. Recreate or RollingUpdate) -strategyType: Recreate +updateStrategy: "Recreate" plexServiceTCP: port: 32400 hostNetwork: false -transcodeHostPathEnabled: false -dataHostPathEnabled: false -configHostPathEnabled: false +environmentVariables: [] gpuConfiguration: {} emptyDirVolumes: true + +appVolumeMounts: + transcode: + emptyDir: true + mountPath: "/transcode" + data: + emptyDir: true + mountPath: "/data" + config: + emptyDir: true + mountPath: "/config" + shared: + emptyDir: true + mountPath: "shared" + shared-logs: + emptyDir: true + mountPath: "/config/Library/Application Support/Plex Media Server/Logs" diff --git a/test/plex/1.1.0/values.yaml b/test/plex/1.1.0/values.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/update_dependencies b/update_dependencies new file mode 100755 index 0000000000..ac74b60947 --- /dev/null +++ b/update_dependencies @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +import argparse +import errno +import os +import subprocess + +from collections import defaultdict + +ITEMS = defaultdict(lambda: {'success': [], 'error': []}) + + +class ValidationException(Exception): + def __init__(self, error_msg, error_no=errno.EFAULT): + self.errmsg = error_msg + self.errno = error_no + + def get_error_name(self): + return errno.errorcode.get(self.errno) or 'EUNKNOWN' + + def __str__(self): + return f'[{self.get_error_name()}] {self.errmsg}' + + +class NotFoundException(ValidationException): + def __init__(self, error): + super().__init__(error, errno.ENOENT) + + +class TrainNotFoundException(NotFoundException): + def __init__(self): + super(TrainNotFoundException, self).__init__('Failed to find train') + + +class CatalogItemNotFoundException(NotFoundException): + def __init__(self, path): + super(CatalogItemNotFoundException, self).__init__(f'Failed to find {path!r} catalog item') + + +def report_result(): + print('[\033[94mINFO\x1B[0m]\tExecution Complete') + for index, item in enumerate(ITEMS): + index += 1 + data = ITEMS[item] + print(f'\n[\033[94mINFO\x1B[0m]\t{index}) {item}') + if data['success']: + print( + f'[\033[92mOK\x1B[0m]\t - Successfully updated dependencies for {", ".join(data["success"])} versions' + ) + + for i_v, version in enumerate(data['error']): + v_name, error = version + print( + f'[\033[91mFAILED\x1B[0m]\t ({i_v + 1}) Failed to update dependencies for {v_name!r} version: {error}' + ) + + +def update_train_charts(train_path, commit): + # We will gather all charts in the train and then for each chart all it's versions will be updated + if not os.path.exists(train_path): + raise TrainNotFoundException() + + print(f'[\033[94mINFO\x1B[0m]\tProcessing {train_path!r} train') + for item in os.listdir(train_path): + process_catalog_item(os.path.join(train_path, item)) + + report_result() + + if commit and any(ITEMS[item]['success'] for item in ITEMS): + if any(ITEMS[item]['error'] for item in ITEMS): + print(f'[\033[91mFAILED\x1B[0m]\tNot committing changes as failures detected') + else: + commit_msg = f'Updated catalog item dependencies ({train_path.rsplit("/", 1)[-1]} train)\n' \ + 'Following items were updated:\n' + for item in ITEMS: + commit_msg += f'Updated {item} ({", ".join(ITEMS[item]["success"])} versions)\n\n' + + for cmd in ( + ['git', '-C', train_path, 'add', train_path], + ['git', '-C', train_path, 'commit', '-m', commit_msg] + ): + cp = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) + stderr = cp.communicate()[1] + if cp.returncode: + print(f'[\033[91mFAILED\x1B[0m]\tFailed to execute {" ".join(cmd)}: {stderr.decode()}') + exit(1) + + print('[\033[92mOK\x1B[0m]\tChanges committed successfully') + + +def process_catalog_item(item_path): + if not os.path.exists(item_path): + raise CatalogItemNotFoundException(item_path) + + item_name = item_path.rsplit('/', 1)[-1] + print(f'[\033[94mINFO\x1B[0m]\tProcessing {item_name!r} catalog item') + for item_version in os.listdir(item_path): + if os.path.isdir(os.path.join(item_path, item_version)): + update_item_version(item_name, item_version, os.path.join(item_path, item_version)) + + +def update_item_version(item_name, version, version_path): + cp = subprocess.Popen( + ['helm', 'dependency', 'update', version_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + stdout, stderr = cp.communicate() + if cp.returncode: + ITEMS[item_name]['error'].append((version, stderr.decode())) + else: + ITEMS[item_name]['success'].append(version) + + +def main(): + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(help='sub-command help', dest='action') + + parser_setup = subparsers.add_parser('update', help='Update dependencies for specified train') + parser_setup.add_argument('--train', help='Specify train path to update dependencies', required=True) + parser_setup.add_argument('--commit', help='Commit after updating dependencies', default=False) + + args = parser.parse_args() + if args.action == 'update': + update_train_charts(args.train, args.commit) + else: + parser.print_help() + + +if __name__ == '__main__': + main()