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

Add configuration change validations #1004

Merged
merged 15 commits into from
Jan 31, 2019
Merged

Conversation

kke
Copy link
Contributor

@kke kke commented Jan 24, 2019

Fixes #997

Here's the mechanism

For addons added a hook:

  validate_configuration do |old_config, new_config|
    raise "can't uninstall!" if old_config.enabled && !new_config.enabled
  end

It can also be defined with only 1 param:

  validate_configuration do |new_config|
    raise "can't be disabled!" unless new_config.enabled
  end

Or 3:

  validate_configuration do |config_key, old_value, new_value|
    raise "can't be changed!" if config_key == "kontena-backup.encryption_key"
  end

For phases / general config changes, made the cluster_manager load previous config earlier and run ValidateConfigurationChanges phase if a working master was found during GatherFacts.

It appears to work:

image

@kke kke added the enhancement New feature or request label Jan 24, 2019
@kke kke changed the title [wip] Validate configuration changes Add configuration change validations Jan 28, 2019
@kke kke requested a review from jakolehm January 28, 2019 11:18
@jakolehm jakolehm added this to the 2.2.0 milestone Jan 29, 2019
lib/pharos/addon.rb Show resolved Hide resolved

# @example deep get network provider
# config.deep_get("network.provider")
# @param key [String] a dot separated key, such as network.provider
Copy link
Contributor

Choose a reason for hiding this comment

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

@return missing.

yield config_key, old_value, new_value
end

def previous_config
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be in Phase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only used in addon_manager in addition to this phase.

# config.deep_get("network.provider")
# @param key [String] a dot separated key, such as network.provider
# @return [Object,NilClass] nil when any part of the chain is unreachable
def deep_get(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should use Pharos::CoreExt::DeepKeys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one doesn't need to hashify in the middle. Interestingly, something like config.deep_get("hosts.first.address") works with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is one .to_h that bad? It would remove duplicate code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I threw away the DeepKeys refinement thing and replaced it with HashDiff and renamed config.deep_get to config.dig which acts like hash.dig: config.dig(:network, :provider).

@kke kke force-pushed the feature/config_change_validation branch from b860ce5 to cf04d08 Compare January 30, 2019 13:37
@@ -47,6 +47,7 @@ module CommandOptions
module CoreExt
autoload :IPAddrLoopback, 'pharos/core-ext/ip_addr_loopback'
autoload :DeepTransformKeys, 'pharos/core-ext/deep_transform_keys'
autoload :DeepKeys, 'pharos/core-ext/deep_keys'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed anymore?

@@ -47,6 +47,7 @@ module CommandOptions
module CoreExt
autoload :IPAddrLoopback, 'pharos/core-ext/ip_addr_loopback'
autoload :DeepTransformKeys, 'pharos/core-ext/deep_transform_keys'
autoload :DeepKeys, 'pharos/core-ext/deep_keys'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
autoload :DeepKeys, 'pharos/core-ext/deep_keys'

Copy link
Contributor

@jakolehm jakolehm left a comment

Choose a reason for hiding this comment

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

LGTM

@jakolehm jakolehm merged commit 1236566 into master Jan 31, 2019
@jakolehm jakolehm deleted the feature/config_change_validation branch January 31, 2019 07:27
This was referenced Feb 1, 2019
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.

2 participants