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

Kap 09 #701

Merged
merged 12 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ before_install:
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 762E3157
# Loop until update succeeds (timeouts can occur)
- travis_retry $(! sudo apt-get -qq update 2>&1 | grep Failed)
- sudo apt-get install -y gnupg2 git
- sudo apt-get install -y golang-1.14
- export PATH="/usr/lib/go-1.14/bin:$PATH"
- export GOROOT=/usr/lib/go-1.14
- go version
- sudo apt-get install -y gnupg2 git curl
# Install Helm Binary
- curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
- chmod 700 get_helm.sh
- sudo ./get_helm.sh

install:
- pip3 install -r requirements.txt
- pip3 install coverage black

script:
- make build_helm_binding && make build_helm_fetch_binding
- make test && make test_coverage

after_success:
Expand Down
27 changes: 9 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
# First build the Helm binding
FROM golang:1.14.4-stretch AS helm-builder
# Build the virtualenv for Kapitan
FROM python:3.7-slim-stretch AS python-builder

RUN mkdir /kapitan
WORKDIR /kapitan

COPY ./kapitan/inputs/helm ./kapitan/inputs/helm
RUN chmod +x ./kapitan/inputs/helm/build.sh \
&& ./kapitan/inputs/helm/build.sh

COPY ./kapitan/dependency_manager/helm ./kapitan/dependency_manager/helm
RUN chmod +x ./kapitan/dependency_manager/helm/build.sh \
&& ./kapitan/dependency_manager/helm/build.sh

COPY ./kapitan ./kapitan
COPY ./MANIFEST.in ./MANIFEST.in
COPY ./requirements.txt ./requirements.txt
COPY ./setup.py ./setup.py

# Build the virtualenv for Kapitan
FROM python:3.7-slim-stretch AS python-builder

COPY --from=helm-builder /kapitan /kapitan
WORKDIR /kapitan

ENV PATH="/opt/venv/bin:${PATH}"

RUN apt-get update \
Expand All @@ -31,10 +17,15 @@ RUN apt-get update \
&& python -m venv /opt/venv \
&& pip install --upgrade pip yq wheel \
&& pip install -r requirements.txt \
&& ./kapitan/inputs/helm/build.sh \
&& ./kapitan/dependency_manager/helm/build.sh \
&& pip install .

# Install Helm
RUN apt-get install --no-install-recommends -y curl \
&& curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 \
Copy link
Contributor

@sebradloff sebradloff Mar 16, 2021

Choose a reason for hiding this comment

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

should we be pinning the version of helm3 that gets downloaded? I believe if I'm reading the get_helm.sh script correctly, we could technically set a DESIRED_VERSION to control the helm3 version being downloaded instead of defaulting to latest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_helm.sh supports --version flag. What would be the benefit of pinning the version ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like in general there are bug fixes here and there that happen with any software. I feel like since we directly depend on the helm binary and we have an "open" interface with helm_params it might be worth being methodical on upgrading versions. Just a thought, don't think it's required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The get_helm.sh script is design to fetch only v3 version. So, all updates should be backward compatible.

Just like this image is using latest python3.7, git or gnupg binaries, I don't think it should cause issues using the latest helm 3 release.

&& chmod 700 get_helm.sh \
&& HELM_INSTALL_DIR=/opt/venv/bin ./get_helm.sh --no-sudo \
&& rm get_helm.sh

# Final image with virtualenv built in previous step
FROM python:3.7-slim-stretch

Expand Down
33 changes: 11 additions & 22 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ FROM bitnami/jsonnet:0.14.0 as jsonnet-binary
# /bin/promtool
FROM quay.io/prometheus/prometheus:v2.15.2 AS prometheus-binary

# Build the Helm binding
FROM golang:1.14.4-stretch AS helm-builder

RUN mkdir /kapitan
WORKDIR /kapitan

COPY ./kapitan/inputs/helm ./kapitan/inputs/helm
RUN chmod +x ./kapitan/inputs/helm/build.sh \
&& ./kapitan/inputs/helm/build.sh

COPY ./kapitan/dependency_manager/helm ./kapitan/dependency_manager/helm
RUN chmod +x ./kapitan/dependency_manager/helm/build.sh \
&& ./kapitan/dependency_manager/helm/build.sh

COPY ./kapitan ./kapitan
COPY ./MANIFEST.in ./MANIFEST.in
COPY ./requirements.txt ./requirements.txt
COPY ./setup.py ./setup.py

# Build final image
FROM python:3.7-buster

Expand All @@ -37,7 +18,13 @@ COPY --from=terraform-binary /bin/terraform /usr/bin/terraform
COPY --from=jsonnet-binary /opt/bitnami/jsonnet/bin/jsonnet /usr/bin/jsonnet
COPY --from=jsonnet-binary /opt/bitnami/jsonnet/bin/jsonnetfmt /usr/bin/jsonnetfmt
COPY --from=prometheus-binary /bin/promtool /usr/bin/promtool
COPY --from=helm-builder /kapitan /kapitan

RUN mkdir /kapitan

COPY ./kapitan /kapitan/kapitan
COPY ./MANIFEST.in /kapitan/MANIFEST.in
COPY ./requirements.txt /kapitan/requirements.txt
COPY ./setup.py /kapitan/setup.py

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
Expand Down Expand Up @@ -72,10 +59,12 @@ RUN apt-get update \
&& python -m venv /opt/venv \
&& pip install --upgrade pip yq wheel \
&& pip install -r ./kapitan/requirements.txt \
&& ./kapitan/kapitan/inputs/helm/build.sh \
&& ./kapitan/kapitan/dependency_manager/helm/build.sh \
&& pip install ./kapitan \
&& rm -rf ./kapitan \
&& curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 \
&& chmod 700 get_helm.sh \
&& HELM_INSTALL_DIR=/opt/venv/bin ./get_helm.sh --no-sudo \
&& rm get_helm.sh \
&& curl -L -o /usr/local/bin/kapp ${KAPP_URL} \
&& chmod +x /usr/local/bin/kapp \
&& curl -L -o /usr/local/bin/kbld ${KBLD_URL} \
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ recursive-include kapitan/reclass/reclass/ *.py
include kapitan/lib/*.libjsonnet
include requirements.txt
recursive-include kapitan/inputs/templates *
recursive-include kapitan/inputs/helm *
recursive-include kapitan/dependency_manager/helm *
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ format_codestyle:
black .
@echo

.PHONY: build_helm_fetch_binding
build_helm_fetch_binding:
bash kapitan/dependency_manager/helm/build.sh

.PHONY: local_serve_documentation
local_serve_documentation:
docker build -f Dockerfile.docs --no-cache -t kapitan-docs .
Expand All @@ -66,4 +62,4 @@ local_serve_documentation:
.PHONY: mkdocs_gh_deploy
mkdocs_gh_deploy: # to run locally assuming git ssh access
docker build -f Dockerfile.docs --no-cache -t kapitan-docs .
docker run --rm -it -v $(PWD):/src -v ~/.ssh:/root/.ssh -w /src kapitan-docs gh-deploy -f ./mkdocs.yml
docker run --rm -it -v $(PWD):/src -v ~/.ssh:/root/.ssh -w /src kapitan-docs gh-deploy -f ./mkdocs.yml
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ boto3 = ">=1.17.101"
requests = "==2.25.0"
addict = "==2.2.1"
yamllint = ">=1.23.0"
cffi = "*"
rfc3987 = "==1.3.8"
hvac = "==0.10.5"
docker = "==4.3.1"
Expand Down
55 changes: 0 additions & 55 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 22 additions & 12 deletions docs/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ parameters:
helm_values_files:
- <values_file_path>
helm_params:
name: <chart_release_name>
namespace: <substitutes_.Release.Namespace>
name_template: <namespace_template>
release_name: <chart_release_name>
- name: add-metadata-test-1
input_type: kadet
output_path: ${test_1:output_path}
Expand Down Expand Up @@ -358,11 +357,13 @@ parameters:
<object_with_values_to_override>
helm_values_files:
- <values_file_path>
helm_path: <helm binary>
helm_params:
name: <chart_release_name>
namespace: <substitutes_.Release.Namespace>
name_template: <namespace_template>
release_name: <chart_release_name>
kube_version: <target_kubernetes_version_string>
output_file: <string>
validate: true
```

`helm_values` is an object containing values specified that will override the default values in the input chart. This has exactly the same effect as specifying `--values custom_values.yml` for `helm template` command where `custom_values.yml` structure mirrors that of `helm_values`.
Expand All @@ -372,21 +373,30 @@ If the same keys exist in `helm_values` and in multiple specified `helm_values_f
There is an example in the tests. The `monitoring-dev`(kapitan/tests/test_resources/inventory/targets/monitoring-dev.yml) and `monitoring-prd`(kapitan/tests/test_resources/inventory/targets/monitoring-prd.yml) targets both use the `monitoring`(tests/test_resources/inventory/classes/component/monitoring.yml) component.
This component has helm chart input and takes a `common.yml` helm_values file which is "shared" by any target that uses the component and it also takes a dynamically defined file based on a kapitan variable defined in the target.

`helm_params` correspond to the options for `helm template` as follows:
`helm_path` can be use to provide the helm binary name or path.
`helm_path` defaults to the value of `KAPITAN_HELM_PATH` env var if it is set, else it defaults to `helm`

- namespace: equivalent of `--namespace` option: note that due to the restriction on `helm template` command, specifying the namespace does not automatically add `metadata.namespace` property to the resources. Therefore, users are encourage to explicitly specify in all resources:
`helm_params` correspond to the flags for `helm template`. Most flags that helm supports can be used here by replacing '-' by '_' in the flag name.

Flags without argument must have a boolean value, all other flags require a string value.

Special flags:

- `name`: equivalent of helm template `[NAME]` parameter. Ignored if `name_template` is also specified. If neither `name_template` nor `name` are specified, the `--generate-name` flag is used to generate a name.
- `output_file`: name of the single file used to output all the generated resources. This is equivalent to call `helm template` without specifing output dir. If not specified, each resource is generated into a distinct file.

- `include_crds` and `skip_tests`: These flags are enabled by default and should be set to `false` to be removed.
- `debug`: prints the helm debug output in kapitan debug log.
- `namespace`: note that due to the restriction on `helm template` command, specifying the namespace does not automatically add `metadata.namespace` property to the resources. Therefore, users are encouraged to explicitly specify it in all resources:

```yaml
metadata:
namespace: {{ .Release.Namespace }} # or any other custom values
```

- name_template: equivalent of `--name-template` option
- release_name: equivalent of `--name` option

See the [helm doc](https://helm.sh/docs/helm/#helm-template) for further detail.
See the [helm doc](https://helm.sh/docs/helm/helm_template/) for further detail.

`kube_version` optionally specifies the Kubernetes version to target when rendering the manifests from the chart, for example "1.16". As some charts generate manifests slightly differently depending on the target Kubernetes version (e.g. targeting different APIs), it may be useful to target a specific version. When not specified, the default version used is "1.12".

#### Example

Expand Down Expand Up @@ -417,7 +427,7 @@ parameters:
image:
repository: custom_repo
helm_params:
release_name: my-first-release-name
name: my-first-release-name
namespace: my-first-namespace
```

Expand Down
12 changes: 7 additions & 5 deletions docs/external_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ Setting `unpack: True` will unpack zip or tar files onto the `output_path`. In s
## Helm type

Fetches helm charts and any specific subcharts in the `requirements.yaml` file.
Currently only works on linux with the `helm_fetch_binding`.

`helm_path` can be used to specify where the `helm` binary name or path.
It defaults to the value of the `KAPITAN_HELM_PATH` environment var or simply to `helm` if neither is set.
You should specify only if you don't want the default behavior.

### Usage

Expand All @@ -184,6 +187,7 @@ parameters:
source: http[s]://<helm_chart_repository_url>
version: <specific chart version>
chart_name: <name of chart>
helm_path: <helm binary>
```


Expand Down Expand Up @@ -213,8 +217,7 @@ parameters:
enabled: false
helm_params:
namespace: monitoring
name_template: prometheus
release_name: prometheus
name: prometheus
```

Then run:
Expand Down Expand Up @@ -266,8 +269,7 @@ parameters:
enabled: false
helm_params:
namespace: monitoring
name_template: prometheus
release_name: prometheus
name: prometheus
```

Then run:
Expand Down
Loading