|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package testing |
| 18 | + |
| 19 | +import ( |
| 20 | + "k8s.io/apimachinery/pkg/conversion" |
| 21 | + "k8s.io/apimachinery/pkg/runtime" |
| 22 | +) |
| 23 | + |
| 24 | +func convertTestType1ToExternalTestType1(in *TestType1, out *ExternalTestType1, s conversion.Scope) error { |
| 25 | + out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField |
| 26 | + out.A = in.A |
| 27 | + out.B = in.B |
| 28 | + out.C = in.C |
| 29 | + out.D = in.D |
| 30 | + out.E = in.E |
| 31 | + out.F = in.F |
| 32 | + out.G = in.G |
| 33 | + out.H = in.H |
| 34 | + out.I = in.I |
| 35 | + out.J = in.J |
| 36 | + out.K = in.K |
| 37 | + out.L = in.L |
| 38 | + out.M = in.M |
| 39 | + if in.N != nil { |
| 40 | + out.N = make(map[string]ExternalTestType2) |
| 41 | + for key := range in.N { |
| 42 | + in, tmp := in.N[key], ExternalTestType2{} |
| 43 | + if err := convertTestType2ToExternalTestType2(&in, &tmp, s); err != nil { |
| 44 | + return err |
| 45 | + } |
| 46 | + out.N[key] = tmp |
| 47 | + } |
| 48 | + } else { |
| 49 | + out.N = nil |
| 50 | + } |
| 51 | + if in.O != nil { |
| 52 | + out.O = new(ExternalTestType2) |
| 53 | + if err := convertTestType2ToExternalTestType2(in.O, out.O, s); err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + } else { |
| 57 | + out.O = nil |
| 58 | + } |
| 59 | + if in.P != nil { |
| 60 | + out.P = make([]ExternalTestType2, len(in.P)) |
| 61 | + for i := range in.P { |
| 62 | + if err := convertTestType2ToExternalTestType2(&in.P[i], &out.P[i], s); err != nil { |
| 63 | + return err |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + return nil |
| 68 | +} |
| 69 | + |
| 70 | +func convertExternalTestType1ToTestType1(in *ExternalTestType1, out *TestType1, s conversion.Scope) error { |
| 71 | + out.MyWeirdCustomEmbeddedVersionKindField = in.MyWeirdCustomEmbeddedVersionKindField |
| 72 | + out.A = in.A |
| 73 | + out.B = in.B |
| 74 | + out.C = in.C |
| 75 | + out.D = in.D |
| 76 | + out.E = in.E |
| 77 | + out.F = in.F |
| 78 | + out.G = in.G |
| 79 | + out.H = in.H |
| 80 | + out.I = in.I |
| 81 | + out.J = in.J |
| 82 | + out.K = in.K |
| 83 | + out.L = in.L |
| 84 | + out.M = in.M |
| 85 | + if in.N != nil { |
| 86 | + out.N = make(map[string]TestType2) |
| 87 | + for key := range in.N { |
| 88 | + in, tmp := in.N[key], TestType2{} |
| 89 | + if err := convertExternalTestType2ToTestType2(&in, &tmp, s); err != nil { |
| 90 | + return err |
| 91 | + } |
| 92 | + out.N[key] = tmp |
| 93 | + } |
| 94 | + } else { |
| 95 | + out.N = nil |
| 96 | + } |
| 97 | + if in.O != nil { |
| 98 | + out.O = new(TestType2) |
| 99 | + if err := convertExternalTestType2ToTestType2(in.O, out.O, s); err != nil { |
| 100 | + return err |
| 101 | + } |
| 102 | + } else { |
| 103 | + out.O = nil |
| 104 | + } |
| 105 | + if in.P != nil { |
| 106 | + out.P = make([]TestType2, len(in.P)) |
| 107 | + for i := range in.P { |
| 108 | + if err := convertExternalTestType2ToTestType2(&in.P[i], &out.P[i], s); err != nil { |
| 109 | + return err |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + return nil |
| 114 | +} |
| 115 | + |
| 116 | +func convertTestType2ToExternalTestType2(in *TestType2, out *ExternalTestType2, s conversion.Scope) error { |
| 117 | + out.A = in.A |
| 118 | + out.B = in.B |
| 119 | + return nil |
| 120 | +} |
| 121 | + |
| 122 | +func convertExternalTestType2ToTestType2(in *ExternalTestType2, out *TestType2, s conversion.Scope) error { |
| 123 | + out.A = in.A |
| 124 | + out.B = in.B |
| 125 | + return nil |
| 126 | +} |
| 127 | + |
| 128 | +func RegisterConversions(s *runtime.Scheme) error { |
| 129 | + if err := s.AddConversionFunc((*TestType1)(nil), (*ExternalTestType1)(nil), func(a, b interface{}, scope conversion.Scope) error { |
| 130 | + return convertTestType1ToExternalTestType1(a.(*TestType1), b.(*ExternalTestType1), scope) |
| 131 | + }); err != nil { |
| 132 | + return err |
| 133 | + } |
| 134 | + if err := s.AddConversionFunc((*ExternalTestType1)(nil), (*TestType1)(nil), func(a, b interface{}, scope conversion.Scope) error { |
| 135 | + return convertExternalTestType1ToTestType1(a.(*ExternalTestType1), b.(*TestType1), scope) |
| 136 | + }); err != nil { |
| 137 | + return err |
| 138 | + } |
| 139 | + if err := s.AddConversionFunc((*TestType2)(nil), (*ExternalTestType2)(nil), func(a, b interface{}, scope conversion.Scope) error { |
| 140 | + return convertTestType2ToExternalTestType2(a.(*TestType2), b.(*ExternalTestType2), scope) |
| 141 | + }); err != nil { |
| 142 | + return err |
| 143 | + } |
| 144 | + if err := s.AddConversionFunc((*ExternalTestType2)(nil), (*TestType2)(nil), func(a, b interface{}, scope conversion.Scope) error { |
| 145 | + return convertExternalTestType2ToTestType2(a.(*ExternalTestType2), b.(*TestType2), scope) |
| 146 | + }); err != nil { |
| 147 | + return err |
| 148 | + } |
| 149 | + return nil |
| 150 | +} |
0 commit comments