Skip to content

Pass the label of docker container to the annotation of OCI runtime spec#36181

Closed
miaoyq wants to merge 1 commit intomoby:masterfrom
miaoyq:label-to-oci-spec-annotation
Closed

Pass the label of docker container to the annotation of OCI runtime spec#36181
miaoyq wants to merge 1 commit intomoby:masterfrom
miaoyq:label-to-oci-spec-annotation

Conversation

@miaoyq
Copy link
Contributor

@miaoyq miaoyq commented Feb 2, 2018

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.json defined 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:

	containerTypeLabelKey       = "io.kubernetes.docker.type"
	containerTypeLabelSandbox   = "podsandbox"
	containerTypeLabelContainer = "container"
	containerLogPathLabelKey    = "io.kubernetes.container.logpath"
	sandboxIDLabelKey           = "io.kubernetes.sandbox.id"

/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)

Copy link
Member

Choose a reason for hiding this comment

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

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AkihiroSuda Thanks, will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AkihiroSuda If a key already exists in s.Annotations we could print a warning msg instead of return directly, wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

I think ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@miaoyq miaoyq force-pushed the label-to-oci-spec-annotation branch from b58f4f6 to 01212c5 Compare February 5, 2018 02:07
Copy link
Member

Choose a reason for hiding this comment

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

: -> =?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure in which scenario that would happen, but I'd vote to start with an error too,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thaJeztah @mlaventure Makes sense. Will change to error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

oh; meant this to be returning the error (thus "fail");

return nil, errors.Errorf(".......

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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. :-)

@miaoyq miaoyq force-pushed the label-to-oci-spec-annotation branch from 472010f to 084986e Compare February 14, 2018 00:44
thaJeztah
thaJeztah previously approved these changes Feb 14, 2018
Copy link
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.

LGTM

@AkihiroSuda PTAL

@thaJeztah
Copy link
Member

Actually; one more thought: do labels that are set on a docker container have to be namespaced when passing through? (e.g. a org.moby.label.<label name> prefix)? IOW; is there a need to distinguish labels from other kind of annotations?

@miaoyq
Copy link
Contributor Author

miaoyq commented Feb 14, 2018

Is there a need to distinguish labels from other kind of annotations?

@thaJeztah I think we should keep it as it is, make sure OCI runtime can get the data that has not be changed.
Containerd also doesn't care the Annotations as far as I know. :-)

@justincormack
Copy link
Contributor

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. com.example.myKey." and "Keys using the org.opencontainers namespace are reserved and MUST NOT be used by subsequent specifications." so I think just adding arbitrary labels is not the intended use case.

(containerd also has annotations, but I don't think we want to expose those either necessrily).

@miaoyq
Copy link
Contributor Author

miaoyq commented Feb 22, 2018

@justincormack Could we filter the labels whose key format like io.kubernetes.docker.type and copy them into annotations fields?

@WeiZhang555
Copy link
Contributor

WeiZhang555 commented Apr 12, 2018

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.

  1. label "annotation.io.kubernetes.docker.type=container", then we pass an Annotation["io.kubernetes.docker.type"]=container
  2. label "io.docker.xxx=xxx", we do NOT pass it to OCI runtime.

@miaoyq
Copy link
Contributor Author

miaoyq commented Aug 3, 2018

Any conclusion for this feature?
Docker still the main and default container runtime engine for k8s so far, so I think this feature is very useful for the people of using secure containers. :-)
@thaJeztah @justincormack

@cpuguy83
Copy link
Member

What about just a list of label keys as an allow-list for what gets passed to the runtime?

@olljanat
Copy link
Contributor

@miaoyq this one needs to be rebased

@derek derek bot added the status/failing-ci Indicates that the PR in its current state fails the test suite label Dec 22, 2018
@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Dec 24, 2018
@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ 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 -f

Amending updates the existing PR. You DO NOT need to open a new one.

@miaoyq miaoyq force-pushed the label-to-oci-spec-annotation branch from d3f80f7 to 634a38c Compare December 24, 2018 00:51
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Dec 24, 2018
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
@miaoyq miaoyq force-pushed the label-to-oci-spec-annotation branch from 634a38c to 4b0fc96 Compare December 24, 2018 01:04
@codecov
Copy link

codecov bot commented Dec 24, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@d147fe0). Click here to learn what that means.
The diff coverage is 33.33%.

@@            Coverage Diff            @@
##             master   #36181   +/-   ##
=========================================
  Coverage          ?   36.56%           
=========================================
  Files             ?      608           
  Lines             ?    45042           
  Branches          ?        0           
=========================================
  Hits              ?    16470           
  Misses            ?    26293           
  Partials          ?     2279

@thaJeztah
Copy link
Member

Implemented (but slightly different) in #45025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime status/failing-ci Indicates that the PR in its current state fails the test suite status/1-design-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.