conversion.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. Copyright 2014 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 v1
  14. import (
  15. "fmt"
  16. "sort"
  17. "k8s.io/apimachinery/pkg/conversion"
  18. "k8s.io/apimachinery/pkg/runtime"
  19. "k8s.io/client-go/tools/clientcmd/api"
  20. )
  21. func Convert_Slice_v1_NamedCluster_To_Map_string_To_Pointer_api_Cluster(in *[]NamedCluster, out *map[string]*api.Cluster, s conversion.Scope) error {
  22. for _, curr := range *in {
  23. newCluster := api.NewCluster()
  24. if err := Convert_v1_Cluster_To_api_Cluster(&curr.Cluster, newCluster, s); err != nil {
  25. return err
  26. }
  27. if *out == nil {
  28. *out = make(map[string]*api.Cluster)
  29. }
  30. if (*out)[curr.Name] == nil {
  31. (*out)[curr.Name] = newCluster
  32. } else {
  33. return fmt.Errorf("error converting *[]NamedCluster into *map[string]*api.Cluster: duplicate name \"%v\" in list: %v", curr.Name, *in)
  34. }
  35. }
  36. return nil
  37. }
  38. func Convert_Map_string_To_Pointer_api_Cluster_To_Slice_v1_NamedCluster(in *map[string]*api.Cluster, out *[]NamedCluster, s conversion.Scope) error {
  39. allKeys := make([]string, 0, len(*in))
  40. for key := range *in {
  41. allKeys = append(allKeys, key)
  42. }
  43. sort.Strings(allKeys)
  44. for _, key := range allKeys {
  45. newCluster := (*in)[key]
  46. oldCluster := Cluster{}
  47. if err := Convert_api_Cluster_To_v1_Cluster(newCluster, &oldCluster, s); err != nil {
  48. return err
  49. }
  50. namedCluster := NamedCluster{key, oldCluster}
  51. *out = append(*out, namedCluster)
  52. }
  53. return nil
  54. }
  55. func Convert_Slice_v1_NamedAuthInfo_To_Map_string_To_Pointer_api_AuthInfo(in *[]NamedAuthInfo, out *map[string]*api.AuthInfo, s conversion.Scope) error {
  56. for _, curr := range *in {
  57. newAuthInfo := api.NewAuthInfo()
  58. if err := Convert_v1_AuthInfo_To_api_AuthInfo(&curr.AuthInfo, newAuthInfo, s); err != nil {
  59. return err
  60. }
  61. if *out == nil {
  62. *out = make(map[string]*api.AuthInfo)
  63. }
  64. if (*out)[curr.Name] == nil {
  65. (*out)[curr.Name] = newAuthInfo
  66. } else {
  67. return fmt.Errorf("error converting *[]NamedAuthInfo into *map[string]*api.AuthInfo: duplicate name \"%v\" in list: %v", curr.Name, *in)
  68. }
  69. }
  70. return nil
  71. }
  72. func Convert_Map_string_To_Pointer_api_AuthInfo_To_Slice_v1_NamedAuthInfo(in *map[string]*api.AuthInfo, out *[]NamedAuthInfo, s conversion.Scope) error {
  73. allKeys := make([]string, 0, len(*in))
  74. for key := range *in {
  75. allKeys = append(allKeys, key)
  76. }
  77. sort.Strings(allKeys)
  78. for _, key := range allKeys {
  79. newAuthInfo := (*in)[key]
  80. oldAuthInfo := AuthInfo{}
  81. if err := Convert_api_AuthInfo_To_v1_AuthInfo(newAuthInfo, &oldAuthInfo, s); err != nil {
  82. return err
  83. }
  84. namedAuthInfo := NamedAuthInfo{key, oldAuthInfo}
  85. *out = append(*out, namedAuthInfo)
  86. }
  87. return nil
  88. }
  89. func Convert_Slice_v1_NamedContext_To_Map_string_To_Pointer_api_Context(in *[]NamedContext, out *map[string]*api.Context, s conversion.Scope) error {
  90. for _, curr := range *in {
  91. newContext := api.NewContext()
  92. if err := Convert_v1_Context_To_api_Context(&curr.Context, newContext, s); err != nil {
  93. return err
  94. }
  95. if *out == nil {
  96. *out = make(map[string]*api.Context)
  97. }
  98. if (*out)[curr.Name] == nil {
  99. (*out)[curr.Name] = newContext
  100. } else {
  101. return fmt.Errorf("error converting *[]NamedContext into *map[string]*api.Context: duplicate name \"%v\" in list: %v", curr.Name, *in)
  102. }
  103. }
  104. return nil
  105. }
  106. func Convert_Map_string_To_Pointer_api_Context_To_Slice_v1_NamedContext(in *map[string]*api.Context, out *[]NamedContext, s conversion.Scope) error {
  107. allKeys := make([]string, 0, len(*in))
  108. for key := range *in {
  109. allKeys = append(allKeys, key)
  110. }
  111. sort.Strings(allKeys)
  112. for _, key := range allKeys {
  113. newContext := (*in)[key]
  114. oldContext := Context{}
  115. if err := Convert_api_Context_To_v1_Context(newContext, &oldContext, s); err != nil {
  116. return err
  117. }
  118. namedContext := NamedContext{key, oldContext}
  119. *out = append(*out, namedContext)
  120. }
  121. return nil
  122. }
  123. func Convert_Slice_v1_NamedExtension_To_Map_string_To_runtime_Object(in *[]NamedExtension, out *map[string]runtime.Object, s conversion.Scope) error {
  124. for _, curr := range *in {
  125. var newExtension runtime.Object
  126. if err := runtime.Convert_runtime_RawExtension_To_runtime_Object(&curr.Extension, &newExtension, s); err != nil {
  127. return err
  128. }
  129. if *out == nil {
  130. *out = make(map[string]runtime.Object)
  131. }
  132. if (*out)[curr.Name] == nil {
  133. (*out)[curr.Name] = newExtension
  134. } else {
  135. return fmt.Errorf("error converting *[]NamedExtension into *map[string]runtime.Object: duplicate name \"%v\" in list: %v", curr.Name, *in)
  136. }
  137. }
  138. return nil
  139. }
  140. func Convert_Map_string_To_runtime_Object_To_Slice_v1_NamedExtension(in *map[string]runtime.Object, out *[]NamedExtension, s conversion.Scope) error {
  141. allKeys := make([]string, 0, len(*in))
  142. for key := range *in {
  143. allKeys = append(allKeys, key)
  144. }
  145. sort.Strings(allKeys)
  146. for _, key := range allKeys {
  147. newExtension := (*in)[key]
  148. oldExtension := runtime.RawExtension{}
  149. if err := runtime.Convert_runtime_Object_To_runtime_RawExtension(&newExtension, &oldExtension, s); err != nil {
  150. return err
  151. }
  152. namedExtension := NamedExtension{key, oldExtension}
  153. *out = append(*out, namedExtension)
  154. }
  155. return nil
  156. }