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

Load config from both env and yaml #162

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Load config from both env and yaml #162

wants to merge 9 commits into from

Conversation

jrauh01
Copy link
Collaborator

@jrauh01 jrauh01 commented Jan 15, 2025

With this PR Icinga for Kubernetes supports configuration loading in three scenarios:

  1. Load configuration solely from YAML files when no relevant environment variables are set.
  2. Combine YAML file and environment variable configurations, allowing environment variables to supplement or override possible incomplete YAML configurations.
  3. Load entirely from environment variables if the default YAML config file is absent and no specific config path is provided by the user.

The configuration is loaded via config.Load()

Requires Icinga/icinga-go-library#87

Closes #160

@jrauh01 jrauh01 requested a review from lippserd January 15, 2025 09:19
@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Jan 15, 2025
@jrauh01 jrauh01 removed the request for review from lippserd January 15, 2025 09:23
@jrauh01 jrauh01 requested a review from lippserd January 15, 2025 09:44
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

Also, please take another look at the Icinga DB PR where I added the default configuration path in the flag description and added code comments to the flags struct on what it actually implements. That should be included here as well.


if err = config.Load(&cfg, config.LoadOptions{
Flags: glue,
EnvOptions: config.EnvOptions{Prefix: "IFK_"},
Copy link
Member

Choose a reason for hiding this comment

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

Although there is (much) more to type, ICINGA_FOR_KUBERNETES_ simply reads much better than IFK.

@jrauh01 jrauh01 requested a review from lippserd January 16, 2025 08:55
pflag.StringVar(
&glue.Config,
"config",
daemon.DefaultConfigPath,
Copy link
Member

Choose a reason for hiding this comment

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

A default shouldn't be set, right? Else f.Config != "" is never false.

@@ -7,12 +7,16 @@ import (
"github.com/icinga/icinga-kubernetes/pkg/notifications"
)

// DefaultConfigPath specifies the default location of Icinga DB's config.yml for package installations.
Copy link
Member

Choose a reason for hiding this comment

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

Everything about this sentence is wrong 😆

@@ -7,12 +7,16 @@ import (
"github.com/icinga/icinga-kubernetes/pkg/notifications"
)

// DefaultConfigPath specifies the default location of Icinga DB's config.yml for package installations.
// const DefaultConfigPath = "/etc/icinga-kubernetes/config.yml"
Copy link
Member

Choose a reason for hiding this comment

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

Please remove.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support loading configuration from both YAML files and env vars
2 participants