interface.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright 2018 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 describe
  14. import (
  15. "fmt"
  16. "k8s.io/apimachinery/pkg/api/meta"
  17. "k8s.io/cli-runtime/pkg/genericclioptions"
  18. )
  19. const (
  20. // LoadBalancerWidth is the width how we describe load balancer
  21. LoadBalancerWidth = 16
  22. // LabelNodeRolePrefix is a label prefix for node roles
  23. // It's copied over to here until it's merged in core: https://github.com/kubernetes/kubernetes/pull/39112
  24. LabelNodeRolePrefix = "node-role.kubernetes.io/"
  25. // NodeLabelRole specifies the role of a node
  26. NodeLabelRole = "kubernetes.io/role"
  27. )
  28. // DescriberFunc gives a way to display the specified RESTMapping type
  29. type DescriberFunc func(restClientGetter genericclioptions.RESTClientGetter, mapping *meta.RESTMapping) (Describer, error)
  30. // Describer generates output for the named resource or an error
  31. // if the output could not be generated. Implementers typically
  32. // abstract the retrieval of the named object from a remote server.
  33. type Describer interface {
  34. Describe(namespace, name string, describerSettings DescriberSettings) (output string, err error)
  35. }
  36. // DescriberSettings holds display configuration for each object
  37. // describer to control what is printed.
  38. type DescriberSettings struct {
  39. ShowEvents bool
  40. }
  41. // ObjectDescriber is an interface for displaying arbitrary objects with extra
  42. // information. Use when an object is in hand (on disk, or already retrieved).
  43. // Implementers may ignore the additional information passed on extra, or use it
  44. // by default. ObjectDescribers may return ErrNoDescriber if no suitable describer
  45. // is found.
  46. type ObjectDescriber interface {
  47. DescribeObject(object interface{}, extra ...interface{}) (output string, err error)
  48. }
  49. // ErrNoDescriber is a structured error indicating the provided object or objects
  50. // cannot be described.
  51. type ErrNoDescriber struct {
  52. Types []string
  53. }
  54. // Error implements the error interface.
  55. func (e ErrNoDescriber) Error() string {
  56. return fmt.Sprintf("no describer has been defined for %v", e.Types)
  57. }