Invalid weight value

1. The problem I’m having:

Hi,

We want to run Blue/Green deployments with caddy as a reverse proxy.

My questions:

We are trying to use the lb policy fallback, weighted_round_robin with a 0 weight. In the documentations it states

The amount of weight arguments should match the amount of upstreams configured. Weights should be non-zero positive integers.

From the relevant resources in the link below it states the weight to be set as 0.

The error doesn’t appears if we use the converted Caddyfile to json using the following command and set the weights to 0 in the json file.

caddy adapt --config Caddyfile --pretty > Caddyfile.json

2. Error messages and/or full log output:

Error: adapting config using caddyfile: parsing caddyfile tokens for 'reverse_proxy': invalid weight value '0': weight should be non-zero and positive, at Caddyfile:5

3. Caddy version:

v2.8.1

d. My complete Caddy config:

reverse_proxy blue01:9000 blue02:9000 green01:9000 green02:9000 {
        lb_policy cookie {
                fallback weighted_round_robin 1 1 0 0
        }
}

5. Links to relevant resources:

Wouldn’t a zero weight imply the backend never gets used?

Hmm, interesting usecase with using fallback. I suppose it would make sense to allow 0 for that. PRs welcome if you want to take a shot at it. Probably simply need to remove a condition + error.

@matt the idea here is if there’s no cookie, then it would only take the blue servers, but if you later need to deploy or w/e, you swap the sets by changing the weights, so old clients continue to hit blue (having the cookie set) while new clients use green (according to the weights).

2 Likes

Thank you for your reply. Created the PR 6388

3 Likes