item.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Copyright 2017 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 parse
  14. import (
  15. "k8s.io/kube-openapi/pkg/util/proto"
  16. "k8s.io/kubernetes/pkg/kubectl/apply"
  17. )
  18. // Item wraps values from 3 sources (recorded, local, remote).
  19. // The values are not collated
  20. type Item interface {
  21. // CreateElement merges the values in the item into a combined Element
  22. CreateElement(ItemVisitor) (apply.Element, error)
  23. }
  24. // primitiveItem contains a recorded, local, and remote value
  25. type primitiveItem struct {
  26. Name string
  27. Primitive *proto.Primitive
  28. apply.RawElementData
  29. }
  30. func (i *primitiveItem) CreateElement(v ItemVisitor) (apply.Element, error) {
  31. return v.CreatePrimitiveElement(i)
  32. }
  33. func (i *primitiveItem) GetMeta() proto.Schema {
  34. // https://golang.org/doc/faq#nil_error
  35. if i.Primitive != nil {
  36. return i.Primitive
  37. }
  38. return nil
  39. }
  40. // listItem contains a recorded, local, and remote list
  41. type listItem struct {
  42. Name string
  43. Array *proto.Array
  44. apply.ListElementData
  45. }
  46. func (i *listItem) CreateElement(v ItemVisitor) (apply.Element, error) {
  47. return v.CreateListElement(i)
  48. }
  49. func (i *listItem) GetMeta() proto.Schema {
  50. // https://golang.org/doc/faq#nil_error
  51. if i.Array != nil {
  52. return i.Array
  53. }
  54. return nil
  55. }
  56. // mapItem contains a recorded, local, and remote map
  57. type mapItem struct {
  58. Name string
  59. Map *proto.Map
  60. apply.MapElementData
  61. }
  62. func (i *mapItem) CreateElement(v ItemVisitor) (apply.Element, error) {
  63. return v.CreateMapElement(i)
  64. }
  65. func (i *mapItem) GetMeta() proto.Schema {
  66. // https://golang.org/doc/faq#nil_error
  67. if i.Map != nil {
  68. return i.Map
  69. }
  70. return nil
  71. }
  72. // mapItem contains a recorded, local, and remote map
  73. type typeItem struct {
  74. Name string
  75. Type *proto.Kind
  76. apply.MapElementData
  77. }
  78. func (i *typeItem) GetMeta() proto.Schema {
  79. // https://golang.org/doc/faq#nil_error
  80. if i.Type != nil {
  81. return i.Type
  82. }
  83. return nil
  84. }
  85. func (i *typeItem) CreateElement(v ItemVisitor) (apply.Element, error) {
  86. return v.CreateTypeElement(i)
  87. }
  88. // emptyItem contains no values
  89. type emptyItem struct {
  90. Name string
  91. }
  92. func (i *emptyItem) CreateElement(v ItemVisitor) (apply.Element, error) {
  93. e := &apply.EmptyElement{}
  94. e.Name = i.Name
  95. return e, nil
  96. }