Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

Chart refactoring (#311)

PurseChickenae3be43fefb6
diff --git a/charts/.helmignore b/charts/.helmignore
new file mode 100644
index 00000000..0e8a0eb3
--- /dev/null
+++ b/charts/.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/charts/Chart.yaml b/charts/Chart.yaml
index 187c32fc..b3fe70eb 100644
--- a/charts/Chart.yaml
+++ b/charts/Chart.yaml
@@ -1,6 +1,6 @@
apiVersion: v2
name: answer
-description: a simple answer deployments for kubernetes
+description: A simple answer deployments for kubernetes
type: application
version: 0.1.0
-appVersion: "0.1.0"
\ No newline at end of file
+appVersion: "1.0.7"
\ No newline at end of file
diff --git a/charts/README.md b/charts/README.md
index e4d7d1cc..f47b7028 100644
--- a/charts/README.md
+++ b/charts/README.md
@@ -1,2 +1,75 @@
-# Helm Charts for Answer project
+# answer
+An open-source knowledge-based community software. You can use it quickly to build Q&A community for your products, customers, teams, and more.
+## Prerequisites
+
+- Kubernetes 1.20+
+## Configuration
+
+The following table lists the configurable parameters of the answer chart and their default values.
+
+| Parameter | Description | Default |
+| --------- | ----------- | ------- |
+| `replicaCount` | Number of answer replicas | `1` |
+| `image.repository` | Image repository | `answerdev/answer` |
+| `image.pullPolicy` | Image pull policy | `Always` |
+| `image.tag` | Image tag | `latest` |
+| `env` | Optional environment variables for answer | `LOG_LEVEL: INFO` |
+| `extraContainers` | Optional sidecar containers to run along side answer | `[]` |
+| `persistence.enabled` | Enable or disable persistence for the /data volume | `true` |
+| `persistence.accessMode` | Specify the access mode of the persistent volume | `ReadWriteOnce` |
+| `persistence.size` | The size of the persistent volume | `5Gi` |
+| `persistence.annotations` | Annotations to add to the volume claim | `{}` |
+| `imagePullSecrets` | Reference to one or more secrets to be used when pulling images | `[]` |
+| `nameOverride` | nameOverride replaces the name of the chart in the Chart.yaml file, when this is used to construct Kubernetes object names. | |
+| `fullnameOverride` | fullnameOverride completely replaces the generated name. | |
+| `serviceAccount.create` | If `true`, create a new service account | `true` |
+| `serviceAccount.annotations` | Annotations to add to the service account | `{}` |
+| `serviceAccount.name` | Service account to be used. If not set and `serviceAccount.create` is `true`, a name is generated using the fullname template | |
+| `podAnnotations` | Annotations to add to the answer pod | `{}` |
+| `podSecurityContext` | Security context for the answer pod | `{}` refer to [Default Security Contexts](#default-security-contexts) |
+| `securityContext` | Security context for the answer container | `{}` refer to [Default Security Contexts](#default-security-contexts) |
+| `service.type` | The type of service to be used | `ClusterIP` |
+| `service.port` | The port that the service should listen on for requests. Also used as the container port. | `80` |
+| `ingress.enabled` | Enable or disable ingress. | `false` |
+| `resources` | CPU/memory resource requests/limits | `{}` |
+| `autoscaling.enabled` | Enable or disable pod autoscaling. If enabled, replicas are disabled. | `false` |
+| `nodeSelector` | Node labels for pod assignment | `{}` |
+| `tolerations` | Node tolerations for pod assignment | `[]` |
+| `affinity` | Node affinity for pod assignment | `{}` |
+
+### Default Security Contexts
+
+The default pod-level and container-level security contexts, below, adhere to the [restricted](https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted) Pod Security Standards policies.
+
+Default pod-level securityContext:
+```yaml
+runAsNonRoot: true
+seccompProfile:
+ type: RuntimeDefault
+```
+
+Default containerSecurityContext:
+```yaml
+allowPrivilegeEscalation: false
+capabilities:
+ drop:
+ - ALL
+```
+### Installing with a Values file
+
+```console
+$ helm install answer -f values.yaml .
+```
+> **Tip**: You can use the default [values.yaml]
+
+## TODO
+
+Publish the chart to Artifacthub and add proper installation instructions. E.G.
+> **NOTE**: This is not currently a valid installation option.
+
+```console
+$ helm repo add answerdev https://charts.answer.dev/
+$ helm repo update
+$ helm install answerdev/answer -n mynamespace
+```
\ No newline at end of file
diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl
index cfdf84d7..5b039579 100644
--- a/charts/templates/_helpers.tpl
+++ b/charts/templates/_helpers.tpl
@@ -34,7 +34,7 @@ Create chart name and version as used by the chart label.
Common labels
*/}}
{{- define "answer.labels" -}}
-helm.sh/chart: {{ .Release.Name }}
+helm.sh/chart: {{ include "answer.chart" . }}
{{ include "answer.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
@@ -46,6 +46,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
Selector labels
*/}}
{{- define "answer.selectorLabels" -}}
-app.kubernetes.io/name: answer
+app.kubernetes.io/name: {{ include "answer.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
+
+{{/*
+Create the name of the service account to use
+*/}}
+{{- define "answer.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create }}
+{{- default (include "answer.fullname" .) .Values.serviceAccount.name }}
+{{- else }}
+{{- default "default" .Values.serviceAccount.name }}
+{{- end }}
+{{- end }}
diff --git a/charts/templates/config.yaml b/charts/templates/config.yaml
deleted file mode 100644
index 24fd733e..00000000
--- a/charts/templates/config.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
----
-apiVersion: v1
-kind: ConfigMap
-metadata:
- name: answer-config
- namespace: {{ .Values.namespace | default "default" | quote }}
-data:
- default.yaml: |-
- #
diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml
new file mode 100644
index 00000000..ced91e4e
--- /dev/null
+++ b/charts/templates/deployment.yaml
@@ -0,0 +1,88 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: {{ include "answer.fullname" . }}
+ labels:
+ {{- include "answer.labels" . | nindent 4 }}
+spec:
+ {{- if not .Values.autoscaling.enabled }}
+ replicas: {{ .Values.replicaCount }}
+ {{- end }}
+ selector:
+ matchLabels:
+ {{- include "answer.selectorLabels" . | nindent 6 }}
+ template:
+ metadata:
+ {{- with .Values.podAnnotations }}
+ annotations:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ labels:
+ {{- include "answer.selectorLabels" . | nindent 8 }}
+ spec:
+ {{- with .Values.imagePullSecrets }}
+ imagePullSecrets:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ serviceAccountName: {{ include "answer.serviceAccountName" . }}
+ securityContext:
+ {{- toYaml .Values.podSecurityContext | nindent 8 }}
+ containers:
+ - name: {{ .Chart.Name }}
+ securityContext:
+ {{- toYaml .Values.securityContext | nindent 12 }}
+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+ imagePullPolicy: {{ .Values.image.pullPolicy }}
+ ports:
+ - name: http
+ containerPort: {{ .Values.service.port }}
+ protocol: TCP
+ livenessProbe:
+ httpGet:
+ path: /
+ port: http
+ readinessProbe:
+ httpGet:
+ path: /
+ port: http
+ resources:
+ {{- toYaml .Values.resources | nindent 12 }}
+ {{- if .Values.env }}
+ env:
+ {{- range .Values.env }}
+ - name: {{ .name }}
+ {{- if .value | quote }}
+ value: {{ .value | quote }}
+ {{- end }}
+ {{- if .valueFrom }}
+ valueFrom:
+ {{- toYaml .valueFrom | nindent 16 }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+ volumeMounts:
+ - name: data
+ mountPath: "/data"
+ {{- if .Values.extraContainers }}
+ {{- toYaml .Values.extraContainers | nindent 8 }}
+ {{- end }}
+ volumes:
+ - name: data
+ {{- if .Values.persistence.enabled }}
+ persistentVolumeClaim:
+ claimName: {{ include "answer.fullname" . }}-claim
+ {{- else }}
+ emptyDir: {}
+ {{- end -}}
+ {{- with .Values.nodeSelector }}
+ nodeSelector:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ {{- with .Values.affinity }}
+ affinity:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ {{- with .Values.tolerations }}
+ tolerations:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
\ No newline at end of file
diff --git a/charts/templates/hpa.yaml b/charts/templates/hpa.yaml
new file mode 100644
index 00000000..53687b82
--- /dev/null
+++ b/charts/templates/hpa.yaml
@@ -0,0 +1,28 @@
+{{- if .Values.autoscaling.enabled }}
+apiVersion: autoscaling/v2beta1
+kind: HorizontalPodAutoscaler
+metadata:
+ name: {{ include "answer.fullname" . }}
+ labels:
+ {{- include "answer.labels" . | nindent 4 }}
+spec:
+ scaleTargetRef:
+ apiVersion: apps/v1
+ kind: Deployment
+ name: {{ include "answer.fullname" . }}
+ minReplicas: {{ .Values.autoscaling.minReplicas }}
+ maxReplicas: {{ .Values.autoscaling.maxReplicas }}
+ metrics:
+ {{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
+ - type: Resource
+ resource:
+ name: cpu
+ targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
+ {{- end }}
+ {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
+ - type: Resource
+ resource:
+ name: memory
+ targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
+ {{- end }}
+{{- end }}
diff --git a/charts/templates/ingress.yaml b/charts/templates/ingress.yaml
new file mode 100644
index 00000000..fd3de613
--- /dev/null
+++ b/charts/templates/ingress.yaml
@@ -0,0 +1,61 @@
+{{- if .Values.ingress.enabled -}}
+{{- $fullName := include "answer.fullname" . -}}
+{{- $svcPort := .Values.service.port -}}
+{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
+ {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
+ {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
+ {{- end }}
+{{- end }}
+{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
+apiVersion: networking.k8s.io/v1
+{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
+apiVersion: networking.k8s.io/v1beta1
+{{- else -}}
+apiVersion: extensions/v1beta1
+{{- end }}
+kind: Ingress
+metadata:
+ name: {{ $fullName }}
+ labels:
+ {{- include "answer.labels" . | nindent 4 }}
+ {{- with .Values.ingress.annotations }}
+ annotations:
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+spec:
+ {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
+ ingressClassName: {{ .Values.ingress.className }}
+ {{- end }}
+ {{- if .Values.ingress.tls }}
+ tls:
+ {{- range .Values.ingress.tls }}
+ - hosts:
+ {{- range .hosts }}
+ - {{ . | quote }}
+ {{- end }}
+ secretName: {{ .secretName }}
+ {{- end }}
+ {{- end }}
+ rules:
+ {{- range .Values.ingress.hosts }}
+ - host: {{ .host | quote }}
+ http:
+ paths:
+ {{- range .paths }}
+ - path: {{ .path }}
+ {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
+ pathType: {{ .pathType }}
+ {{- end }}
+ backend:
+ {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
+ service:
+ name: {{ $fullName }}
+ port:
+ number: {{ $svcPort }}
+ {{- else }}
+ serviceName: {{ $fullName }}
+ servicePort: {{ $svcPort }}
+ {{- end }}
+ {{- end }}
+ {{- end }}
+{{- end }}
diff --git a/charts/templates/pvc.yaml b/charts/templates/pvc.yaml
new file mode 100644
index 00000000..7e510033
--- /dev/null
+++ b/charts/templates/pvc.yaml
@@ -0,0 +1,25 @@
+{{- if .Values.persistence.enabled }}
+kind: PersistentVolumeClaim
+apiVersion: v1
+metadata:
+ name: {{ include "answer.fullname" . }}-claim
+ {{- with .Values.persistence.annotations }}
+ annotations:
+ {{ toYaml . | indent 4 }}
+ {{- end }}
+ labels:
+ {{- include "answer.labels" . | nindent 4 }}
+spec:
+ {{- if .Values.persistence.storageClass }}
+ {{- if (eq "-" .Values.persistence.storageClass) }}
+ storageClassName: ""
+ {{- else }}
+ storageClassName: "{{ .Values.persistence.storageClass }}"
+ {{- end }}
+ {{- end }}
+ accessModes:
+ - {{ .Values.persistence.accessMode | quote }}
+ resources:
+ requests:
+ storage: {{ .Values.persistence.size | quote }}
+{{- end }}
\ No newline at end of file
diff --git a/charts/templates/service.yaml b/charts/templates/service.yaml
index b5db58f8..4f587446 100644
--- a/charts/templates/service.yaml
+++ b/charts/templates/service.yaml
@@ -1,17 +1,15 @@
----
apiVersion: v1
kind: Service
metadata:
name: {{ include "answer.fullname" . }}
labels:
{{- include "answer.labels" . | nindent 4 }}
- namespace: {{ .Values.namespace | default "default" | quote }}
spec:
- type: ClusterIP
+ type: {{ .Values.service.type }}
ports:
- - name: answer
- port: 80
- targetPort: 80
+ - port: {{ .Values.service.port }}
+ targetPort: http
protocol: TCP
+ name: http
selector:
{{- include "answer.selectorLabels" . | nindent 4 }}
diff --git a/charts/templates/serviceaccount.yaml b/charts/templates/serviceaccount.yaml
new file mode 100644
index 00000000..7f4fc535
--- /dev/null
+++ b/charts/templates/serviceaccount.yaml
@@ -0,0 +1,12 @@
+{{- if .Values.serviceAccount.create -}}
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: {{ include "answer.serviceAccountName" . }}
+ labels:
+ {{- include "answer.labels" . | nindent 4 }}
+ {{- with .Values.serviceAccount.annotations }}
+ annotations:
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+{{- end }}
diff --git a/charts/templates/statefulset.yaml b/charts/templates/statefulset.yaml
deleted file mode 100644
index ac6a6be8..00000000
--- a/charts/templates/statefulset.yaml
+++ /dev/null
@@ -1,31 +0,0 @@
----
-apiVersion: apps/v1
-kind: StatefulSet
-metadata:
- name: answer
- namespace: {{ .Values.namespace | default "default" | quote }}
-spec:
- selector:
- matchLabels:
- {{- include "answer.labels" . | nindent 6 }}
- serviceName: answer
- replicas: 1
- template:
- metadata:
- labels:
- {{- include "answer.labels" . | nindent 8 }}
- spec:
- containers:
- - name: answer
- image: nginx:stable
- ports:
- - containerPort: 80
- name: answer-ui
- volumeMounts:
- - name: config
- mountPath: "/etc/answer.yaml"
- subPath: default.yaml
- volumes:
- - name: config
- configMap:
- name: answer-config
diff --git a/charts/values.yaml b/charts/values.yaml
index 9065ca5b..74b15dcc 100644
--- a/charts/values.yaml
+++ b/charts/values.yaml
@@ -1 +1,147 @@
-namespace: default
+# Default values for answer.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+replicaCount: 1
+
+image:
+ repository: answerdev/answer
+ pullPolicy: Always
+ # Overrides the image tag whose default is the chart appVersion.
+ tag: "latest"
+
+# Environment variables
+# Configure environment variables below
+# https://answer.dev/docs/env
+env:
+ - name: LOG_LEVEL
+ # [DEBUG INFO WARN ERROR]
+ value: "INFO"
+ # uncomment the below values to use AUTO_INSTALL and not have to go through the setup process.
+ # Once used to do the initial setup, these variables wont be used moving forward.
+ # You must at a minimum comment AUTO_INSTALL after initial setup to prevent an error about the database already being initiated.
+ # - name: AUTO_INSTALL
+ # value: "true"
+ # - name: DB_TYPE
+ # value: "sqlite3"
+ # # DB_FILE Only for sqlite3
+ # - name: DB_FILE
+ # value: "/data/answer.db"
+ # - name: LANGUAGE
+ # value: "en-US"
+ # - name: SITE_NAME
+ # value: "MyAnswer"
+ # - name: SITE_URL
+ # value: "http://localhost:80"
+ # - name: CONTACT_EMAIL
+ # value: "[email protected]"
+ # - name: ADMIN_NAME
+ # # lowercase
+ # value: "myadmin"
+ # - name: ADMIN_PASSWORD
+ # # 32 Characters MAX
+ # value: "MyInsecurePasswordInTheRepo!"
+ # # Use valueFrom to use a secret
+ # # valueFrom:
+ # # secretKeyRef:
+ # # key: answer-admin-password
+ # # name: answer-secrets
+ # - name: ADMIN_EMAIL
+ # value: "[email protected]"
+
+# Configure extra containers
+extraContainers: []
+ # - name: cloudsql-proxy
+ # image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.1.2
+ # command:
+ # - /cloud-sql-proxy
+ # args:
+ # - project:region:instance
+ # - --port=5432
+ # - --auto-iam-authn
+ # ports:
+ # - containerPort: 5432
+
+# Persistence for the /data volume
+# Without persistence, your uploads and config.yaml will not be remembered between restarts.
+persistence:
+ enabled: true
+ # If set to "-", storageClassName: "", which disables dynamic provisioning
+ # If undefined (the default) or set to null, no storageClassName spec is
+ # set, choosing the default provisioner. (gp2 on AWS, standard on
+ # GKE, AWS & OpenStack)
+ # storageClass: "-"
+ accessMode: ReadWriteOnce
+ size: 5Gi
+ annotations: {}
+
+imagePullSecrets: []
+nameOverride: ""
+fullnameOverride: ""
+
+serviceAccount:
+ # Specifies whether a service account should be created
+ create: true
+ # Annotations to add to the service account
+ annotations: {}
+ # The name of the service account to use.
+ # If not set and create is true, a name is generated using the fullname template
+ name: ""
+
+podAnnotations: {}
+
+podSecurityContext: {}
+ # fsGroup: 2000
+
+securityContext: {}
+ # capabilities:
+ # drop:
+ # - ALL
+ # readOnlyRootFilesystem: true
+ # runAsNonRoot: true
+ # runAsUser: 1000
+
+service:
+ type: ClusterIP
+ port: 80
+
+ingress:
+ enabled: false
+ className: ""
+ annotations: {}
+ # kubernetes.io/ingress.class: nginx
+ # kubernetes.io/tls-acme: "true"
+ hosts:
+ - host: answer.local
+ paths:
+ - path: /
+ pathType: ImplementationSpecific
+ tls: []
+ # - secretName: answer-tls
+ # hosts:
+ # - answer.local
+
+resources: {}
+ # We usually recommend not to specify default resources and to leave this as a conscious
+ # choice for the user. This also increases chances charts run on environments with little
+ # resources, such as Minikube. If you do want to specify resources, uncomment the following
+ # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
+ # limits:
+ # cpu: 100m
+ # memory: 128Mi
+ # requests:
+ # cpu: 100m
+ # memory: 128Mi
+
+autoscaling:
+ enabled: false
+ minReplicas: 1
+ maxReplicas: 100
+ targetCPUUtilizationPercentage: 80
+ # targetMemoryUtilizationPercentage: 80
+
+nodeSelector: {}
+
+tolerations: []
+
+affinity: {}
\ No newline at end of file