From 62f7d87b2ceefeb174e2333ed733390463fcc8c1 Mon Sep 17 00:00:00 2001 From: qizhicheng Date: Fri, 6 Mar 2026 12:17:58 +0800 Subject: [PATCH 1/2] feat: add generic app template arnor --- charts/arnor/.helmignore | 23 +++ charts/arnor/Chart.yaml | 26 ++++ charts/arnor/README.md | 133 ++++++++++++++++++ charts/arnor/templates/NOTES.txt | 22 +++ charts/arnor/templates/_helpers.tpl | 72 ++++++++++ charts/arnor/templates/deployment.yaml | 77 ++++++++++ charts/arnor/templates/hpa.yaml | 28 ++++ charts/arnor/templates/httproute.yaml | 25 ++++ charts/arnor/templates/ingress.yaml | 61 ++++++++ charts/arnor/templates/prometheusrule.yaml | 20 +++ charts/arnor/templates/service.yaml | 15 ++ charts/arnor/templates/serviceaccount.yaml | 12 ++ charts/arnor/templates/servicemonitor.yaml | 48 +++++++ .../templates/tests/test-connection.yaml | 15 ++ charts/arnor/templates/vaultstaticsecret.yaml | 16 +++ charts/arnor/values.yaml | 127 +++++++++++++++++ 16 files changed, 720 insertions(+) create mode 100644 charts/arnor/.helmignore create mode 100644 charts/arnor/Chart.yaml create mode 100644 charts/arnor/README.md create mode 100644 charts/arnor/templates/NOTES.txt create mode 100644 charts/arnor/templates/_helpers.tpl create mode 100644 charts/arnor/templates/deployment.yaml create mode 100644 charts/arnor/templates/hpa.yaml create mode 100644 charts/arnor/templates/httproute.yaml create mode 100644 charts/arnor/templates/ingress.yaml create mode 100644 charts/arnor/templates/prometheusrule.yaml create mode 100644 charts/arnor/templates/service.yaml create mode 100644 charts/arnor/templates/serviceaccount.yaml create mode 100644 charts/arnor/templates/servicemonitor.yaml create mode 100644 charts/arnor/templates/tests/test-connection.yaml create mode 100644 charts/arnor/templates/vaultstaticsecret.yaml create mode 100644 charts/arnor/values.yaml diff --git a/charts/arnor/.helmignore b/charts/arnor/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/arnor/.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/arnor/Chart.yaml b/charts/arnor/Chart.yaml new file mode 100644 index 0000000..d8b0de0 --- /dev/null +++ b/charts/arnor/Chart.yaml @@ -0,0 +1,26 @@ +apiVersion: v2 +name: arnor +description: A Helm chart for standard web application +maintainers: +- name: douban + +# 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: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/charts/arnor/README.md b/charts/arnor/README.md new file mode 100644 index 0000000..6a864f2 --- /dev/null +++ b/charts/arnor/README.md @@ -0,0 +1,133 @@ +# Arnor + +Arnor 并不是一个具体的 app, 本 Chart 用于一些简单的项目部署, 使用者在填写了镜像及域名配置后, 即可快速拉起一个 HTTP 应用。 + +## 使用步骤 + +1. `helm repo add douban https://douban.github.io/charts/` +2. `helm install my-app douban/arnor -f my-values.yaml` + +## 镜像 + +- `image.repository`: 业务镜像仓库 (如 `registry.example.com/my-app`) +- `image.tag`: 镜像版本号 (如 `v1.0.0`) + +## 主机名/域名路由 + +Arnor 可分别启用 Ingress 或 Envoy Gateway HTTPRoute, 两者互不依赖。 + +### Ingress 配置 + +```yaml +ingress: + enabled: true + className: nginx + hosts: + - host: app.example.com + paths: + - path: / + pathType: ImplementationSpecific + tls: + - secretName: app-example-com-tls + hosts: + - app.example.com +``` + +### HTTPRoute 配置 + +```yaml +httpRoute: + enabled: true + parentRefs: + - name: envoy-gateway-bundle + namespace: envoy-gateway-system + hostnames: + - app.example.com + extraPaths: [] +``` + +## 挂载 Volume 与 Secret + +1. 在 `volumes` 中定义所需卷 (ConfigMap、Secret、PVC 等)。 +2. 在 `volumeMounts` 中将卷挂载到容器路径。 + +示例: + +```yaml +volumes: + - name: app-config + configMap: + name: my-config + - name: extra-secret + secret: + secretName: my-app-secret +volumeMounts: + - name: app-config + mountPath: /etc/app + - name: extra-secret + mountPath: /var/run/secret + readOnly: true +``` + +## Vault 静态密钥注入 + +启用 `vaultStaticSecret.enabled` 后, Chart 会负责拉取 Vault 中的静态密钥并注入到 Kubernetes Secret 中; 需要在 `volumes` 与 `volumeMounts` 手动引用该 Secret 才能在容器内使用。 + +```yaml +vaultStaticSecret: + enabled: true + mount: kv-v2 + path: secret/data + secretNameOverride: my-secret + +volumes: + - name: vault-secret + secret: + secretName: my-secret +volumeMounts: + - name: vault-secret + mountPath: /vault/secrets + readOnly: true +``` + +> 最终路径与 `path` 完全一致, 请确认 Vault 中已存在该路径。 + +## 完整示例 + +```yaml +image: + repository: registry.example.com/frontend + tag: v1.2.3 + +ingress: + enabled: true + className: nginx + hosts: + - host: frontend.example.com + paths: + - path: / + pathType: ImplementationSpecific + +httpRoute: + enabled: false + +volumes: + - name: env-secret + secret: + secretName: frontend-env + - name: vault-secret + secret: + secretName: frontend +volumeMounts: + - name: env-secret + mountPath: /app/.env + readOnly: true + - name: vault-secret + mountPath: /vault/data + readOnly: true + +vaultStaticSecret: + enabled: true + secretNameOverride: frontend +``` + diff --git a/charts/arnor/templates/NOTES.txt b/charts/arnor/templates/NOTES.txt new file mode 100644 index 0000000..ed7379a --- /dev/null +++ b/charts/arnor/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "arnor.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "arnor.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "arnor.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "arnor.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/arnor/templates/_helpers.tpl b/charts/arnor/templates/_helpers.tpl new file mode 100644 index 0000000..fae741e --- /dev/null +++ b/charts/arnor/templates/_helpers.tpl @@ -0,0 +1,72 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "arnor.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 "arnor.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 "arnor.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "arnor.labels" -}} +helm.sh/chart: {{ include "arnor.chart" . }} +{{ include "arnor.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "arnor.selectorLabels" -}} +app.kubernetes.io/name: {{ include "arnor.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "arnor.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "arnor.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +VaultStaticSecret secretName +*/}} +{{- define "arnor.vaultStaticSecretDestination" -}} +{{- if .Values.vaultStaticSecret.secretNameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- include "arnor.fullname" . }} +{{- end }} diff --git a/charts/arnor/templates/deployment.yaml b/charts/arnor/templates/deployment.yaml new file mode 100644 index 0000000..c484335 --- /dev/null +++ b/charts/arnor/templates/deployment.yaml @@ -0,0 +1,77 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "arnor.fullname" . }} + labels: + {{- include "arnor.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "arnor.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "arnor.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "arnor.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 }} + {{- with .Values.args }} + args: + {{- toYaml . | nindent 12 }} + {{- end}} + {{- with .Values.env }} + env: + {{- toYaml . | nindent 12 }} + {{- end}} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.containerPort }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumes}} + volumes: + {{- toYaml . | nindent 8 }} + {{- 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 }} diff --git a/charts/arnor/templates/hpa.yaml b/charts/arnor/templates/hpa.yaml new file mode 100644 index 0000000..341f251 --- /dev/null +++ b/charts/arnor/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "arnor.fullname" . }} + labels: + {{- include "arnor.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "arnor.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/arnor/templates/httproute.yaml b/charts/arnor/templates/httproute.yaml new file mode 100644 index 0000000..1c36755 --- /dev/null +++ b/charts/arnor/templates/httproute.yaml @@ -0,0 +1,25 @@ +{{- if .Values.httpRoute.enabled }} +--- +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ include "arnor.fullname" . }} + labels: + {{- include "arnor.labels" . | nindent 4 }} +spec: +{{- with .Values.globalConfigs.routeParentRefs }} + parentRefs: + {{- toYaml . | nindent 4 }} +{{- end }} + hostnames: + {{- range .Values.httpRoute.hostnames }} + - {{ . | quote }} + {{- end }} + rules: +{{- if .Values.controller.httpRoute.extraRules }} +{{- toYaml .Values.controller.httpRoute.extraRules | nindent 2 }} +{{- end }} + - backendRefs: + - name: {{ include "arnor.fullname" . }} + port: {{ .Values.service.port }} +{{- end }} diff --git a/charts/arnor/templates/ingress.yaml b/charts/arnor/templates/ingress.yaml new file mode 100644 index 0000000..1c32f8e --- /dev/null +++ b/charts/arnor/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "arnor.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 "arnor.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/arnor/templates/prometheusrule.yaml b/charts/arnor/templates/prometheusrule.yaml new file mode 100644 index 0000000..d7e0049 --- /dev/null +++ b/charts/arnor/templates/prometheusrule.yaml @@ -0,0 +1,20 @@ +{{- if .Values.prometheusRule.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: {{ template "arnor.fullname" . }} +{{- with .Values.prometheusRule.namespace }} + namespace: {{ . }} +{{- end }} + labels: +{{ include "arnor.labels" . | indent 4 }} +{{- with .Values.prometheusRule.additionalLabels }} +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- with .Values.prometheusRule.rules }} + groups: + - name: {{ template "arnor.name" $ }} + rules: {{ tpl (toYaml .) $ | nindent 8 }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/arnor/templates/service.yaml b/charts/arnor/templates/service.yaml new file mode 100644 index 0000000..0f02ca5 --- /dev/null +++ b/charts/arnor/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "arnor.fullname" . }} + labels: + {{- include "arnor.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "arnor.selectorLabels" . | nindent 4 }} diff --git a/charts/arnor/templates/serviceaccount.yaml b/charts/arnor/templates/serviceaccount.yaml new file mode 100644 index 0000000..4c0e42c --- /dev/null +++ b/charts/arnor/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "arnor.serviceAccountName" . }} + labels: + {{- include "arnor.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/arnor/templates/servicemonitor.yaml b/charts/arnor/templates/servicemonitor.yaml new file mode 100644 index 0000000..3c8a9b9 --- /dev/null +++ b/charts/arnor/templates/servicemonitor.yaml @@ -0,0 +1,48 @@ +{{- if .Values.serviceMonitor.enabled }} +{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) ( .Values.serviceMonitor.enabled ) }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: +{{- if .Values.serviceMonitor.labels }} + labels: +{{ toYaml .Values.serviceMonitor.labels | indent 4}} +{{- end }} + name: {{ template "arnor.fullname" . }} +{{- if .Values.serviceMonitor.namespace }} + namespace: {{ .Values.serviceMonitor.namespace }} +{{- end }} +spec: + endpoints: + - port: http +{{- if .Values.serviceMonitor.interval }} + interval: {{ .Values.serviceMonitor.interval }} +{{- end }} +{{- if .Values.serviceMonitor.telemetryPath }} + path: {{ .Values.serviceMonitor.telemetryPath }} +{{- end }} +{{- if .Values.serviceMonitor.timeout }} + scrapeTimeout: {{ .Values.serviceMonitor.timeout }} +{{- end }} +{{- if .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: +{{ toYaml .Values.serviceMonitor.metricRelabelings | indent 4 }} +{{- end }} +{{- if .Values.serviceMonitor.relabelings }} + relabelings: +{{ toYaml .Values.serviceMonitor.relabelings | indent 4 }} +{{- end }} + jobLabel: {{ template "arnor.fullname" . }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: +{{- include "arnor.selectorLabels" . | nindent 6 }} +{{- if .Values.serviceMonitor.targetLabels }} + targetLabels: +{{- range .Values.serviceMonitor.targetLabels }} + - {{ . }} +{{- end }} +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/arnor/templates/tests/test-connection.yaml b/charts/arnor/templates/tests/test-connection.yaml new file mode 100644 index 0000000..ff53902 --- /dev/null +++ b/charts/arnor/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "arnor.fullname" . }}-test-connection" + labels: + {{- include "arnor.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "arnor.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/arnor/templates/vaultstaticsecret.yaml b/charts/arnor/templates/vaultstaticsecret.yaml new file mode 100644 index 0000000..e62ab0a --- /dev/null +++ b/charts/arnor/templates/vaultstaticsecret.yaml @@ -0,0 +1,16 @@ +{{- if .Values.vaultStaticSecret.enabled }} +apiVersion: secrets.hashicorp.com/v1beta1 +kind: VaultStaticSecret +metadata: + name: {{ include "arnor.fullname" . }} + labels: + {{- include "arnor.labels" . | nindent 4 }} +spec: + path: {{ .Values.vaultStaticSecret.path }} + type: {{ .Values.vaultStaticSecret.type }} + mount: {{ .Values.vaultStaticSecret.mount }} + destination: + create: true + name: {{ include "arnor.vaultStaticSecretDestination" .}} + type: "Opaque" +{{- end}} diff --git a/charts/arnor/values.yaml b/charts/arnor/values.yaml new file mode 100644 index 0000000..17c0042 --- /dev/null +++ b/charts/arnor/values.yaml @@ -0,0 +1,127 @@ +# Default values for arnor. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: arnor + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +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 + +vaultStaticSecret: + enabled: false + # basePath is the base path in vault where the secrets are stored, the final path would be basePath + "/" + secretName + secretNameOverride: "" + mount: "kv-v2" + type: "kv-v2" + path: "secret/data" + +service: + type: ClusterIP + port: 80 + +containerPort: 80 + +volumes: [] + +volumeMounts: [] + +env: [] + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: arnor + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + + +httpRoute: + enabled: false + parentRefs: [] + # - name: envoy-gateway-bundle + # namespace: envoy-gateway-system + # define routing rules below + hostnames: [] + extraPaths: [] + # - matches: + # - path: + # type: PathPrefix + # value: /custom + # backendRefs: + # - name: my-service + # port: 8080 + +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: {} + + +serviceMonitor: + enabled: false + + +prometheusRule: + enabled: false + # namespace: monitoring + # additionalLabels: {} + # release: prometheus-operator + # rules: [] From 82d85c540df85453b7e347a8422085b7ae3976b5 Mon Sep 17 00:00:00 2001 From: qizhicheng Date: Fri, 6 Mar 2026 12:27:05 +0800 Subject: [PATCH 2/2] feat: enhance vault static secret configuration and update HTTP route references --- charts/arnor/README.md | 12 ++++++++++++ charts/arnor/templates/_helpers.tpl | 3 ++- charts/arnor/templates/deployment.yaml | 2 +- charts/arnor/templates/httproute.yaml | 6 +++--- charts/arnor/values.yaml | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/charts/arnor/README.md b/charts/arnor/README.md index 6a864f2..535fd2b 100644 --- a/charts/arnor/README.md +++ b/charts/arnor/README.md @@ -73,6 +73,18 @@ volumeMounts: 启用 `vaultStaticSecret.enabled` 后, Chart 会负责拉取 Vault 中的静态密钥并注入到 Kubernetes Secret 中; 需要在 `volumes` 与 `volumeMounts` 手动引用该 Secret 才能在容器内使用。 +如果没有设置 `vaultStaticSecret.secretNameOverride`, secret 名字会与 fullname 完全相同, 也就是: + +```bash +# release name 和 chart 同名时, 为 release name +arnor +# release name 和 chart 不同时, 为 release name - chart name +my-app-arnor +# 填写了 fullnameOverride 的情况下, 以 fullnameOverride 为准 +my-fullname +# 详细逻辑请参考 _helpers.tpl 内的代码 +``` + ```yaml vaultStaticSecret: enabled: true diff --git a/charts/arnor/templates/_helpers.tpl b/charts/arnor/templates/_helpers.tpl index fae741e..ad7ba52 100644 --- a/charts/arnor/templates/_helpers.tpl +++ b/charts/arnor/templates/_helpers.tpl @@ -66,7 +66,8 @@ VaultStaticSecret secretName */}} {{- define "arnor.vaultStaticSecretDestination" -}} {{- if .Values.vaultStaticSecret.secretNameOverride }} -{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- .Values.vaultStaticSecret.secretNameOverride | trunc 63 | trimSuffix "-" }} {{- else }} {{- include "arnor.fullname" . }} {{- end }} +{{- end }} diff --git a/charts/arnor/templates/deployment.yaml b/charts/arnor/templates/deployment.yaml index c484335..474e25a 100644 --- a/charts/arnor/templates/deployment.yaml +++ b/charts/arnor/templates/deployment.yaml @@ -59,7 +59,7 @@ spec: port: http resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.volumes}} + {{- with .Values.volumes }} volumes: {{- toYaml . | nindent 8 }} {{- end }} diff --git a/charts/arnor/templates/httproute.yaml b/charts/arnor/templates/httproute.yaml index 1c36755..b839af3 100644 --- a/charts/arnor/templates/httproute.yaml +++ b/charts/arnor/templates/httproute.yaml @@ -7,7 +7,7 @@ metadata: labels: {{- include "arnor.labels" . | nindent 4 }} spec: -{{- with .Values.globalConfigs.routeParentRefs }} +{{- with .Values.httpRoute.parentRefs }} parentRefs: {{- toYaml . | nindent 4 }} {{- end }} @@ -16,8 +16,8 @@ spec: - {{ . | quote }} {{- end }} rules: -{{- if .Values.controller.httpRoute.extraRules }} -{{- toYaml .Values.controller.httpRoute.extraRules | nindent 2 }} +{{- if .Values.httpRoute.extraRules }} +{{- toYaml .Values.httpRoute.extraRules | nindent 2 }} {{- end }} - backendRefs: - name: {{ include "arnor.fullname" . }} diff --git a/charts/arnor/values.yaml b/charts/arnor/values.yaml index 17c0042..f18117d 100644 --- a/charts/arnor/values.yaml +++ b/charts/arnor/values.yaml @@ -38,7 +38,7 @@ securityContext: {} vaultStaticSecret: enabled: false - # basePath is the base path in vault where the secrets are stored, the final path would be basePath + "/" + secretName + # if set, the secret created by VaultStaticSecret will use this name instead of the default fullname secretNameOverride: "" mount: "kv-v2" type: "kv-v2"