instrumenta / kubeval

Validate your Kubernetes configuration files, supports multiple Kubernetes versions
https://kubeval.com
Other
3.16k stars 229 forks source link

Witout TTY docker on CI #36

Closed albertoig closed 6 years ago

albertoig commented 6 years ago

I am triying to use kubeval on docker without TTY to validate YML on CI but give me this error "The document stdin appears to be empty". How i can use it without TTY?

garethr commented 6 years ago

Hi @albertoig could you post an example of the command you're running? I'll try and recreate.

albertoig commented 6 years ago

Hi!

I am using Gitlab CI with some pipelines to deploy a project. I think is interesting to validate my YML kubernetes files with Kubeval. I execute on a pipeline this thing like this:

yaml-validator: stage: doctor image: garethr/kubeval tags:

If a execute on terminal it work because the docker commmand use TTY, but gitlab CI does not. Why the kubeval have to be TTY?

captura de pantalla 2017-11-23 a las 17 17 59

johscheuer commented 6 years ago

@albertoig I solved this issue by running kubeval with script e.g.script -q -e -c "kubeval -v 1.8.1 ./deploy/*"

xanonid commented 6 years ago

@albertoig @johscheuer You can also redirect stdin from /dev/null: kubeval *.yaml < /dev/null

Tombar commented 6 years ago

FTR the same thing happens when using kubeval in the context of an ansible template validation

    - name: setup-k8s | template image pull secret
      template:
        src: k8s/image-pull-secret.yml.j2
        dest: "{{ deploy_dir }}/010-image-pull-secret.yml"
        validate: '/usr/bin/kubeval %s'
      tags: k8s-tasks
TASK [setup-k8s | template image pull secret] ****************************************************************************************************************
Tuesday 06 March 2018  03:13:00 +0000 (0:00:01.031)       0:00:10.130 *********
fatal: [localhost]: FAILED! => {"changed": false, "checksum": "28a4d034ca2f8202789bb7e0ac11439c06fa0ff1", "exit_status": 1, "msg": "failed to validate", "stderr": "", "stderr_lines": [], "stdout": "***PRINTED BY CALLBACK***", "stdout_lines": "***PRINTED BY CALLBACK***"}

stdout: The document stdin appears to be empty

the script -q -e -c workaround seems to work only for some cases where the < /dev/null doesn't work in any scenario

Neirda24 commented 6 years ago

Having the same trouble here.... :/ can't find a way around so far...

I am using kubeval like this:

unalias kubeval 2> /dev/null > /dev/null || true
kubeval() {
    docker run \
        --rm \
        -v "${CURRENT_DIR}/.fixtures:/temp_kubeval/.fixtures" \
        -w "/temp_kubeval" \
        garethr/kubeval $*
}
export -f kubeval

then:

kubeval "./.fixtures/${PROJECT_NAME}/*" --strict
Neirda24 commented 6 years ago

@garethr : Hi, we greatly appreciate your work on this. It helps us a lot when debugging helm on local with no access to a kubernetes cluster. We'd like to use it in our CI as well (gitlab-ci) (see the above post). Do you have any news on this bug ?

iomv commented 6 years ago

Hi, I am having the same issue here, we are using TeamCity CI to spin up a linux box and I pass a list of paths to kubeval: kubeval -v $K8S_VERSION -f $FILES_LIST_DEV it works locally on my machine but on the build agent I get: The document 01_deploy.yml appears to be empty

None of the workarounds above works for my case unfortunately.

Might come useful to specify that I copy the app from source and I install the binary while on #40 seems to imply that it might work when building from docker?

keegancsmith commented 6 years ago

This is an issue with how kubeval decides to use STDIN vs reading files from arguments. You can very easily reproduce with the docker image provided

docker run --rm=true --entrypoint=/bin/sh -v `pwd`/fixtures:/fixtures garethr/kubeval:0.7.1 -c 'find /fixtures | xargs /kubeval'

I don't know why kubeval checks stdin's mode to decide to use stdin. Every other tool I know of just uses stdin if no args are provided or have - mean stdin.

https://github.com/garethr/kubeval/blob/master/cmd/root.go#L42-L43