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 environment variables to have a default value #2534

Closed
jrcamp opened this issue Feb 23, 2021 · 6 comments
Closed

Allow environment variables to have a default value #2534

jrcamp opened this issue Feb 23, 2021 · 6 comments

Comments

@jrcamp
Copy link
Contributor

jrcamp commented Feb 23, 2021

Is your feature request related to a problem? Please describe.

When using environmental variables you may want to have a default that is used if a user does not override it. For example:

config:
  endpoint: ${ENDPOINT:-localhost:8080}

Describe the solution you'd like
Allow bash-like variable substitution.

Describe alternatives you've considered
Not allowing it and require all defaults to be set external to the process. The downside is that the config and defaults now live in two separate places.

@jcchavezs
Copy link
Contributor

I can work on this.

@bogdandrutu
Copy link
Member

@jcchavezs please wait couple of days until we publish a document about the syntax we want for this.

/cc @tigrannajaryan @pjanotti

@jrcamp
Copy link
Contributor Author

jrcamp commented Mar 10, 2021

Will be addressed by #2469 with general default syntax.

@jrcamp jrcamp added the priority:p3 Lowest label Mar 10, 2021
@jrcamp jrcamp self-assigned this Mar 10, 2021
@ttomsu
Copy link

ttomsu commented Jun 18, 2021

Any progress made here? We've got some env vars that have (multiple) fallbacks, so these default values would be really nice.

@jrcamp
Copy link
Contributor Author

jrcamp commented Jun 18, 2021

It is part of the configsource in Splunk distribution but I'm not sure if there's a timeline of when it will be upstreamed https://github.com/signalfx/splunk-otel-collector/tree/main/internal/configsource/envvarconfigsource @pjanotti?

@jrcamp jrcamp removed their assignment Jun 22, 2021
hughesjj pushed a commit to hughesjj/opentelemetry-collector that referenced this issue Apr 27, 2023
Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.8.0 to 0.9.0.
- [Release notes](https://github.com/aquasecurity/trivy-action/releases)
- [Commits](aquasecurity/trivy-action@0.8.0...0.9.0)

---
updated-dependencies:
- dependency-name: aquasecurity/trivy-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@github-actions github-actions bot added the Stale label Jun 23, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2023
@ringerc
Copy link

ringerc commented Nov 14, 2023

A workaround for the lack of this capability in k8s based deployments is to use a layered configmap reference.

In a podTemplate container spec such as the .spec.template.spec.containers[] of a Deployment or DaemonSet, add e.g.:

envFrom:
  - configMapRef:
      name: my-collector-defaults
  - configMapRef:
      name: my-collector-overrides
      optional: true

Deploy my-collector-defaults with your component's usual manifests bundle.

Create my-collector-overrides with keys you wish to override default environment values for. The last-found value will be the one that takes effect. Be warned that values in env: override envFrom:.

The same thing works with env e.g.

          - name: DEBUG_EXPORTER_VERBOSITY
            valueFrom: 
              configMapKeyRef:
                name: otel-node-agent-settings-default
                key: DEBUG_EXPORTER_VERBOSITY
          - name: DEBUG_EXPORTER_VERBOSITY 
            valueFrom:
              configMapKeyRef:
                name: otel-node-agent-settings-override
                key: DEBUG_EXPORTER_VERBOSITY
                optional: true

If you use flux for your manifest deployments, you can annotate your overrides configmap with e.g.

metadata:
  annotations:
    kustomize.toolkit.fluxcd.io/prune: disabled
    kustomize.toolkit.fluxcd.io/reconcile: disabled

to ensure flux won't try to delete it.

(You can avoid having the defaults configmap by defining env literals in the app manifest instead but I dislike doing so. The defaults and overrides pattern makes it a bit more discoverable.)

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

No branches or pull requests

5 participants