-
Notifications
You must be signed in to change notification settings - Fork 458
/
v1alpha1_unstructured.go
65 lines (51 loc) · 1.4 KB
/
v1alpha1_unstructured.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package v1alpha1
import (
"fmt"
)
// Unstructured allows wrapping any map[string]interface{} into a config object.
//
// docgen: nodoc
// +k8s:deepcopy-gen=true
type Unstructured struct {
Object map[string]interface{} `yaml:",inline"`
}
// DeepCopy performs copying of the Object contents.
func (in *Unstructured) DeepCopy() *Unstructured {
if in == nil {
return nil
}
out := new(Unstructured)
out.Object = deepCopyUnstructured(in.Object).(map[string]interface{}) //nolint:errcheck,forcetypeassert
return out
}
func deepCopyUnstructured(x interface{}) interface{} {
switch x := x.(type) {
case map[string]interface{}:
if x == nil {
return x
}
clone := make(map[string]interface{}, len(x))
for k, v := range x {
clone[k] = deepCopyUnstructured(v)
}
return clone
case []interface{}:
if x == nil {
return x
}
clone := make([]interface{}, len(x))
for i, v := range x {
clone[i] = deepCopyUnstructured(v)
}
return clone
case string, bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, complex64, complex128, nil:
return x
case []byte:
return append([]byte(nil), x...)
default:
panic(fmt.Errorf("cannot deep copy %T", x))
}
}