Comments (12)
There are no sig labels on this issue. Please add an appropriate label by using one of the following commands:
/sig <group-name>
/wg <group-name>
/committee <group-name>
Please see the group list for a listing of the SIGs, working groups, and committees available.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
from kubernetes.
This issue is currently awaiting triage.
If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted
label and provide further guidance.
The triage/accepted
label can be added by org members by writing /triage accepted
in a comment.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
from kubernetes.
how about sorting by lastTransitionTime
?
from kubernetes.
I didn't mean sorting the conditions, I meant sorting the fields within each condition so that type
is always first. But not just conditions. This is just one example though. So many of our structures have fields that should be first, like name or key, but they aren't first alphabetically. When I look at emitted yaml or json. It's just not in an order that I naturally want to see it, which makes examples and CLI output less friendly than it could be
from kubernetes.
ok, I got it, that makes sense, I think the conditions also should be sorted. Do you agree with this?
/assign @cyclinder
from kubernetes.
I think the conditions also should be sorted.
Conditions are a sort of extension point - we don't know every possible Condition. Sorting them based on transition time could confuse clients who look at the YAML/JSON for diffs.
From a UX point of view, I am much more concerned with YAML/JSON readability wrt the fields we know exist. I don't think Go's standard JSON supports any sort of thing here, but something like keeping the field ordering when rendering is what I was thinking
from kubernetes.
OK, the reason for sorting conditions by lastTransitionTime
is that the user can know what's happening based on the timeline, which may help the user understand the entire startup process of the pod. If you think you're worried about something else, let's focus on sorting the fields first.
from kubernetes.
I believe this happens because of how json.Marshal
is implemented.
Could this be where the alphabetical field sorting is being done?
https://github.com/golang/go/blob/0253c0f4acdf9f7a2930609f55d24b334fa7d3c2/src/encoding/json/encode.go#L1186-L1203
slices.SortFunc(fields, func(a, b field) int {
// sort field by name, breaking ties with depth, then
// breaking ties with "name came from json tag", then
// breaking ties with index sequence.
if c := strings.Compare(a.name, b.name); c != 0 {
return c
}
if c := cmp.Compare(len(a.index), len(b.index)); c != 0 {
return c
}
if a.tag != b.tag {
if a.tag {
return -1
}
return +1
}
return slices.Compare(a.index, b.index)
})
Maybe this could be extended to optionally support the specification of an order in the struct field's json tag...
from kubernetes.
Note that we emit both JSON and YAML (and maybe others but they matter less?)
from kubernetes.
Yeah, it could be a problem in both places, but the yaml printer uses the same json.Marshal
and then converts the json to yaml as a second step.
from kubernetes.
Actually it is in kubernetes' yaml package (used by the printer) where it first marshals to JSON, then converts to YAML.
kubernetes/vendor/sigs.k8s.io/yaml/yaml.go
Lines 30 to 38 in 04cc45b
from kubernetes.
I did a test and I think I was wrong. json.MarshalIndent
and json.Marshal
seem to use whatever field order you define in the struct.
Example:
package main
import "encoding/json"
type Example struct {
Foo string `json:"foo"`
Bar int `json:"bar"`
}
func main() {
examples := []Example{
{"Test1", 1},
{"Test2", 2},
{"Test3", 3},
}
result, err := json.MarshalIndent(examples, "", " ")
if err != nil {
panic(err)
}
println(string(result))
}
Output:
[
{
"foo": "Test1",
"bar": 1
},
{
"foo": "Test2",
"bar": 2
},
{
"foo": "Test3",
"bar": 3
}
]
Go version 1.23.0
I guess I will dig a little deeper... 👀
Ah, further down in the code, it sorts the fields again, this time by index, which I guess is what produces the output in the field order.
slices.SortFunc(fields, func(i, j field) int {
return slices.Compare(i.index, j.index)
})
So I guess there has to be something in kubectl that is causing the fields to show up alphabetically. Maybe it is unmarshaled into a map at some point...
from kubernetes.
Related Issues (20)
- Kubernetes mounts a pod to local file system HOT 4
- tokenfile path is hardcoded in the config.go HOT 20
- Explicit version specification in go directive fouling corporate Snyk scans HOT 12
- `kubectl wait --for=jsonpath='{.status.readyReplicas}'=1` fails in 1.31.0-rc.1 HOT 3
- kube-scheduler updates pod status mistakenly during preemption HOT 7
- Status cannot be changed via pod patching HOT 4
- Get "invalid configuration: unable to read certificate-authority " error with clientcmd.RESTConfigFromKubeConfig function HOT 4
- Pod status phase misses Pending transition after node reboot HOT 8
- ResourceSliceList object has `listMeta` field instead of `metadata` field HOT 11
- Pkgs.k8s.io repository for Red Hat based distributions for the latest release 1.31.0 has dependency issue! HOT 8
- QosClass of pod status shouldn't be changeable HOT 4
- kube-apiserver and other components no longer honor --version build ID overrides HOT 3
- Fake client returns unexpected results on errors since 1.31 HOT 8
- Compromised container can trigger OOM with `kubectl cp` HOT 10
- Andoka Cloud HOT 4
- The pod initialization container initcontainers returns No space left on device HOT 6
- [kubelet] Pod is deleted due to Node not ready, deletions is cancelled, kubelet is not aware container is not running HOT 3
- Container network metrics missing with kubelet 1.30 and crio-1.30 HOT 7
- Emulation version: Remove hard coded DefaultKubeBinaryVersion value. HOT 3
- [Bug] Scheduler fails to schedule a pod due to a race condition HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kubernetes.