Open pedrorochagoncalves opened 5 years ago
The composite namevar does seem to make sense here.
For not finding them, could list_instances_of
be omitting the namespace? Then they wouldn't match because the composite namevar is used for matching.
Could absent
be introduced somehow because your else clause includes namespace => $namespace
and $namespace
is undef? What particular code does line 27 correspond to?
I suspect the auto-generation needs an update to account for namespaces across all resources.
@MikaelSmith , thank you very much for taking the time to read my wall of text and helping!
So, I checked what kubeclient returns and it seems to be returning the namespace as expected. Example:
#<Kubeclient::Resource metadata={:name=>"te-docker-reg", :namespace=>"ops", :selfLink=>"/api/v1/namespaces/ops/secrets/te-docker-reg", :uid=>"<some_id>", :resourceVersion=>"311", :creationTimestamp=>"2018-12-13T16:57:40Z"}, data={:".dockerconfigjson"=>"some_base64_stuff"}....
And actually, I printed the content of the variable hash
inside the self.instances (lib/puppet_x/swagger/provider.rb
):
def self.instances
begin
list_instances.collect do |instance|
begin
hash = instance_to_hash(instance)
Puppet.debug("Ignoring #{name} due to invalid or incomplete response") unless hash
new(hash) if hash
end
end.compact
rescue Timeout::Error, StandardError => e
raise PuppetX::Puppetlabs::Swagger::PrefetchError.new(self.resource_type.name.to_s, e)
end
end
and it seems to be populating the fields in the hash according to what is defined in lib/puppet/provider/kubernetes_secret/swagger.rb
inside self.instance_to_hash
(as posted in the original post) as expected:
Info: Hash: {:ensure=>:present, :name=>"te-docker-reg", :namespace=>"ops", :metadata=>{:name=>"te-docker-reg", :namespace=>"ops", :selfLink=>"/api/v1/namespaces/ops/secrets/te-docker-reg", :uid=>"<some_uid>", :resourceVersion=>"311", :creationTimestamp=>"2018-12-13T16:57:40Z"}, :data=>{:".dockerconfigjson"=>"<base64_stuff>"....}
But then the @property_hash variable is empty it seems.
As regards the absent
, thank you for pointing out a bug. You're right that the $namespace
variable inside the else clause is undef and I've fixed that! 👍 Unfortunately, however, the errors I posted above seem to happen only for the secrets that go in the if
clause and not the else clause. The secrets that go in the else clause seem to be working just fine and they are matched. Which makes that error even more of a mystery to me. Line 27 corresponds to: kubernetes_secret { "${secretname}-${namespace}":
, which is the first line of:
kubernetes_secret { "${secretname}-${namespace}":
ensure => $secret['ensure'],
name => $secretname,
namespace => $namespace,
metadata => $metadata,
data => $secret['data'],
type => $secret['type']
}
Once again, thank you for your time and patience!
Could it be referring to a namespace that doesn't exist? I don't really have a lot of ideas.
Based on what I've seen, I don't think that it's referring to a non-existing namespace. I was printing the namespaces during execution and they were all existing namespaces.
I don't have more ideas either unfortunately... Anyway, I really appreciate your help!
Hey,
First of all I wanted to thank you very much for having created this module, it's very useful and I've been using it at the company I work for.
We seem to have struck a small issue and I wanted to request your help and opinion. It would be great if we could add the same secret, with the same content and name, to multiple namespaces. So initially we had the following manifest:
Suppose we have the following hash in hiera for the secrets we want to add:
The second secret,
web-tls-dhparam
, will be created and managed just fine. We only manage it in one namespace, so the resulting Puppet resource would look like this:The first secret, docker_reg, which needs to be created with the same name on all namespaces is where this gets tricky. These are the resulting Puppet resources:
The issue is that the kubernetes_secret provider/type uses the content of the name variable (which is the same as the title of the resource in this case) to name the secret instead of what is inside
metadata.name
. So, Puppet will attempt to create 3 secrets calleddocker-reg-namespace1, docker-reg-namespace2 and docker-reg-namespac3
on namespace1, namespace2 and namespace3 respectively. But what we want, is a secret calleddocker-reg
on all three namespaces. And we can't change the content of thename
param, because it needs to match thetitle
.I'm a complete noob in Puppet custom resources, providers, types, etc. But I tried to hack around a little bit because I really wanted this to work. I started reading and found about composite namevars, which sounded exactly like what I needed to fix this. So I dove into the code and added the following:
(I'm aware these files are auto generated by puppet-swagger-generator, but I still wanted to hack around).
Having a composite namevar would allow me to change the Puppet code to the following:
Aha! So now for the
docker-reg
secret case that needs to exist in all namespaces, we can have the name parameter be the same for all three, because the resource now has a composite namevar:This works....partially. And this is the part where things are very fuzzy for me. 😀
In this scenario the secrets already exist in all namespaces. Puppet can't seem to find them (the exists info was added by me to check the content of
@property_hash
). I can see them being returned in the self.instances function of the provider, but I have no clue why the@property_hash
is empty for them. I'm also clueless about the error above. Where is it getting theabsent
namespace from? I have no idea how to debug that.Interestingly though, this does work just fine for the other secret that doesn't need to exist in all namespaces, which confuses me further. 😄
I was wondering if you could help me figure out what's going on and would like to hear your opinion. I realize the files I changed are auto generated, so maybe you have a much better idea on how to tackle this use case, to allow us to deploy the same secret with the same secret name to multiple namespaces. I apologize for the wall of text but I wanted to give you as much information as possible.
Thank you and I look forward to hearing back from you.
Cheers,