0

Could anybody please help me understand this command - What would be the output of this key -value pair:

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

where

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

This piece of code is from here: https://github.com/bitnami/charts/blob/main/bitnami/keycloak/templates/configmap-env-vars.yaml

I am fairly new to Kubernetes and I am trying to understand what would be the value of JAVA_OPTS_APPEND.

Thanks in advance. Nafee

nafi
  • 55
  • 2
  • 9

1 Answers1

2

You can render helm templates locally with helm template command, this will render your values so you see the outputs of this command.

If you don't enough permissions on your Kubernetes cluster, you can spin a local mininkube or kind instance and then render the template:

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

In the rendered manifest you will find the following 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"

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

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

And that was done with printf function which rendered common.names.fullname and common.names.namespacce from the templates helpers which are defined in the "parent" chart:

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

and

{{/*
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;

It is taking the Chart, Release names as defaults. And if you want to override them have a look at the documentation: https://github.com/bitnami/charts/tree/main/bitnami/keycloak#common-parameters, or the templates :), and just set:

fullnameOverride String to fully override common.names.fullname

namespaceOverride String to fully override common.names.namespace


Other examples

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

Result:

# 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 

Result:

# 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"
  ...
Fcmam5
  • 4,888
  • 1
  • 16
  • 33
  • 1
    In the first paragraph, it's worth noting that `helm template` doesn't normally contact the cluster; compare `helm install --dry-run`, which does. In this particular case it doesn't matter, but it's possible to make charts conditional on specific Kubernetes API versions, where it would be more visible. – David Maze Feb 10 '23 at 14:11
  • Thanks so much - The details helped a lot. I have posted another related question on related topic. Could you be able to answer please: https://stackoverflow.com/questions/75412661/updating-java-heap-size-while-deploying-installing-keycloak-using-bitnami-keyclo – nafi Feb 10 '23 at 14:52