TritonDataCenter / sdc-docker

Docker Engine for Triton
Mozilla Public License 2.0
182 stars 49 forks source link

Allow for escaping docker:label #137

Open Smithx10 opened 5 years ago

Smithx10 commented 5 years ago

While working on https://github.com/Smithx10/virtual-kubelet, I came across a situation where I would like for all instances provisioned to have a certain set of shared tags whether they are provisioned via sdc-docker or sdc-cloudapi.

The Docker API is only aware of labels, which are stored in Triton as tags prefixed with docker:label:

I was hoping that we could add to docker a way to escape docker:label: and set tags directly, this will save me from having to make 2 api calls, a Create, and then an Apply tag.

Implementation Idea: I noticed that the label "triton.cns.services" was applied without the docker:label prefix. I imagine we could do something like the following to escape it...

--label no.prefix.mytag=mytagvalue 

Which would result in the following tag:

mytag=mytagvalue 

Instead of

docker:label:mytag
Smithx10 commented 5 years ago

I hacked together something simple. I believe this sums up in essence what is desired, but probably needs a safer implementation.

I added the following to https://github.com/joyent/sdc-docker/blob/master/lib/backends/sdc/containers.js#L2033

2023                     } else if (triton_tags.isTritonTag(key)) {
2024                         triton_tags.parseTritonTagStr(key, val,
2025                                 function (err, parsed) {
2026                             if (err) {
2027                                 labelErrs.push(err);
2028                             } else {
2029                                 payload.tags[key] = parsed;
2030                             }
2031                             next();
2032                         });
2033                     } else if (key.lastIndexOf('escape.prefix.', 0) === 0) {
2034                          key = key.split(/\.(?=[^\.]+$)/)[1];
2035                          payload.tags[key] = val;
2036                          next();
2037                     } else {
2038                         payload.tags[common.LABELTAG_PREFIX + key] = val;
2039                         next();
2040                     }
2041                 }