Skip to content

fixes when no equal sign in label file#1416

Open
lifubang wants to merge 1 commit into
docker:masterfrom
lifubang:labelfilenoequalsign
Open

fixes when no equal sign in label file#1416
lifubang wants to merge 1 commit into
docker:masterfrom
lifubang:labelfilenoequalsign

Conversation

@lifubang
Copy link
Copy Markdown
Contributor

@lifubang lifubang commented Oct 4, 2018

Signed-off-by: Lifubang lifubang@acmcoder.com

- What I did
When use --label:
./build/docker run -d --name=redis5 --label foo redis

root@dockerdemo:~/gocode/src/github.com/docker/cli# ./build/docker inspect --format '{{.Config.Labels}}' redis5
map[foo:]

When use --label-file:

root@dockerdemo:~/gocode/src/github.com/docker/cli# echo $foo
bar
root@dockerdemo:~/gocode/src/github.com/docker/cli# cat ~/labels.txt 
foo
bar=
root@dockerdemo:~/gocode/src/github.com/docker/cli# build/docker run -d --name=redis7 --label-file ~/labels.txt redis
root@dockerdemo:~/gocode/src/github.com/docker/cli# ./build/docker inspect --format '{{.Config.Labels}}' redis7
map[bar:]

label foo is lost.

The behavior of --label and --label-file is different when there is no equal sign after label variable.
- How I did it
When there is no equal sign after label variable, and no emptyFn, add it to output.

- How to verify it
After fix:

root@dockerdemo:~/gocode/src/github.com/docker/cli# build/docker run -d --name=redis8 --label-file ~/labels.txt redis
root@dockerdemo:~/gocode/src/github.com/docker/cli# ./build/docker inspect --format '{{.Config.Labels}}' redis8
map[bar: foo:]

- Description for the changelog
fixes when no equal sign in label file

- A picture of a cute animal (not mandatory but encouraged)
508c439d40d41d0a9c2e3256ee1ca5a

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #1416 into master will increase coverage by 0.13%.
The diff coverage is 50%.

@@            Coverage Diff             @@
##           master    #1416      +/-   ##
==========================================
+ Coverage   54.26%   54.39%   +0.13%     
==========================================
  Files         289      289              
  Lines       19331    19268      -63     
==========================================
- Hits        10490    10481       -9     
+ Misses       8165     8115      -50     
+ Partials      676      672       -4

vdemeester
vdemeester previously approved these changes Oct 4, 2018
Copy link
Copy Markdown
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Haven't checked yet, but is this same function also used for env-files? If so, should it behave the same?

We should at least have a test for this, as the behavior of empty values vs not-set is already tricky, so easy to introduce regressions / change in behavior

@vdemeester
Copy link
Copy Markdown
Collaborator

Haven't checked yet, but is this same function also used for env-files? If so, should it behave the same?

Yeah, but for env-files the emptyfn is not nil so it should still act the same 😉 But I agree on a test

@lifubang
Copy link
Copy Markdown
Contributor Author

lifubang commented Oct 4, 2018

Thank you for all your review, I'll add some test cases.

@lifubang lifubang force-pushed the labelfilenoequalsign branch 2 times, most recently from ee54671 to a2bea38 Compare October 4, 2018 11:09
Copy link
Copy Markdown
Contributor Author

@lifubang lifubang left a comment

Choose a reason for hiding this comment

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

I have add two test cases for label/env file without equal sign.

@lifubang
Copy link
Copy Markdown
Contributor Author

lifubang commented Oct 5, 2018

@thaJeztah I don't know if I have understood your points. Do you mean add some test cases, or change code to check the lines value?

@tonistiigi
Copy link
Copy Markdown
Member

ping @thaJeztah

@thaJeztah
Copy link
Copy Markdown
Member

Cleaning up old PRs; I thought this was fixed, but indeed looks like the "no value set" omits the label; still need to look if that was or was not by design, but did a quick rebase, and updated the patch to make the new tests added in this PR pass.

@thaJeztah thaJeztah added this to the 29.5.1 milestone May 13, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
opts/parse.go 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@thaJeztah thaJeztah force-pushed the labelfilenoequalsign branch from 17c1fa2 to e559a45 Compare May 13, 2026 15:27
Signed-off-by: Lifubang <lifubang@acmcoder.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the labelfilenoequalsign branch from e559a45 to 6a201f3 Compare May 13, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants