-
Notifications
You must be signed in to change notification settings - Fork 40.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Annotation Format #12226
Comments
cc @bgrant0607 |
This was on my list of features to consider for "v2" APIs: #8190. If changed in the v1 API we'd need to retain backward compatibility. Do you think that's feasible? We've discussing "subobject plugins" a number of times. Some standardized schema metadata (apiVersion, kind) would be necessary for interpreting them, much as our top-level API resources. |
cc @lavalamp |
@alexhersh I do think this is worthwhile, if you'd like to give it a try. The main requirement that needs to be satisfied is backward compatibility -- strings need to continue to work. |
This would also make it easier to use annotations to represent experimental fields exposed through new API versions when we serialize the resources using v1 in etcd. I think we should be able to retain backward compatibility, but might need our own polymorphic type, similar to IntOrString. |
This would be a cute trick, but it might wreak havoc on client libraries. I know we can trick Go into doing things, I don't know about other languages... |
cc @abonas @jimmidyson for input on clients in at least one other language An alternative would be a new |
Whether we use the same field or another, I'd like some input on how On Fri, Aug 7, 2015 at 3:57 PM, Brian Grant notifications@github.com
|
I don't see a problem. It's generic json: maps, lists, strings, etc. A schema isn't necessary to parse it. |
no, no schema required, just non-obvious marshalling/unmarshalling. Or On Fri, Aug 7, 2015 at 8:58 PM, Brian Grant notifications@github.com
|
No big deal for the Java client. We would probably hold it as a string & allow registration of custom (un)marshalers. Is there any concern on starting to use annotations for larger objects like this? Potentially hitting the resource limit? I could see this functionality having a lot of uses but what kind of impact could this have on storage, etc? |
cc @simon3z |
@bgrant0607 @thockin thanks for doing this discussion. |
We have folks using about 20k per resource for builds to store metadata. On Aug 8, 2015, at 4:12 AM, Jimmi Dyson notifications@github.com wrote: No big deal for the Java client. We would probably hold it as a string & Is there any concern on starting to use annotations for larger objects like — |
We will need size limits at some point, not just for annotations, but also for command lines, env, and anywhere else people could cram extra data. Some sort of resource-size LimitRange and/or ResourceQuota would make sense. I agree with the backward-compatibility concerns. If we were to do this, it would need to be a new field. I propose the field be called |
Implementation note: the easiest way to do this in go is to just stick variables of type json.RawJSON in the structure; that way, you don't even unmarshal them if you don't need to. It would be a breaking change to start doing this for annotations, however. Do we want to encourage people to store this much data in their objects? |
Related to #18670 |
We discussed this today some and while there are some short term advantages, the addition of additional unstructured structure does not dramatically improve the ability of the annotation to fulfill its core purpose - allowing third parties to carry opaque data with arbitrary objects. The json structure of the child object is only truly beneficial in a json serialization - and we already anticipate allowing a formal protobuf representation of all objects. The protobuf representation of these annotations would not be any easier to work with than a map, and would require more complex client logic for handling edge cases (whether numbers are allowed, is their format the same as json or different, etc). We feel that map[string]string is the simplest construct that accomplishes the goal, and additional structure is only situationally relevant. We should however better document best practices and patterns for working with annotations, planning for versioning, and storing complex data. |
+1 to @smarterclayton - I move close this |
@smarterclayton |
Is
"ugly"? How about:
Kubectl already does JSON encoding for you in this case. |
Nice trick, better than not having anything. Its still hacky imo to ask the end user to do this on every pod.
PS: Is dry-run available on master? |
Not sure how the second version works.
-f looks for a file with pod name. It cant have just the annotations. If it has the pod, where do you put the unencoded annotations? If it needs encoded annotations, its back to square one. It means that long structures still go on the command line which is a big pain. |
If kubectl create and annotate can take an extensions json file as another argument, json encode and update annotations that might work. |
The ... is the example is the encoded json string (well, bash). When Ultimately, if you want to apply an extension to everything, and you Ie support "v1.myextensions/does" with value "somethingsimple". Then |
I don't think a very sophisticated scheme is needed for what is being asked. There are a lot of plugins/extensions which need some configuration. It would be nice to carry that in the pod spec without making them first class objects. The alternative is to submit a proposal, rally the community and finally get it in a release. Even for good use cases, this process takes several months. If the use case is not very common, then its not going to be accepted in to k8s. Having a mechanism to carry this configuration will allow the plugins to move at their own pace. |
I understand. The recommendation at the current time is to focus on |
An alternate is to define a new field "extensions" as proposed earlier in the thread. As long as the size of this can be limited, I dont see any drawbacks. It will allow standard interfaces/tooling to be used for k8s. |
I think the main issues for annotations as field extensions currently are:
Escaping seems to not be a problem for yaml. Use single quotes:
|
Literal and folded styles also work:
That doesn't seem bad. |
@bgrant0607 Did the second example (this one #12226 (comment) ) render correctly on Github? That is, it's just regular YAML but with a "greater than" sign after the colon on the line with the key name? Also, if we do this would that mean people who want to use this annotation would have to write their whole config in YAML? I assume you can't just toss in some random YAML (for the annotation) in the midst of a JSON pod description? It seems like that might be a deal-breaker. |
@davidopp Either block scalar style should work: Yes, my example has a greater-than sign at the end of line. A pipe at the end of line (literal style) also works. JSON is legal YAML, so they can mix JSON and YAML as they wish. |
What did you mean "no conversion from yaml to json"? Clearly your "kubectl convert -f nginx-pod.yaml -o json" converts yaml to json. Did you mean inside the API server? |
@davidopp The data inside the annotation value is not converted because it is opaque to kubectl and to the apiserver. We could do the conversion server-side, but that would have to be on a per-annotation basis. |
Reasoning about versioned annotations is already hard enough without
the server fiddling with their representation. Opaque string
annotations are easy to reason about, structure introduces more things
that can go wrong.
|
cc @mikedanese |
I think we're never going to do this, so closing. |
For posterity: you can find an example of embedding JSON in the value of an annotation in #19758. It works, complete with validation. |
I am working on implementing network policy rules in Kubernetes annotations and am hitting a limitation in how Kubernetes parses dictionary values in the pod spec.
I would like to put nested lists within annotation values, but annotations are expected to be single
"key": "value"
string pairs. To get around this I am tokenizing my data as a single string and then marshaling it separately in my code, but the result is unreadable and not intuitive.For example, I would like to format my pod config like:
but my workaround looks like:
One line solutions are cool and all, but this design is not very easy to program or debug, nor is it suitable for larger annotations. I would much prefer to have more robust annotation support natively in the Kubernetes pod spec.
If you agree that this feature is worth implementing, I can go ahead and try to build it in myself.
The text was updated successfully, but these errors were encountered: