Skip to content
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

Fixed statefulset PVC's capacity in kubectl description. #47573

Merged
merged 1 commit into from Jun 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/printers/internalversion/describe.go
Expand Up @@ -1382,7 +1382,7 @@ func describeVolumeClaimTemplates(templates []api.PersistentVolumeClaim, w Prefi
printLabelsMultilineWithIndent(w, " ", "Labels", "\t", pvc.Labels, sets.NewString())
printLabelsMultilineWithIndent(w, " ", "Annotations", "\t", pvc.Annotations, sets.NewString())
if capacity, ok := pvc.Spec.Resources.Requests[api.ResourceStorage]; ok {
w.Write(LEVEL_1, "Capacity:\t%s\n", capacity)
w.Write(LEVEL_1, "Capacity:\t%s\n", capacity.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

a better way is to change %s to %v.

Copy link
Member Author

Choose a reason for hiding this comment

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

%v will not work :(. Here's the output of %v:

  Capacity:	{{1073741824 0} {<nil>} 1Gi BinarySI}

When we print an object by %s in go, it'll call object's String(); but Quantity.String() is using pointer (for caching string), we have to call it explicitly.

Should be func (q Quantity) String() string not func (q *Quantity) String() string at https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go#L608 .

Copy link
Contributor

Choose a reason for hiding this comment

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

you are right. probably worth fix the stringer interface thing. it just looks strange to explicitly call x.String()

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. According to the comments, it use (q *Quantity) String() for caching string, not sure the performance impact (e.g. build string every time); prefer to open an issue to trace it :).

Copy link
Contributor

Choose a reason for hiding this comment

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

sgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

#47585 to trace the discussion.

} else {
w.Write(LEVEL_1, "Capacity:\t%s\n", "<default>")
}
Expand Down