Pass the label of docker container to the annotation of OCI runtime spec#36181
Pass the label of docker container to the annotation of OCI runtime spec#36181miaoyq wants to merge 1 commit intomoby:masterfrom
Conversation
daemon/oci_linux.go
Outdated
There was a problem hiding this comment.
Is s.Annotations guaranteed to be empty here?
Even if so, I think the code should be as follows:
for k, v := range c.Config.Labels{
vv, ok := s.Annotations[k]
if ok {
return nil, errors.Errorf("label %q conflicts, old=%q, new=%q", vv, v)
}
s.Annotations[k] = v
}There was a problem hiding this comment.
@AkihiroSuda If a key already exists in s.Annotations we could print a warning msg instead of return directly, wdyt?
b58f4f6 to
01212c5
Compare
daemon/oci_linux.go
Outdated
1ad04bd to
514713f
Compare
daemon/oci_linux.go
Outdated
There was a problem hiding this comment.
nit: oldValue and ok are only used inside the if, so;
if oldValue, ok := s.Annotations[k]; ok {
logrus.Warningf("Key %q already exists in Annotations, old value=%q, new value=%q", k, oldValue, v)
continue
}The warning should also mention that we're ignoring the new value
I'm not sure what would be best though:
- under what situations would an existing label exist in the annotations?
- if an existing annotation is there, is it correct to ignore the new value (even with a warning)? Or should it produce an error; instructing the user to correct the conflicting option?
In general, I'm in favour of being strict, and error out. If at some point in future we think it's ok to change an error into a warning, we can do so without breaking backward compatibility, whereas the opposite is not possible.
ping @mlaventure @cpuguy83 PTAL
There was a problem hiding this comment.
I'm not sure in which scenario that would happen, but I'd vote to start with an error too,
There was a problem hiding this comment.
@thaJeztah @mlaventure Makes sense. Will change to error.
514713f to
472010f
Compare
daemon/oci_linux.go
Outdated
There was a problem hiding this comment.
oh; meant this to be returning the error (thus "fail");
return nil, errors.Errorf(".......There was a problem hiding this comment.
@thaJeztah I thought that this should not terminate the container starting, just give an error message, since the Annotations does not seem to be used directly by docker.
But returning the error is also reasonable here. Have done. :-)
472010f to
084986e
Compare
|
Actually; one more thought: do labels that are set on a docker container have to be namespaced when passing through? (e.g. a |
@thaJeztah I think we should keep it as it is, make sure OCI runtime can get the data that has not be changed. |
|
I really don't like just passing all labels through, people use labels for all sorts of things, and these may not be intended to be passed on. Also the OCI spec says "Keys SHOULD be named using a reverse domain notation - e.g. ( |
|
@justincormack Could we filter the labels whose |
|
I think this feature can be useful, currently there's no way to pass Annotations into OCI runtime from docker, though OCI spec defines Annotations field. How about we make some rules, for example, if the label key string starts with "annotation.", we pass it to runtime annotation, otherwise we do nothing.
|
|
Any conclusion for this feature? |
|
What about just a list of label keys as an allow-list for what gets passed to the runtime? |
|
@miaoyq this one needs to be rebased |
|
Please sign your commits following these rules: $ git clone -b "label-to-oci-spec-annotation" git@github.com:miaoyq/docker.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354427496
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -fAmending updates the existing PR. You DO NOT need to open a new one. |
d3f80f7 to
634a38c
Compare
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
634a38c to
4b0fc96
Compare
Codecov Report
@@ Coverage Diff @@
## master #36181 +/- ##
=========================================
Coverage ? 36.56%
=========================================
Files ? 608
Lines ? 45042
Branches ? 0
=========================================
Hits ? 16470
Misses ? 26293
Partials ? 2279 |
|
Implemented (but slightly different) in #45025 |
Signed-off-by: Yanqiang Miao miao.yanqiang@zte.com.cn
- What I did
Currectly, docker save the label data in container struct of docker, but not in
config.jsondefined by OCI.This pr pass the label of docker container to the annotation of OCI runtime spec, so that the label data which is set by kubernetes can be used by the VM-based runtime (like
clear-containers) .For example:
/cc @sameo @plutoinmii
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)