puppetlabs / puppetlabs-node_manager

Create and manage PE node groups as resources.
Apache License 2.0
10 stars 21 forks source link

Can't remove pinned nodes from a group #26

Closed Sharpie closed 7 years ago

Sharpie commented 7 years ago

Tried applying the following:

node_group { 'PE ActiveMQ Broker':
  ensure               => 'present',
  classes              => {'puppet_enterprise::profile::amq::broker' => {}},
  environment          => 'production',
  override_environment => 'false',
  parent               => 'PE Infrastructure',
  rule                 => undef,
}

But no changes were made.

WhatsARanjit commented 7 years ago

So here's what I'm finding. If you try and do rule => undef or rule => [], Puppet ends up ignoring this input at all. For the first level, the type has to take the input and hand off to the provider correctly. I started with this:

  newproperty(:rule, :array_matching => :all) do
    desc 'Match conditions for this group'
      require 'pry'; binding.pry
  end

So what I found is that if you specify rule => [] , pry doesn't even fire. Meaning Puppet isn't considering there is an input to work with (basically an undef). If you specify rule => '', it does fire. This something to work with.

WhatsARanjit commented 7 years ago

So on the provider level, if you input rule => '', it mostly works. The API wants { rule => nil } in order to remove all rules. Working with nil inside of the provider's methods doesn't seem like the right way to go. Puppet often doesn't consider nil as a value that matters so setters don't fire. I can swap this at the end durin the actual HTTP call.

  def update_group(data)
    data = Hash[data.map { |k,v| v == [''] ? [k,nil] : [k,v] }]
    ...

This is kind of unknown to Puppet. It thinks it's dealing with [''] as the value and reports as such. Last, updating the getter to report the nil value from the API as [''] so it is idempotent.

  def rule
    @property_hash[:rule].nil? ? [''] : @property_hash[:rule]
  end
WhatsARanjit commented 7 years ago

Merged https://github.com/WhatsARanjit/prosvcs-node_manager/pull/30