garethr / garethr-kubernetes

Puppet types and provider for managing Pods, ReplicationControllers, Services and more in Kubernetes
http://garethr.github.io/garethr-kubernetes
Apache License 2.0
28 stars 28 forks source link

Exception when using resources with camelcase properties #25

Closed teintuc closed 7 years ago

teintuc commented 7 years ago

When applying Kubernetes_Deployment resource:

kubernetes_deployment { 'deployment':
  ensure => present,
  apiVersion => 'extensions/v1beta1',
  metadata => {
    name => 'deployment',
    namespace => 'deployment',
    labels => {
      'app' => 'deployment'
    },
  },
  spec => {
    replicas => 1,
    selector => {
      'app' => 'deployment'
    },
    template => {
      'metadata' => {
        'name' => 'deployment',
        'labels' => {
          'app' => 'deployment'
        }
      },
      'spec' => {
        'containers' => []
      }
    }
  }
 }

It produces the following error:

Error: no parameter named 'apiVersion' at /etc/puppetlabs/code/environments/production/addons/hello-world.pp:24 on Kubernetes_deployment[hello-world] at /etc/puppetlabs/code/environments/production/addons/hello-world.pp:24 on node [puppet master server]
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource.rb:578:in `validate_parameter'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:371:in `block in validate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:371:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:371:in `validate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:119:in `finish'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:687:in `block in finish'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:675:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:675:in `finish'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:193:in `block (2 levels) in compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:193:in `block in compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/context.rb:65:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb:241:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:162:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:33:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:266:in `block (2 levels) in compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:264:in `block in compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:223:in `block in benchmark'
/opt/puppetlabs/puppet/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:222:in `benchmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:262:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:53:in `find'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/indirection.rb:194:in `find'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:256:in `block in main'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/context.rb:65:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb:241:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:225:in `main'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application/apply.rb:170:in `run_command'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:344:in `block in run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:540:in `exit_on_fail'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/application.rb:344:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:132:in `run'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/command_line.rb:72:in `execute'
/opt/puppetlabs/puppet/bin/puppet:5:in `<main>'

The reason seems to come from puppet. A property name with an upper case letter is internally transformed to a snake case name at creation, but during property lookup it's missing the lower case operation and puppet can't find the property.

Changing manually the property to api_version makes it work for puppet but, of course, not for kubernetes. Might be the same problem with Kubernetes_Secrets on 'stringData' parameter.

The fix would be to camel case parameter's name when generating with swagger and snake case parameter's name when building the kubernetes api request.

masterzen commented 7 years ago

I've created PUP-7140 for the upstream issue.

masterzen commented 7 years ago

Note: from what I understood from the kubeclient code and thepuppet-swagger-generator code, apiVersion (and kind FWIW) shouldn't be properties of the types, as they are managed by kubeclient automatically.

This is tracked by garethr/puppet-swagger-generator#8.