Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: per-chart helm configuration #310

Merged
merged 10 commits into from
Jun 13, 2024

Conversation

Zebradil
Copy link
Member

@Zebradil Zebradil commented Jun 9, 2024

This PR adds per-chart Helm configuration, resolving #261.

There is a new helm.charts subsection in the configuration schema:

helm:
  #! ...

  #! Per-chart configuration. Values override the global configuration.
  #! The `name` field is used to match the chart in the `charts` directory.
  #! The list is used instead of a map due to a limitation in ytt schema spec.
  #! See https://github.com/carvel-dev/ytt/issues/656 for more information.
  #@schema/validation ("chart names must be unique", lambda x: len(set([c["name"] for c in x])) == len(x))
  charts:
    - buildDependencies: false
      includeCRDs: false
      #@schema/validation min_len=1
      name: ""
      namespace: ""
      releaseName: ""

It's a list of per-chart overrides of the common options under the helm key in the config.
Selecting the chart-specific configuration is done via matching the name field with the chart's base name. For example, if a chart's path defined in the vendir config is charts/CHART_NAME, then CHART_NAME is the name of the chart and is used for selecting the options overrides.

@Zebradil Zebradil linked an issue Jun 9, 2024 that may be closed by this pull request
@Zebradil Zebradil requested review from kbudde and fritzduchardt June 9, 2024 19:10
@Zebradil Zebradil marked this pull request as ready for review June 9, 2024 20:45
@fritzduchardt
Copy link
Collaborator

fritzduchardt commented Jun 10, 2024

Hi @Zebradil , while testing this, I conceived an app-data.ytt.yaml that would currently fail:

#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
helm:
  namespace: monitoring
  charts:
    - buildDependencies: true
      name: "kube-prometheus-stack"
    - buildDependencies: false
      name: "kube-prometheus-stack-exporter"
application:
  namespace:
    create: true

It would lead to the following error:

Invalid schema - wrong number of items in array definition
==========================================================

data-schema.ytt.yaml:
      |
  108 |   charts:
      |

      = found: 2 array items
      = expected: exactly 1 array item, of the desired type

Is this a case you have considered?

@Zebradil
Copy link
Member Author

Hi @fritzduchardt, thanks for testing!

It is a bug, and a new test case. I'll implement it shortly.

@Zebradil
Copy link
Member Author

@fritzduchardt it turns out that it's not a bug, but a limitation of ytt. You can't define default values for arrays like that in a ytt schema file (#@data/values-schema). You have to either use a data file (#@data/values) or use annotations in the schema file:

#@ def charts():
- name: render-test-1
  releaseName: overriden-release-name-1
- name: render-test-2
  releaseName: overriden-release-name-2
#@ end

#@data/values-schema
---
helm:
  #@schema/default charts()
  #@overlay/replace
  #@schema/validation ("chart names must be unique", lambda x: len(set([c["name"] for c in x])) == len(x))
  charts:
    - buildDependencies: false
      includeCRDs: false
      #@schema/validation min_len=1
      name: ""
      namespace: ""
      releaseName: ""

The latter I find very inconvenient, because you have to copy the original array item definition, as well as the validation annotations.

@fritzduchardt
Copy link
Collaborator

The latter I find very inconvenient, because you have to copy the original array item definition, as well as the validation annotations.

Nice workaround! Since you also do validation in config_helm.go, I guess the validations are not strictly required.

}

chartConfigs := map[string]HelmChartOverride{}
for i, chart := range helmConfigWrapper.Helm.Charts {
Copy link
Collaborator

@fritzduchardt fritzduchardt Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also validate for charts being part of the config, but not of the actual app. Of course, this would lead to a lot of errors/warnings, if you define your chart-specific configuration in the env-data.ytt.yaml. Nevertheless, this feature seems more likely to be used in the app-data.ytt.yaml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an interesting idea. I think we can give it a try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented. This is how it looks like.

image

Currently, there is no central place for config validation (and it will require significant changes to the overall program structure to implement it), this is why it is duplicated in the sync and render steps and printed twice. But I think we can live with that :-)

Later, if these warnings are too annoying, we can add a switch to disable it.

@Zebradil
Copy link
Member Author

Since you also do validation in config_helm.go, I guess the validations are not strictly required.

That's right. However, ytt validations give better error message, in my opinion. But of course, it is completely up to the user :-)

@Zebradil Zebradil merged commit 68ffd4a into main Jun 13, 2024
5 checks passed
@Zebradil Zebradil deleted the 261-feat-implement-per-chart-configuration branch June 13, 2024 14:22
Zebradil added a commit that referenced this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] Implement per-chart configuration
2 participants