resources.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package format
  14. import (
  15. "fmt"
  16. "sort"
  17. "strings"
  18. "k8s.io/kubernetes/pkg/api"
  19. )
  20. // ResourceList returns a string representation of a resource list in a human readable format.
  21. func ResourceList(resources api.ResourceList) string {
  22. resourceStrings := make([]string, 0, len(resources))
  23. for key, value := range resources {
  24. resourceStrings = append(resourceStrings, fmt.Sprintf("%v=%v", key, value.String()))
  25. }
  26. // sort the results for consistent log output
  27. sort.Strings(resourceStrings)
  28. return strings.Join(resourceStrings, ",")
  29. }