Code Monkey home page Code Monkey logo

helm-datree's Introduction

Datree Helm Plugin

A Helm plugin to validate charts against the Datree policy

Installation

helm plugin install https://github.com/datreeio/helm-datree

⚠️ Helm plugins are not supported on Windows OS ⚠️
Windows users can work around this by using Helm under WSL

Update Datree's plugin version

helm plugin update datree

Uninstall

helm plugin uninstall datree

Usage

Trigger datree policy check via the helm CLI

helm datree test [CHART_DIRECTORY]

Passing arguments

If you need to pass helm arguments to your template, you will need to add -- before them:

helm datree test [CHART_DIRECTORY] -- --values values.yaml --set name=prod

Test files

By default, test files generated by Helm will be skipped. If you wish to include test files in your policy check, add the --include-tests flag:

helm datree test --include-tests [CHART_DIRECTORY]

Check plugin version

helm datree version

See help text

helm datree help

Using other helm command

Helm might be installed through other tooling like microk8s. The DATREE_HELM_COMMAND allows specifying a command to run helm (default: helm):

DATREE_HELM_COMMAND="microk8s helm3" helm datree test [CHART_DIRECTORY]

Testing multiple charts

If you have multiple charts inside a single directory, you can test all of them sequentially using the following script:

#!/bin/bash

path="${1:-.}"
final_exit_code=0

while read -r helmchart; do
	dir="$(dirname "$helmchart")"
    echo "*** Proceeding to test Helm chart: $helmchart ***"
	set +e
	helm datree test "$dir"
	exitcode=$?
	set -e
	if [ "$exitcode" -gt "$final_exit_code" ]; then
        final_exit_code="$exitcode"
    fi
    echo ""
done < <(find "$path" -type f -name 'Chart.y*ml')

if [ "$final_exit_code" = 0 ]; then
    echo "Success"
else
    echo "Violations found, returning exit code $final_exit_code"
fi
exit "$final_exit_code"

The script will run a policy check against all charts before exiting, and return 0 only if no violations were found in any of them.
This is useful for CI, to avoid the need to call datree test multiple times.

Examples

Basic usage

helm plugin install https://github.com/datreeio/helm-datree
git clone [email protected]:datreeio/examples.git
helm datree test examples/helm-chart/nginx

image

GitHub Workflow

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
    
env:
  DATREE_TOKEN: ${{ secrets.DATREE_TOKEN }} 

jobs:
  k8sPolicyCheck:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        
      - name: Run Datree Policy Check
        uses: datreeio/action-datree@main
        with:
          path: 'myChartDirectory'
          cliArguments: '--only-k8s-files'
          isHelmChart: true
          helmArguments: '--values values.yaml'

Troubleshooting

Error: plugin "datree" exited with error

This is actually expected behavior because it's raised by Helm itself every time a plugin returns a non-zero exit code.
Therefore, if you will run datree plugin on a Chart that will pass the policy check, it will return 0 as exit code, and you will not see this error.

K8s schema validation error

This error occurs when trying to scan Chart.yaml or values.yaml files instead of the chart directory.
Solution: Pass the helm chart directory path to Datree's CLI, instead of to the file itself:

  • Correct - helm datree test examples/helm-chart/nginx
  • Wrong - helm datree test examples/helm-chart/nginx/values.yaml

The policy check returns false-positive results

The best way to determine if a false-positive result is a bug or a true misconfiguration, is by rendering the Kubernetes manifest with helm and then checking it manually:

helm template [CHART_DIRECTORY]

If after eyeballing the rendered manifest you still suspect it's a bug, please open an issue.

helm-datree's People

Contributors

dimabru avatar geisterfurz007 avatar hadar-co avatar myishay avatar noaabarki avatar romanlab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

helm-datree's Issues

Does not work with Helm 3.6.2

Describe the bug
Plugin crashes with helm v3.6.2

To Reproduce

$ helm datree test . --values my-values.yaml
Error: plugin "datree" exited with error

Expected behavior
Datree should analyze the Helm template.

Desktop:

  • OS: MacOS 10.15.7

Datree plugin version (run helm datree verion):

  • Version: 0.1.763

Additional context

$ helm version
version.BuildInfo{Version:"v3.6.2", GitCommit:"ee407bdf364942bcb8e8c665f82e15aa28009b71", GitTreeState:"dirty", GoVersion:"go1.16.5"}

$ sw_vers  
ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H1217

$zsh --version
zsh 5.7.1 (x86_64-apple-darwin19.0)

helm datree test my-app/ doesn't work on Windows WSL

Describe the bug
command 'helm datree test my-test-app/'
gives the following error:
Error: unknown flag: --skip-tests
Error: plugin "datree" exited with error

To Reproduce
Steps to reproduce the behavior:

  1. Run command 'helm create my-test-app'
  2. Run command 'helm datree test my-test-app/'
  3. See error:
    Error: unknown flag: --skip-tests
    Error: plugin "datree" exited with error

Expected behavior
Output similar to datree test my-test-app.yaml (helm template my-test-app/ > my-test-app.yaml; datree test my-test-app.yaml)

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • OS: Windows WSL2 Ubuntu

Datree plugin version (run helm datree verion):

  • Version: 1.8.27

Additional context
Add any other context about the problem here.

Passing in values file with -f flag

Describe the solution you'd like
Is it currently possible to pass in values files with a -f flag? This is something I'd like to be able to do.

Installation sometimes fails in Travis CI

Describe the bug
I'm running datree in Travis CI using the helm plugin, installing it on every CI run.
helm plugin install https://github.com/datreeio/helm-datree
The installation fails about 1 out of 3 times, which stops my CI and fails my build.

To Reproduce

  1. Run helm plugin install https://github.com/datreeio/helm-datree in Travis CI (might work locally as well)
  2. The CI sometimes fails to install

Expected behavior
Installation should work and CI continue

Screenshots
Screen Shot 2022-03-31 at 13 25 44

Desktop (please complete the following information):

  • OS: Travis CI, Ubuntu Trusty (in travis.yaml dist: trusty)

Datree plugin version (run helm datree verion):

  • Version: 1.1.10 (happens in other versions)

Additional context
This may have nothing to do with Travis CI, but rather with the github servers.

Allow use with other installations of helm

Is your feature request related to a problem? Please describe.

I am using the helm3 plugin/addon of microk8s which is run using microk8s helm3; for easier personal use I just aliased that to helm but run.sh doesn't pick that up causing the datree plugin to not compile the chart which in turn causes a "No files detected" error since this line (specifically helm show chart) fails as the command isn't known:

elif [[ $helm_chart_location == "" && $(helm show chart $1 2> /dev/null | grep apiVersion) == apiVersion* ]]; then

Describe the solution you'd like

Some flag / env variable for the script to provide an alternative path / way of calling helm to allow executing helm that is prebundled with other tools and thus requires a different command to run.

Describe alternatives you've considered

  • Modifying the installed run.sh file to include the alias at the top of the file locally
  • Dropping a helm executable somewhere in the path that essentially serves as the alias

Additional context
-

ignore chart dependencies

Is your feature request related to a problem? Please describe.
Today, if I will ran datree to test a chart with dependencies (that are not installed), I will get the following error message:
Error: An error occurred while checking for chart dependencies. You may need to run 'helm dependency build' to fetch missing dependencies: found in Chart.yaml, but missing in charts/ directory [CHART_NAME]
image

Describe the solution you'd like
A flag to skip pre-installed dependencies requirement: helm datree test [CHART_DIRECTORY] --ignore-dependencies
--ignore-dependencies -> this flag is just an example.

Describe alternatives you've considered
Comment out dependencies section from Chart:
image

Additional context

  • Default behavior - include testing dependencies
  • If missing dependencies message is raised - suggest the user to use the flag

Does not work with helm v3.5.2

helm datree test . --values values.yaml        
Error: plugin "datree" exited with error
datree version  
0.1.708
helm version                           
version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"clean", GoVersion:"go1.15.7"}

Add pre-commit-hooks feature for helm-datree

Is your feature request related to a problem? Please describe.
I would not want to commit to the repos every time I work with fixing the policies. So pre-commit-hooks are useful to Helm Charts users

Describe the solution you'd like
It would be nice to have pre-commit hooks feature as well for the Helm Chart users.

Something like this:

  • id: install-datree
    name: datree helm install
    description: Run Helm charts against the datree policy
    require_serial: true
    pass_filenames: true
    entry: scripts/install.sh
    language: script
    files: [file, yaml]

  • id: run-datree
    name: datree helm test
    description: Run Helm charts against the datree policy
    require_serial: true
    pass_filenames: true
    entry: scripts/run.sh
    language: script
    files: [file, yaml]

Thank you!

Can't install plugin in Gitlab CI with alpine/helm image

Describe the bug
When trying to install the plugin in Gitlab CI with the alpine/helm, I get a failure.

To Reproduce
Steps to reproduce the behavior:

  1. Run this script in Gitlab CI (truncated for privacy reasons)
stages:
  - test

test:
  stage: test
  image:
    name: alpine/helm:3.7.2
    entrypoint: [""]
  variables:
    DATREE_TOKEN: XXXXXXXXXXXXXXXXXXXXX
    HELM_PLUGINS: ./.helm_plugins
  before_script:
    # Debugging pluging
    - helm plugin list # Should be empty
    # Install another plugin just to check
    - helm plugin install https://github.com/technosophos/helm-github
    - helm plugin list # Should list the helm-github plugin
    - helm plugin install https://github.com/datreeio/helm-datree
    - helm plugin list # Should list both pluging
  script:
    - ...
  1. See error sh: ./scripts/install.sh: not found

image

Expected behavior
The plugin should install

Datree plugin version (run helm datree verion):

  • Version: probably the latest at the time of writing.

CI/CD friendliness

An interesting tool overall!

I do not see a way to use it in a CI/CD env, unless I am missing the obvious.

It would be great if it had something along the lines of --quiet and --error-count, so that I could parse the result of helm datree test ... and find our if I need to fail the build or not. Currently this is very cumbersome to do (I get the output and parse it, which to put it mildly, simply sucks).

Thank you for looking into this.

Choose values file

I think need args "-f" to choose file values. Because my file values.yml not in the same folder chart.

Recursive test for helm validation

Is your feature request related to a problem? Please describe.
I want to run datree against a bunch of helm charts checked into a single repo. Everytime I add a new repo, I have to manually add in github actions / config to run it against a specific chart.

Describe the solution you'd like
I want to be able to recursively specify a master folder with helm charts against which I want to run datree. I am also fine to follow a certain convention of naming the custom values files or maintain a config file for this

Describe alternatives you've considered
Considering a script which user has to run which generates this and adds to the github actions. But don't want to add that capability to user

Additional context
Add any other context or screenshots about the feature request here.

Chart name contains spaces

If there are spaces in the title of the diagram, there will be an error

Chart.yaml

apiVersion: v2
name: Test Chart v2
description: A Helm chart for Kubernetes
❯ helm datree test ./ -- --values values.yaml --values values-test.yaml --set namespace=test
~/.local/share/helm/plugins/helm-datree/scripts/run.sh: line 34: $tempManifestPath: ambiguous redirect
Error: plugin "datree" exited with error

You should quote the variable $tempManifestPath

run.sh

helm template "${helm_options[@]}" "$helm_chart_location" > "$tempManifestPath"
$HELM_PLUGIN_DIR/bin/datree "${datree_options[@]}" "$tempManifestPath"

Problems finding k8s schema file

Describe the bug
Wanted to give datree a try, installed helm plugin to check on my charts. Yaml validation is OK, Kubernetes schema validation cannot find file. Tried with example repo, no luck.

To Reproduce
Steps to reproduce the behavior:

  1. helm plugin install https://github.com/datreeio/helm-datree
  2. git clone https://github.com/datreeio/examples.git
  3. helm datree test examples/helm-chart/nginx

Expected behavior
K8s schema is validated, starting policy check.

Screenshots
image

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • kernel: 5.11.0-41-generic
  • helm: version.BuildInfo{Version:"v3.7.0", GitCommit:"eeac83883cb4014fe60267ec6373570374ce770b", GitTreeState:"clean", GoVersion:"go1.16.8"} (installed by snap)

Datree plugin version (run helm datree verion):

  • Version: 0.14.49

Additional context
Same happens with passing values
helm datree test helm-charts/app/ -- --values compiled/DEV1/php.yml

Add helm flag --skip-tests by default

Is your feature request related to a problem? Please describe.
Helm template creates test resources, while helm install does not. This default behavior creates a discrepancy where the datree test fails on policy check on the test resources, while these resources are never applied.

Describe the solution you'd like

  1. By default, datree executes the test command with the usage of the flag --skip-tests
  2. Create a flag that allows users to execute datree test w/o having this flag (same as the behavior today)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.