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

Allow enabling and disabling policy sources #544

Merged
merged 4 commits into from
Nov 24, 2021
Merged

Conversation

lgfa29
Copy link
Contributor

@lgfa29 lgfa29 commented Nov 23, 2021

This PR builds on top of the approach taken in #525 but allows a more flexible way to define which policy sources should be enabled.

It introduces a new configuration block called source that can be placed within the existing policy block. Currently this block takes only a label that specifies which source it controls and a boolean attribute to enable or disable it:

policy {
  source "nomad" {
    enabled = false
  }
}

Both file and nomad sources are initially enabled by default, with file requiring that policy -> dir is also defined to be fully enabled, so everything remains backwards compatible.

The CLI flag parsing is a bit different than others, and it special cases the existing policy sources. This seems fine to me, as all policy sources are internal and having CLI flags to disable them sounds pretty useful.

If no policy source is enabled, the Autoscaler agent will fail and exit, since it won't be able to do any work without policies. In the future, we may want to implement a full reload of policy sources via SIGHUP so that sources can be enabled/disabled dynamically.

Possible future enhancements

This approach allows further customization of policy sources, such as moving the current policy -> dir into a new config map inside the file source:

source "file" {
  # Possible future enhancement.
  config = {
    dir = "./policies"
  }
}

With this, we could start supporting multiple configurations for the same policy source, such as reading policies from multiple paths:

source "file" "aws" {
  # Possible future enhancement.
  config = {
    dir = "./policies/aws"
  }
}

source "file" "gcp" {
  # Possible future enhancement.
  config = {
    dir = "./policies/gcp"
  }
}

Another possibility would be to start supporting external policy source plugins:

source "my-plugin" {
  # Possible future enhancement.
  driver = "my_source_plugin"
  config = {
    key = "value"
  }
}

This pattern of disabling internal components via a enabled attribute could also be used for plugins:

strategy "target-value" {
  driver  = "target-value"
  # Possible future enhancement.
  enabled = false
}

Closes #524

agent/config/config.go Outdated Show resolved Hide resolved
agent/config/config.go Outdated Show resolved Hide resolved
agent/config/config.go Show resolved Hide resolved
@lgfa29 lgfa29 requested a review from jrasell November 23, 2021 17:33
@lgfa29 lgfa29 merged commit ca3f067 into main Nov 24, 2021
@lgfa29 lgfa29 deleted the config-policy-source branch November 24, 2021 16:00
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

Successfully merging this pull request may close these issues.

Allow to disable the nomad source
2 participants