jvm bitnami/Keycloak中JAVA_OPTS_APPEND默认值的Helm yaml命令输出

eoxn13cs  于 2023-02-12  发布在  Java
关注(0)|答案(1)|浏览(162)

有人能帮我理解一下这个命令吗-这个键-值对的输出是什么:

JAVA_OPTS_APPEND: {{ printf "-Djgroups.dns.query=%s-headless.%s.svc.%s" (include "common.names.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain | quote }}

其中

common.names.fullname: ""
common.names.namespace: ""
clusterDomain: cluster.local

这段代码来自这里:https://github.com/bitnami/charts/blob/main/bitnami/keycloak/templates/configmap-env-vars.yaml
我是Kubernetes的新手,我正在尝试理解JAVA_OPTS_APPEND的值是什么。
先谢了纳菲

xlpyo6sf

xlpyo6sf1#

你可以用helm template命令在本地渲染helm模板,这将渲染你的值,这样你就可以看到这个命令的输出。
如果您对Kubernetes集群没有足够的权限,可以旋转本地mininkubekind示例,然后呈现模板:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm template bitnami/keycloak --namespace mhajeb

在呈现的清单中,您将找到以下ConfigMap:

# Source: keycloak/templates/configmap-env-vars.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: release-name-keycloak-env-vars
  namespace: "mhajeb"
  labels:
    app.kubernetes.io/name: keycloak
    helm.sh/chart: keycloak-13.0.4
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: keycloak
data:
  KEYCLOAK_ADMIN: "user"
  KEYCLOAK_HTTP_PORT: "8080"
  KEYCLOAK_PROXY: "passthrough"
  KEYCLOAK_ENABLE_STATISTICS: "false"
  KEYCLOAK_DATABASE_HOST: "release-name-postgresql"
  KEYCLOAK_DATABASE_PORT: "5432"
  KEYCLOAK_DATABASE_NAME: "bitnami_keycloak"
  KEYCLOAK_DATABASE_USER: "bn_keycloak"
  KEYCLOAK_PRODUCTION:  "false"
  KEYCLOAK_ENABLE_HTTPS: "false"
  KEYCLOAK_CACHE_TYPE: "ispn"
  KEYCLOAK_CACHE_STACK: "kubernetes"
  JAVA_OPTS_APPEND: "-Djgroups.dns.query=release-name-keycloak-headless.mhajeb.svc.cluster.local"
  KEYCLOAK_LOG_OUTPUT: "default"
  KC_LOG_LEVEL: "INFO"

现在请注意JAVA_OPTS_APPEND: {{ printf "-Djgroups.dns.query=%s-headless.%s.svc.%s" (include "common.names.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain | quote }}渲染:

JAVA_OPTS_APPEND: "-Djgroups.dns.query=release-name-keycloak-headless.mhajeb.svc.cluster.local"

这是通过printf函数完成的,该函数从"父"图表中定义的模板帮助程序中呈现common.names.fullnamecommon.names.namespacce

{{/*
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" -}}
{{- 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 -}}

以及

{{/*
Allow the release namespace to be overridden for multi-namespace deployments in combined charts.
*/}}
{{- define "common.names.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

TLDR;
它将图表、版本名称作为默认值。如果您想覆盖它们,请查看文档:https://github.com/bitnami/charts/tree/main/bitnami/keycloak#common-parameters,或者模板:),然后只需设置:
fullnameOverride用于完全覆盖通用名称的字符串。
namespaceOverride用于完全覆盖通用名称命名空间的字符串
其他例子

helm template my-food-release bitnami/keycloak --namespace mhajeb

结果:

# Source: keycloak/templates/configmap-env-vars.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-food-release-keycloak-env-vars
  namespace: "mhajeb"
  labels:
    app.kubernetes.io/name: keycloak
    helm.sh/chart: keycloak-13.0.4
    app.kubernetes.io/instance: my-food-release
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: keycloak
data:
  KEYCLOAK_DATABASE_HOST: "my-food-release-postgresql"
  ...
  JAVA_OPTS_APPEND: "-Djgroups.dns.query=my-food-release-keycloak-headless.mhajeb.svc.cluster.local"
  ...
helm template my-food-release bitnami/keycloak --namespace mhajeb --set fullnameOverride=daNewName --set namespaceOverride=daNewNamespaceOverride

结果:

# Source: keycloak/templates/configmap-env-vars.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: daNewName-env-vars
  namespace: "daNewNamespaceOverride"
  labels:
    app.kubernetes.io/name: keycloak
    helm.sh/chart: keycloak-13.0.4
    app.kubernetes.io/instance: my-food-release
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: keycloak
data:
  ...
  JAVA_OPTS_APPEND: "-Djgroups.dns.query=daNewName-headless.daNewNamespaceOverride.svc.cluster.local"
  ...

相关问题