bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
8.81k stars 9.1k forks source link

Problems deploying pre-configured and exported Keycloak realms #9739

Closed werwuifi closed 2 years ago

werwuifi commented 2 years ago

Name and Version

bitnami/keycloak 7.1.6

What steps will reproduce the bug?

I am customizing values.yaml to import existing realm configs. According to the comments in the template file

# NOTE: nil keys will be considered files to import locally my assumption was I only need to provide the path to the exported files and leave the value after the colon empty.

keycloakConfigCli:
    configuration:
        realms/acme-corp.json:

results in: Error: YAML parse error on keycloak/templates/keycloak-config-cli-configmap.yaml: error converting YAML to JSON: yaml: line 13: did not find expected key

the same file converted to YAML

keycloakConfigCli:
    configuration:
        realms/acme-corp.yaml:

gives me: MountVolume.SetUp failed for volume "config-volume" : object "mynamespace"/"mykeycloak-keycloak-config-cli-configmap" not registered

If I just past the content of the realm config as in one of the examples provided, I get the following error:

keycloakConfigCli:
    configuration:
        realms/acme-corp.json: |
            {
                ...
            }

COMBINED OUTPUT: Error: UPGRADE FAILED: cannot patch "mykeycloak-keycloak-config-cli-configmap" with kind ConfigMap: ConfigMap "mykeycloak-keycloak-config-cli-configmap" is invalid: data[realms/acme-corp.json]: Invalid value: "realms/acme-corp.json": a valid config key must consist of alphanumeric characters, '-', '_' or '.' (e.g. 'key.name', or 'KEY_NAME', or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+')

Are you using any custom parameters or values?

keycloakConfigCli:
    enabled: true

so that I can set the realm configuration further below

What is the expected behavior?

Keycloak would get deployed to Kubernetes cluster without errors and the realms correctly configured.

What do you see instead?

The respective error messages provided in the description.

Additional information

No response

werwuifi commented 2 years ago

Actually the 3rd option with pasting the content now works. My mistake was I put the whole path there (realms/...) instead of just a file name. However it would be more convenient to have the config in external JSON files than pasting thousands lines of code.

javsalgar commented 2 years ago

Hi,

Did you try with the existingConfigMap value?

  ## @param keycloakConfigCli.existingConfigmap ConfigMap with keycloak-config-cli configuration. This will override `keycloakConfigCli.config`
  ## NOTE: This will override keycloakConfigCli.configuration
  ##
  existingConfigmap: ""
thowimmer commented 2 years ago

Hi @werwuifi & @javsalgar,

I can confirm that the configuration via existingConfigmap is working as expected.

This is how you can configure Keycloak with some config files in your Helm chart:

Chart structure

keycloak
  charts                    -> the actual keycloak helm chart is added as a dependency for this chart
    keycloak-7.1.14.tgz
  keycloak-config           -> config directory for Keycloak config files
    some-realm-config.json
  templates
    configmap.yaml          -> configmap for the existingConfigmap value of the Keycloak chart
  values.yaml
  Chart.yaml

Chart.yaml

apiVersion: v2
name: keycloak
description: A Helm chart for the Keycloak instance
type: application
version: 0.0.1

dependencies:
  - name: keycloak
    version: 7.1.14
    repository: https://charts.bitnami.com/bitnami

configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: keycloak-config
data:
{{ (.Files.Glob "keycloak-config/*").AsConfig | indent 2 }}

values.yaml

...
keycloak:
  ...
  keycloakConfigCli:
    enabled: true
    existingConfigmap: "keycloak-config"
  ...
javsalgar commented 2 years ago

Thanks for letting us know!

werwuifi commented 2 years ago

Thank you all for your help, all is working now as expected :) Closing the issue ...