From 9f04812bcf6781c0a90fdf7c29f2d989bb934909 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Wed, 17 Jan 2024 00:18:26 +0100 Subject: [PATCH] Update README --- README.md | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6435e5f..c6b0e9f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ mirrors: As you can see, it won't work on scale, so all the field can be templated using the chart data and a couple of helpers. ```yaml - - name: badhouseplants-git + - name: my-git-mirror git: url: git@git.badhouseplants.net:allanger/helmuled-charts.git branch: upgrade-{{ name }}-to-{{ version }} @@ -57,7 +57,7 @@ variables: git-msg: Hello there mirrors: - - name: badhouseplants-git + - name: my-git-mirror git: url: git@git.badhouseplants.net:allanger/helmuled-charts.git branch: upgrade-{{ name }}-to-{{ version }} @@ -99,6 +99,212 @@ These command are executed from the workdir. It's created during the run, and by Now, when we got our mirrors, we need to start mirroring. -...to be continued... +To mirror a chart you'll have to define repos first. You can choose between `helm` and `git` repos. +```yaml +repositories: + - name: db-operator + git: + url: https://github.com/db-operator/charts.git + ref: main + path: charts + - name: flux-community + helm: + url: https://fluxcd-community.github.io/helm-charts + - name: bitnami-oci + helm: + # it can be OCI too + url: oci://registry-1.docker.io/bitnamicharts/ +``` + +And then you need to start adding charts + +```yaml +charts: + # it should be the real chart name + - name: flux2 + # the name of the repo from the .repositories + repository: flux-community + # it will be latest if not provided, or you can fix it here + # + # but if you use git repos, it makes sense to always use latest + # becase in a git repo usually there is only one version + # of a chart, and you either need to guess it, or just fix it + # on the repo level, and use latest here + version: latest + mirrors: + - custom-command + - my-git-mirror + +``` + +Let's assume you've named this file `helmule.yaml`, and now it's time to test it. Execute the following +```bash +helmule -c helmule.yaml -d -w test +``` + +Also, `variables` can be defined per chart with `charts.[].variables` then they going to be merged with global ones + +It's going to create the `test` folder, where you'll be able to find both target repos and charts to be mirrored. If you're happy with the result, run it without `-d` and `-w test` to actually mirror. + +Until this moment, it looks exactly like a yet another helm chart mirroring solution, right? At least, it does to me. So let's walk through features. + +--- + +First one is `extensions` config property. +> Currently it will only cope files to your chart after it was pulled from the upstream. But later I plan to add an ability to use variables there, so one extension can more-or-less easily be reused between charts. + +Why would one need it? Well, me for example, in my clusters I use Istio as an ingress controller and db-operator to manage databases, and since usually charts are provided with `ingress` and obviously without `database` custom resources, I can't just use them without modifications. I don't want to modify manifests that are generated by helm, because of many reasons. So I need to have them in the helm chart. Since I'm using helmfile, I can add them as dependencies without forking charts, but it still not the perfect solution I guess. + +So, here come extensions. You can create a `VirtualService` and a `Database`, let's say you've created something like that: +``` +helmule.yaml +extensions + _helper.tpl + database.yaml + virtual-service.yaml +``` + +And then you can add it to you helmule config + +```yaml +charts: + - name: flux2 + repository: flux-community + version: latest + # Obviously, flux doesn't need any of those extensions, + # but it's just for a sake of example + extensions: + - name: Create a VirtualService and a Database + # Relative to the config + source_dir: ./extensions + # Relative to the chart root + target_dir: ./templates/extensions + mirrors: + - custom-command + - my-git-mirror +``` + +And if you run helmule now, you'll see additional resources added to the chart. + +> Extensions currently are always trying to create the dir that is defined as a `target_dir`, so if it exists, extension will fail. It will be fixed later, but currently that's what we've got + +--- + +The second feature is `patches`. Those are supposed to be modifications to helm chart that require more logic than just copy-paste. + +There are 4 kinds of patches at the moment. + +1. Regexp patch. This one will create a regexp and try to replace it with desired value. It's not checking if anything was actually changed though. It can be defined like that +```yaml +charts: + - name: flux2 + patches: + - name: Some regexp patch + regexp: + path: ./patch/to/patch +``` + +And the patch itself should also be a yaml file: + +```yaml +--- +name: Replace image with picture +targets: + - values.yaml +before: image +after: picture +``` + +It was the first kind of patch added, so it's more or less POC. I wouldn't recommend using it at this point, unless you're really sure what you are doing + +2. Git patch. You see "Git" here, but it doesn't mean that it's working only with git repos. What it's doing is it's initializing a git repo in the chart dir, and trying to apply a git patch you've provided. To create one, you could use a flag `--init-git-patch $CHART_NAME_1,$CHART_NAME_2`. Then helmule won't try to mirror charts that are listed under that flug, but it will init git repos in their root folders and prints paths to them, so you can go there, change something, execute `git diff > $CONFIG_DIR/chart.patch` and then add it to the config like that: + +```yaml +charts: + - name: flux2 + patches: + - name: Some git patch + git: + path: ./flux2.patch +``` + +3. Yq patch. It's just a helper for yq. +```yaml +charts: + - name: flux2 + patches: + - name: yq example + yq: + op: Add # or Replace, or Remove + key: .home # Just a yaml key (also can be .annotations."something.annotation") + value: localhost # A value to set, is not required if operation is Remove + files: Chart.yaml # A file that should be changed +``` + +4. CustomCommand patch. It's not really a patch, I'd say it can be anything you want. It will just execute commands from the root dir if a chart. Example: +```yaml + - name: yamlfmt + custom_command: + commands: + - "cat <> .yamlfmt\n formatter:\n pad_line_comments: 2\nEOT" + - yamlfmt values.yaml --conf ./yamlfmt.yaml + - rm -f yamlfmt.yaml +``` + +It's also possible to re-use patches by different charts. If you have a common patch, you can define it on the root level of you config: +```yaml +charts: {} +patches: + - name: yamlfmt + custom_command: + commands: + - "cat <> .yamlfmt\n formatter:\n pad_line_comments: 2\nEOT" + - yamlfmt values.yaml --conf ./yamlfmt.yaml + - rm -f yamlfmt.yaml +``` + +And then, if you define a patch with the name only for a chart, it's going to be taken from global patches + +```yaml +charts: + - name: flux2 + patches: + - name: yamlfmt +patches: + - name: yamlfmt + custom_command: + commands: + - "cat <> .yamlfmt\n formatter:\n pad_line_comments: 2\nEOT" + - yamlfmt values.yaml --conf ./yamlfmt.yaml + - rm -f yamlfmt.yaml +``` + +--- + +One last thing that is not described yet is the `include` property. It looks like that: +```yaml +include: + - kind Charts # Can also be Repositories and Mirrors, other properties will be includable later + path: ./charts.yaml +charts: {} +``` + +The included file will be marshalled into a vector of desired property. But the file that is included can contain either a list or just a single object, so both will work + +```yaml +# charts.yaml +name: flux2 +repository: flux-community +mirrors: + - my-git-mirror +``` + +```yaml +# charts.yaml +- name: flux2 + repository: flux-community + mirrors: + - my-git-mirror +```