Repository navigation
fix: keep deprecated BACKUP_STOP_CONTAINER_LABEL usable - #905
Conversation
m90
left a comment
There was a problem hiding this comment.
Thanks for working on this. I have a feeling this should either be simpler (just checking the raw env) or more ergonomic (not having to know about the env to config mapping). Currently, the added complexity is not really worth it.
Let me know what you think.
`BACKUP_STOP_DURING_BACKUP_LABEL` defaults to `true`, so the check that detects both settings being in use (`!= ""` on both fields) always succeeds when the deprecated `BACKUP_STOP_CONTAINER_LABEL` is set, even though the user never configured its successor. `resolve()` then fails with "both BACKUP_STOP_DURING_BACKUP_LABEL and BACKUP_STOP_CONTAINER_LABEL have been set, cannot continue" and the deprecation warning right below it is never emitted, which also explains why offen#882 saw the error without any deprecation message. This breaks the documented deprecation path: "The old key will stay supported until the next major version, but logs a warning each time a backup is taken." (docs/how-tos/replace-deprecated-backup-stop-container-label.md) The parsed value of the successor key cannot tell an explicit setting apart from its default, so the conflict is detected from the environment instead: the key is looked up with `os.Getenv`, the same pattern used for `DOCKER_HOST` in script.go. Configurations that set both keys are still rejected, while configurations that only use the deprecated key are transposed and warned about as documented. Refs offen#882 Signed-off-by: simpleqt <2015900818@qq.com>
690ae21 to
866c798
Compare
|
You're right — the extra machinery wasn't worth it. I've replaced it with the raw-env check: if c.BackupStopContainerLabel != "" {
// BACKUP_STOP_DURING_BACKUP_LABEL defaults to true, so the parsed values
// cannot tell whether the user has set it on purpose. Look at the
// environment instead, the same way DOCKER_HOST is checked in script.go.
if os.Getenv("BACKUP_STOP_DURING_BACKUP_LABEL") != "" {
err = errwrap.Wrap(nil, "both BACKUP_STOP_DURING_BACKUP_LABEL and BACKUP_STOP_CONTAINER_LABEL have been set, cannot continue")
return
}
...That dropped the Tests: the subtest that exercises the conflict now sets the key with One consequence worth your call. Because the check reads the environment, a successor key supplied through the Also for completeness: RED at submission was |
Considering this has been deprecated a long time ago, I think it's fine to keep it simple. Thanks for raising in any case. |
Root cause
BACKUP_STOP_DURING_BACKUP_LABELhas a non-empty default (true), so inConfig.resolve()(cmd/backup/config.go:353) the checkis always true when the deprecated
BACKUP_STOP_CONTAINER_LABELis set — no matter whether its successor was configured by the user or just filled in from its default. This makes the deprecation path below it unreachable:both ... have been set, cannot continue, anddocs/how-tos/replace-deprecated-backup-stop-container-label.md:19) is never logged, which is also why the reporter of cannot run when only setting BACKUP_STOP_CONTAINER_LABEL #882 never saw a deprecation message.Reproduction
A container that only sets the deprecated key breaks all of its backup runs:
The same configuration works when
BACKUP_STOP_DURING_BACKUP_LABEL=""is added, i.e. the conflict is only reported because of the default value.Fix
loadConfignow records the keys that have actually been provided by the user (cmd/backup/config_provider.go), which allowsresolve()to detect a conflict based on an explicitly set successor key only. The deprecated key is then transposed and warned about as documented, and configurations that really do set both keys are still rejected.Test evidence
New test in
cmd/backup/config_stop_label_test.go, run withgo test ./cmd/backup/.Before (HEAD):
After:
gofmt -l cmd internalreports no files.Refs #882
Not run: the Docker based integration suite in
test/(no Docker available here),golangci-lint(not installed locally).