Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis config file should be updated as needed (desired state) #478

Open
nicksma opened this issue Jul 18, 2023 · 1 comment
Open

redis config file should be updated as needed (desired state) #478

nicksma opened this issue Jul 18, 2023 · 1 comment

Comments

@nicksma
Copy link

nicksma commented Jul 18, 2023

The guard allows to set the redis configuration in the first run. Once the breadcrumb is written along with the configuration file, the config is never getting updated anymore. This is the case even while changing the address, the maxclients or any other parameter configurable by this provider.

not_if { ::File.exist?("#{current['configdir']}/#{server_name}.conf.breadcrumb") }

Solution could be, instead of defining the variables attributes inside the resource, we will fill a variable variables_to_be_set with these information. This variable will be used in the template resource later.
To check, if these variables have changed, we generate a hash and store the value in the breadcrumb file. With these information we are able to guard the template resource by checking if the breadcrumb file contains the fresh calculated hash. If not, we have to execute the template resource, which will write the changed configuration file.
In this case we need to update the breadcrumb file with the new hash, done by the file resource with the modified content and the action changed to create.

This is just a snippets to show the idea and needs to be fleshed out:

    variables_to_be_set = variables( 
      version: version_hash, 
      piddir: piddir, 
      ...
      repldisklesssync:           current['repldisklesssync'],
      repldisklesssyncdelay:      current['repldisklesssyncdelay'] 
    )

    config_hash = hash(variables_to_be_set)

    # Lay down the configuration files for the current instance
    template "#{current['configdir']}/#{server_name}.conf" do
      source node['redisio']['redis_config']['template_source']
      cookbook node['redisio']['redis_config']['template_cookbook']
      owner current['user']
      group current['group']
      mode current['permissions']
      action :create
      variables variables_to_be_set
      not_if { ::File.foreach("#{current['configdir']}/#{server_name}.conf.breadcrumb").grep(#{config_hash}).any? }}
    end

    file "#{current['configdir']}/#{server_name}.conf.breadcrumb" do
      content 'This file prevents the chef cookbook from overwriting the redis config if config has not changed. \nconfig_hash: #{config_hash}'
      action :create
      only_if { current['breadcrumb'] == true }
    end

Thank you for your excellent code and for maintaining it. :)

@simonasr
Copy link
Contributor

simonasr commented Aug 2, 2023

Hi, we solve similar problem using "includes" attribute which is used to include another config file to the initial configuration.
Settings in this included file overrides settings of the initial config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants