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

traefik: unify TOML generation #89744

Merged
merged 1 commit into from Jun 19, 2020
Merged

Conversation

vojta001
Copy link
Contributor

@vojta001 vojta001 commented Jun 7, 2020

As a side effect, the dynamic config file is now indented

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

As a side effect, the dynamic config file is now indented
@mdlayher
Copy link
Member

mdlayher commented Jun 8, 2020

@GrahamcOfBorg test traefik

Copy link
Member

@mdlayher mdlayher left a comment

Choose a reason for hiding this comment

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

LGTM!

[matt@servnerr-3:~/src/nixpkgs]$ cat /nix/store/ifi9fh33m7ysxzdx0qfzhldi7ix3sdjb-config.toml
[entryPoints]
  [entryPoints.web]
    address = ":80"

[global]
  checkNewVersion = false
  sendAnonymousUsage = false

[providers]
  [providers.docker]
    exposedByDefault = false
  [providers.file]
    filename = "/nix/store/c9v743dlz0x900y1rxf7g6ws3qbggdy2-config.toml"

@vojta001
Copy link
Contributor Author

vojta001 commented Jun 8, 2020

LGTM!

[matt@servnerr-3:~/src/nixpkgs]$ cat /nix/store/ifi9fh33m7ysxzdx0qfzhldi7ix3sdjb-config.toml
[entryPoints]
  [entryPoints.web]
    address = ":80"

[global]
  checkNewVersion = false
  sendAnonymousUsage = false

[providers]
  [providers.docker]
    exposedByDefault = false
  [providers.file]
    filename = "/nix/store/c9v743dlz0x900y1rxf7g6ws3qbggdy2-config.toml"

This file should be the same, I haven't touched its generation. You are probably interested in the file provider - /nix/store/c9v743dlz0x900y1rxf7g6ws3qbggdy2-config.toml in your case

@alyssais alyssais merged commit 4e69b0a into NixOS:master Jun 19, 2020
@jktr
Copy link
Contributor

jktr commented Jun 25, 2020

This patch seems to break my existing traefik configuration.

The underlying problem is that json doesn't distinguish between integers and floats, but both toml and nix do. So if I specify an integer value in dynamicConfigOptions, this is first converted to a json number by builtins.toJSON. Then, yj converts this json number to a toml float. So the type information is lost when converting to json.

While surprising, this is probably correct behavior on yj's part (see sclevine/yj#3). Still, this seems to make it impossible to specify traefik settings that expect integers via dynamicConfigOptions, as these integer settings are always converted to floats, which will then cause traefik to fail to load the resultant toml with Cannot start the provider *file.Provider: toml: cannot load TOML value of type float64 into a Go integer.

For example, lets take a look at the following traefik configuration:

services.traefik = {
  enable = true;
  staticConfigOptions.entryPoints."http"  = { address = ":80";  };
  dynamicConfigOptions = {
    http = {
      middlewares."ratelimit".ratelimit = {
        average = 1;
        burst = 10;
      };
      routers."subdomains" = {
        rule = "HostRegexp(`{subdomain:[a-z]+}.example.com`)";
        service = "nginx";
        middlewares = [ "ratelimit" ];
        priority = 1;
      };
      services."nginx".loadBalancer.servers = [{ url = "h2c://[::1]:8001"; }];
    };
  };
};

the above is converted to the following (dynamic) configuration file:

[http]
  [http.middlewares]
    [http.middlewares.ratelimit]
      [http.middlewares.ratelimit.ratelimit]
        average = 1.0
        burst = 10.0
  [http.routers]
    [http.routers.subdomains]
      middlewares = ["ratelimit"]
      priority = 1.0
      rule = "HostRegexp(`{subdomain:[a-z]+}.example.com`)"
      service = "nginx"
  [http.services]
    [http.services.nginx]
      [http.services.nginx.loadBalancer]

        [[http.services.nginx.loadBalancer.servers]]
          url = "h2c://[::1]:8001"

As you can see, the average, burst and priority settings have their types converted, causing traefik to fail to load this dynamic configuration.

@bqv
Copy link
Contributor

bqv commented Jun 29, 2020

This broke my config also, and was a nightmare to hunt down. @alyssais please revert

@lheckemann
Copy link
Member

Reverted in 5b8b201

@sclevine
Copy link

This is addressed in yj v5.0.0 (even though the previous behavior technically adheres to the spec).

 onyx:yj stephen$ echo '{"a": 1}'|./yj -jt
a = 1
 onyx:yj stephen$ echo '{"a": 1.0}'|./yj -jt
a = 1.0

@vojta001 vojta001 deleted the traefik-indent-config branch February 17, 2021 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants