Just recently I was looking at the environments part of puppet implementation, and I have stumbled upon this curious gimmick.
There is Puppet::Environments class, which is a class for general Environments management (searching, loaders, caching, etc).
Then there is Puppet::Node::Environment which is instantiated for every environent found. Logical up to this point.
But, contrary to all OOP notions, get_conf() function is not a method of Puppet::Node::Environment class.
Rather, it is a lookup function in Puppet::Environments class which takes environment name as an argument and fetches Puppet::Settings::EnvironmentConf instance.
Puppet::Environments has two function for environment and environment data retrieval:
- get() fetches Puppet::Node::Environment instance
- get_conf() fetches Puppet::Settings::EnvironmentConf instance
The curious thing is:
- get() method operates with cache
- get_conf() does not include any caching
I tested this on a catalog of 1633 resources, and:
- get() was called around 220 times
- get_conf() was called around 25.000 times
These are the comments above get_conf() in environments.rb:
# This implementation evicts the cache, and always gets the current
# configuration of the environment
#
# TODO: While this is wasteful since it
# needs to go on a search for the conf, it is too disruptive to optimize
# this.
My questions are:
- why does get_conf() method belong to Environments instead of Node::Environment class?
- why are get_conf() results not cached? Why is it "too disruptive"?
Thanks for answers,
b.