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

remove resolved settings from config when changed to absent #429

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

TheMeier
Copy link
Contributor

@TheMeier TheMeier commented Mar 9, 2024

Pull Request (PR) description

When dns_stub_listener and dns_stub_listener_extra are changed from a value to undef they don't get removed from the config.

There is plenty more settings here that could use the same treatment I guess

This Pull Request (PR) fixes the following issues

Fixes #397

@TheMeier TheMeier added the enhancement New feature or request label Mar 9, 2024
@TheMeier TheMeier requested a review from traylenator March 9, 2024 15:14
@traylenator
Copy link
Contributor

The fear is that since undef is the default this is now an action.

It's probably okay with this parameter.

I always quite like yumrepo's explicit absent.

@TheMeier
Copy link
Contributor Author

The fear is that since undef is the default this is now an action.

It's probably okay with this parameter.

I always quite like yumrepo's explicit absent.

I see you point. I can't follow your comparison to yumrepo here. These are class parameters, yumrepo is more
There is a couple of ways we could handle this:

  • go with the path laid out in this MR and mark it breaking
  • implement more logic with a custom function that could look something like this:
    $_dns_stub_listener = $dns_stub_listener ? {
      true    => 'yes',
      false   => 'no',
      default => $dns_stub_listener,
    }
    
    if ($_dns_stub_listener) {
      ini_setting { 'dns_stub_listener':
        ensure  => new_function($_dns_stub_listener),
        value   => $_dns_stub_listener,
        setting => 'DNSStubListener',
        section => 'Resolve',
        path    => '/etc/systemd/resolved.conf',
        notify  => Service['systemd-resolved'],
      }
    }
    
  • embrace the breaking and do a major restructuring
    Remove all the
    if $manage_* {
      contain systemd::*
    }
    
    and change alle the subclasses marked @api private to be used directly by the user.
    This would have 2 benefits, less params in init.pp, move many test out of init_spec.rb
    That would be a drastic change, though. But I think it is worth considering.

@TheMeier
Copy link
Contributor Author

Not sure about the custom function. Isn't it just:

if $dns_stub_listener =~ NotUndef {
  ini_setting { '':
    ensure  => 'present',
    value   => $_dns_stub_listener,
    setting => 'DNSStubListener',
    section => 'Resolve',
    path    => '/etc/systemd/resolved.conf',
    notify  => Service['systemd-resolved'],
  }
}

i.e default remains as do nothing and set if set to which ever ?

But wasn't the whole point to find a way to set ensure => 'absent'. The idea was that one can set $dns_stub_listener == 'absent' and only in that case the ensure would be set to absent

@TheMeier TheMeier force-pushed the issues/397 branch 3 times, most recently from 56c41ad to bf96af3 Compare March 11, 2024 08:10
@TheMeier
Copy link
Contributor Author

@traylenator I have changed the code for an alternative solution... please have another look

@ekohl ekohl changed the title remove resovled settings from config when changed to undef remove resolved settings from config when changed to undef Mar 11, 2024
@TheMeier TheMeier requested a review from ekohl March 12, 2024 18:18
manifests/init.pp Outdated Show resolved Hide resolved
manifests/init.pp Outdated Show resolved Hide resolved
@TheMeier TheMeier force-pushed the issues/397 branch 2 times, most recently from 6d83293 to 14a42fe Compare March 12, 2024 18:42
@TheMeier TheMeier requested review from bastelfreak and jstraw March 12, 2024 18:48
@ekohl
Copy link
Member

ekohl commented Mar 20, 2024

The commit message and PR description no longer match the actual code. Would you mind fixing that up to avoid confusion in the future?

@TheMeier TheMeier changed the title remove resolved settings from config when changed to undef remove resolved settings from config when changed to absent Mar 20, 2024
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits, but overall 👍

@@ -204,8 +206,8 @@
Optional[Variant[Boolean,Enum['allow-downgrade']]] $dnssec = undef,
Variant[Boolean,Enum['yes', 'opportunistic', 'no']] $dnsovertls = false,
Optional[Variant[Boolean,Enum['no-negative']]] $cache = undef,
Optional[Variant[Boolean,Enum['udp','tcp']]] $dns_stub_listener = undef,
Optional[Array[String[1]]] $dns_stub_listener_extra = undef,
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,

Optional[Variant[Boolean,Enum['udp','tcp']]] $dns_stub_listener = undef,
Optional[Array[String[1]]] $dns_stub_listener_extra = undef,
Optional[Variant[Boolean,Enum['udp','tcp','absent']]] $dns_stub_listener = undef,
Optional[Variant[Array[String[1]],Enum['absent']]] $dns_stub_listener_extra = undef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a bit more readable type you can consider this:

Suggested change
Optional[Variant[Array[String[1]],Enum['absent']]] $dns_stub_listener_extra = undef,
Variant[Undef, Array[String[1]], Enum['absent']] $dns_stub_listener_extra = undef,

@TheMeier TheMeier merged commit 9e330f9 into master Apr 23, 2024
35 checks passed
@TheMeier TheMeier deleted the issues/397 branch April 23, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Impossible to unset DNSStubListenerExtra= once set.
5 participants