cloud66-oss / copper

A configuration file validator for Kubernetes.
https://help.cloud66.com/copper/
Apache License 2.0
274 stars 15 forks source link

basic example fails with (<unknown>): mapping values are not allowed in this context at line 11 column 22 (Psych::SyntaxError) #12

Closed carltonmason closed 5 years ago

carltonmason commented 5 years ago

Hi There!

I just installed ruby and copper on my mac to give this a try. I am using the basic example as described in https://copper.sh/ and I get the error shown below. Am I doing something wrong? Yes I am a ruby newbie...

Carltons-MacBook-Pro:rendered-armada.d ckmason$ cat cop-deploy.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    namespace: foobar
    name: foo
spec:
    template:
        spec:
            containers:
            - name: mysql
                image: index.docker.io/library/mysql:6.5.0
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$ cat my_rules.cop
rule NoLatest ensure {  // use of latest as image tag is not allowed
    fetch("$.spec.template.spec.containers..image")
        .as(:image)
        .pick(:tag)
        .contains("latest") == false
    }
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$ copper check --rules my_rules.cop --file cop-deploy.yaml
Validating part 0
Traceback (most recent call last):
    15: from /usr/local/lib/ruby/gems/2.5.0/bin/copper:23:in `<main>'
    14: from /usr/local/lib/ruby/gems/2.5.0/bin/copper:23:in `load'
    13: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:7:in `<top (required)>'
    12: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:121:in `<module:Copper>'
    11: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
    10: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
     9: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
     8: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
     7: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `check'
     6: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `each_with_index'
     5: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `each'
     4: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:75:in `block in check'
     3: from /usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:263:in `load'
     2: from /usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:350:in `parse'
     1: from /usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:402:in `parse_stream'
/usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:402:in `parse': (<unknown>): mapping values are not allowed in this context at line 11 column 22 (Psych::SyntaxError)
carltonmason commented 5 years ago

Ah, its a yaml formatting problem...

In the cop-deploy.yaml, the image element is indented to far.

So, it should be like this corrected snippet:

            - name: mysql
              image: index.docker.io/library/mysql:6.5.0

instead of:

            - name: mysql
                image: index.docker.io/library/mysql:6.5.0

Probably need to fix the formatting of this deploy.yml example code in https://copper.sh/ so others don't make the same mistake I did.

Feel free to close this issue.

Thanks

khash commented 5 years ago

Thank you @carltonmason Yaml and copy paste don't work very well and it might have been the issue copying the example into the docs. I will make sure it gets corrected.