puppetlabs-postgresql
puppetlabs-postgresql copied to clipboard
Dependency cycle when `postgresql::globals::encoding` is set
Describe the Bug
While upgrading the module from 9.1.0 to 10.5.0 we ran into the issue of a dependency cycle, when setting a value for postgresql::globals::encoding.
Info: Applying configuration version '*****.puppetserver01-atm_10130-1e601b89123d47539e44cf03bd0dce23a8d9a166'
Error: Found 1 dependency cycle:
(Anchor[postgresql::server::service::begin::main] => Postgresql_psql[Set template1 encoding to UTF-8] => Postgresql::Server::Instance::Late_initdb[main] => Postgresql::Server::Instance::Initdb[main] => Postgresql_conf[port_for_instance_main] => Postgresql::Server::Instance::Service[main] => Anchor[postgresql::server::service::begin::main])
Expected Behavior
No dependency cycle.
Steps to Reproduce (hiera)
---
classes:
- postgresql::server
postgresql::globals::encoding: 'UTF-8'
Steps to Reproduce (docker)
docker run -it --rm ubuntu:22.04 bash
apt-get update
apt-get install -y wget
wget https://apt.puppetlabs.com/puppet-release-jammy.deb
dpkg -i puppet-release-jammy.deb
apt-get update
apt-get install -y puppet-agent
/opt/puppetlabs/bin/puppet module install puppetlabs-postgresql
/opt/puppetlabs/bin/puppet apply -e "
class { 'postgresql::globals': encoding => 'UTF-8', }
class { 'postgresql::server': }
"
Environment
- Module version 10.5.0
- Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04
Additional Context
Removing the value will compile and apply successful.
Same as #1543?
Seems to be the same with the little difference they are setting encoding via Class postgresql::server. I am setting it via postgresql::server::globals.
Using the parameter postgresql::server::encoding works on our nodes, but it does not work with the same classes in our rspec tests, which is extremly strange.
Anyways - it has to work also with postgresql::globals::encoding on nodes and rspec. I tried to check which dependency could cause the problem. But I find it very hard since there are so many difference dependencies set in different files.
Added Steps to Reproduce (docker) to the initial post.
And while testing the steps from Steps to Reproduce (docker) with a changed command it still fails with a dependency cycle.
/opt/puppetlabs/bin/puppet apply -e "class { 'postgresql::server': encoding => 'UTF-8', }"
root@4eea8d3588b3:/# /opt/puppetlabs/bin/puppet apply -e "class { 'postgresql::server': encoding => 'UTF-8', }"
Notice: Compiled catalog for 4eea8d3588b3 in environment production in 0.09 seconds
Error: Found 1 dependency cycle:
(Anchor[postgresql::server::service::begin::main] => Postgresql_psql[Set template1 encoding to UTF-8] => Postgresql::Server::Instance::Late_initdb[main] => Postgresql::Server::Instance::Initdb[main] => Postgresql_conf[port_for_instance_main] => Postgresql::Server::Instance::Service[main] => Anchor[postgresql::server::service::begin::main])\nTry the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
Error: Failed to apply catalog: One or more resource dependency cycles detected in graph
Very very odd.
Well I think I found the issue - it is at https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/manifests/server/instance/late_initdb.pp#L46 and https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/lib/puppet/type/postgresql_psql.rb#L137
postgresql_psql { "Set template1 encoding to ${encoding}": is set to but run before Anchor["postgresql::server::service::end::${name}"], but in type there is a autorequire set to the same resource.
Thats the actual dependency cycle. I will test this.
Commenting out https://github.com/puppetlabs/puppetlabs-postgresql/blob/main/manifests/server/instance/late_initdb.pp#L46 does NOT fix the issue.
The depedency cycle still happens for me if using the latest state of main.
As deeper I get into the modules code as more confused I am getting...
Running into the same issue myself in our environment. After removing postgresql::globals::encoding it works. @crazymind1337 were you able to find out more?
Sadly I had no more time to investigate. But I think this module requires some general refactoring including the removal of those anchors. Again sadly I have no time for that.
this seems like its probably related to https://github.com/puppetlabs/puppetlabs-postgresql/pull/1564