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

config: add yaml flag #3069

Merged
merged 1 commit into from
May 8, 2024
Merged

config: add yaml flag #3069

merged 1 commit into from
May 8, 2024

Conversation

AlexanderYastrebov
Copy link
Member

YAML flag parses (preferably flow-style) YAML value from the command line or unmarshals object yaml value from the yaml config file.

Example value:

bin/skipper -foo-flag='{foo: hello, bar: [world, "1"], baz: 2, qux: {baz: 3}}'

and equivalent branch in config yaml:

foo-flag:
  foo: hello
  bar:
    - world
    - "1"
  baz: 2
  qux:
    baz: 3

This will be useful for #2104

It is also a better alternative to manual parsing of micro-syntax like e.g. implemented in #2888

@AlexanderYastrebov AlexanderYastrebov added the minor no risk changes, for example new filters label May 7, 2024
YAML flag parses (preferably flow-style) YAML value from the command line
or unmarshals object yaml value from the yaml config file.

Example value:
```
bin/skipper -foo-flag='{foo: hello, bar: [world, "1"], baz: 2, qux: {baz: 3}}'
```

and equivalent branch in config yaml:
```yaml
foo-flag:
  foo: hello
  bar:
    - world
    - "1"
  baz: 2
  qux:
    baz: 3
```

This will be useful for #2104

It is also a better alternative to manual parsing of micro-syntax like
e.g. implemented in #2888

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
)

type yamlFlag[T any] struct {
Ptr **T
Copy link
Member

Choose a reason for hiding this comment

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

ouch :)
But I see why

Copy link
Member Author

Choose a reason for hiding this comment

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

The usage looks like

type Config struct {
  OpenTelemetry *otel.Options `yaml:"open-telemetry"`
  ...
}
...
flag.Var(newYamlFlag(&cfg.OpenTelemetry), "open-telemetry", "OpenTelemetry configuration in YAML format, use flow-style for convenience")
...

if o.OpenTelemetry != nil {
...
}

The value is allocated when flag is set and stays nil when it is not, i.e. this allows to tell if flag was provided.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I saw it, all good :)

@szuecs
Copy link
Member

szuecs commented May 7, 2024

👍

1 similar comment
@AlexanderYastrebov
Copy link
Member Author

👍

@AlexanderYastrebov AlexanderYastrebov merged commit f97919e into master May 8, 2024
14 checks passed
@AlexanderYastrebov AlexanderYastrebov deleted the config/yaml-flag branch May 8, 2024 08:58
JanardhanSharma pushed a commit to JanardhanSharma/skipper that referenced this pull request Jul 19, 2024
YAML flag parses (preferably flow-style) YAML value from the command line
or unmarshals object yaml value from the yaml config file.

Example value:
```
bin/skipper -foo-flag='{foo: hello, bar: [world, "1"], baz: 2, qux: {baz: 3}}'
```

and equivalent branch in config yaml:
```yaml
foo-flag:
  foo: hello
  bar:
    - world
    - "1"
  baz: 2
  qux:
    baz: 3
```

This will be useful for zalando#2104

It is also a better alternative to manual parsing of micro-syntax like
e.g. implemented in zalando#2888

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor no risk changes, for example new filters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants