mirror of https://github.com/k3s-io/k3s
![]() Automatic merge from submit-queue Remove an empty line being output when exposing annotations and labels via downward api volume The issue is that formatMap function (for annotations and labels) in pkg/fieldpath/fieldpath.go appends a "\n" after each key value pair which is correct for all pairs except the last pair because then a complete string is returned with a "\n" in the end. It is inconsistent with other strings (metadata.name, namespace and resources) being returned as they dont have "\n" in the end. These returned strings are processed by sortLines function in pkg/volume/downwardapi/downwardapi.go and the function finally appends "\n" to each string, but incorrectly outputs an empty line if there is an already "\n" in the end with the input string. To illustrate: The sortLines works as follows: lets say the input string is : "a\nb\nc\n". 1. It splits them as "a", "b", "c", "" (note empty string in the end). 2. it sort them: "", "a", b", "c" 3. And then it appends "\n" again to each string: "\n", "a\n" ,"b\n", "c\n" So we can see that it is erroneously creating an empty string in the beginning when the input string to sortLines has "\n" in the end. As I said above, it is not an issue with metadata.name, namespace and resources as their input strings are without \n" in the end. So now, the output in the downward api volume, (using the example in http://kubernetes.io/docs/user-guide/downward-api/): ``` # cat /etc/annotations zone="us-est-coast" cluster="test-cluster1" rack="rack-22" ``` After this patch, the output will be correct and without the erroneous empty line in the beginning. I could think other ways to solve this but I found the way in this patch with minimal code changes. @kubernetes/rh-cluster-infra |
||
---|---|---|
.. | ||
OWNERS | ||
downwardapi.go | ||
downwardapi_test.go |