Skip to content

Commit 20f6545

Browse files
author
Antoine Pelisse
committed
Rename "Interface" into "Unstructured"
Interface can mean too many things, while unstructured has this kubernetes meaning of "map[string]interface{}" types of objects.
1 parent bc29f6d commit 20f6545

File tree

10 files changed

+53
-53
lines changed

10 files changed

+53
-53
lines changed

internal/cli/operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (m merge) Execute(w io.Writer) error {
114114
return err
115115
}
116116

117-
yaml, err := yaml.Marshal(out.AsValue().Interface())
117+
yaml, err := yaml.Marshal(out.AsValue().Unstructured())
118118
if err != nil {
119119
return err
120120
}

merge/multiple_appliers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ func (r repeatingConverter) Convert(v *typed.TypedValue, version fieldpath.APIVe
985985
if err != nil {
986986
return nil, missingVersionError
987987
}
988-
y, err := yaml.Marshal(v.AsValue().Interface())
988+
y, err := yaml.Marshal(v.AsValue().Unstructured())
989989
if err != nil {
990990
return nil, err
991991
}

typed/merge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ type mergeRule func(w *mergingWalker)
5858
var (
5959
ruleKeepRHS = mergeRule(func(w *mergingWalker) {
6060
if w.rhs != nil {
61-
v := w.rhs.Interface()
61+
v := w.rhs.Unstructured()
6262
w.out = &v
6363
} else if w.lhs != nil {
64-
v := w.lhs.Interface()
64+
v := w.lhs.Unstructured()
6565
w.out = &v
6666
}
6767
})

typed/remove.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func removeItemsWithSchema(val value.Value, toRemove *fieldpath.Set, schema *sch
3737
}
3838

3939
func (w *removingWalker) doScalar(t *schema.Scalar) ValidationErrors {
40-
w.out = w.value.Interface()
40+
w.out = w.value.Unstructured()
4141
return nil
4242
}
4343

@@ -61,7 +61,7 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
6161
if subset := w.toRemove.WithPrefix(pe); !subset.Empty() {
6262
item = removeItemsWithSchema(item, subset, w.schema, t.ElementType)
6363
}
64-
newItems = append(newItems, item.Interface())
64+
newItems = append(newItems, item.Unstructured())
6565
}
6666
if len(newItems) > 0 {
6767
w.out = newItems
@@ -97,7 +97,7 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
9797
if subset := w.toRemove.WithPrefix(pe); !subset.Empty() {
9898
val = removeItemsWithSchema(val, subset, w.schema, fieldType)
9999
}
100-
newMap[k] = val.Interface()
100+
newMap[k] = val.Unstructured()
101101
return true
102102
})
103103
if len(newMap) > 0 {

typed/typed.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (tv TypedValue) NormalizeUnions(new *TypedValue) (*TypedValue, error) {
158158
var errs ValidationErrors
159159
var normalizeFn = func(w *mergingWalker) {
160160
if w.rhs != nil {
161-
v := w.rhs.Interface()
161+
v := w.rhs.Unstructured()
162162
w.out = &v
163163
}
164164
if err := normalizeUnions(w); err != nil {
@@ -184,7 +184,7 @@ func (tv TypedValue) NormalizeUnionsApply(new *TypedValue) (*TypedValue, error)
184184
var errs ValidationErrors
185185
var normalizeFn = func(w *mergingWalker) {
186186
if w.rhs != nil {
187-
v := w.rhs.Interface()
187+
v := w.rhs.Unstructured()
188188
w.out = &v
189189
}
190190
if err := normalizeUnionsApply(w); err != nil {

typed/union.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func normalizeUnionsApply(w *mergingWalker) error {
6666
if err := newUnion(&union).NormalizeApply(old, w.rhs.Map(), out.Map()); err != nil {
6767
return err
6868
}
69-
*w.out = out.Interface()
69+
*w.out = out.Unstructured()
7070
}
7171
return nil
7272
}

value/listinterface.go renamed to value/listunstructured.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ limitations under the License.
1616

1717
package value
1818

19-
type listInterface []interface{}
19+
type listUnstructured []interface{}
2020

21-
func (l listInterface) Length() int {
21+
func (l listUnstructured) Length() int {
2222
return len(l)
2323
}
2424

25-
func (l listInterface) At(i int) Value {
25+
func (l listUnstructured) At(i int) Value {
2626
return NewValueInterface(l[i])
2727
}

value/mapinterface.go renamed to value/mapunstructured.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ limitations under the License.
1616

1717
package value
1818

19-
type mapInterface map[interface{}]interface{}
19+
type mapUnstructuredInterface map[interface{}]interface{}
2020

21-
func (m mapInterface) Set(key string, val Value) {
22-
m[key] = val.Interface()
21+
func (m mapUnstructuredInterface) Set(key string, val Value) {
22+
m[key] = val.Unstructured()
2323
}
2424

25-
func (m mapInterface) Get(key string) (Value, bool) {
25+
func (m mapUnstructuredInterface) Get(key string) (Value, bool) {
2626
if v, ok := m[key]; !ok {
2727
return nil, false
2828
} else {
2929
return NewValueInterface(v), true
3030
}
3131
}
3232

33-
func (m mapInterface) Delete(key string) {
33+
func (m mapUnstructuredInterface) Delete(key string) {
3434
delete(m, key)
3535
}
3636

37-
func (m mapInterface) Iterate(fn func(key string, value Value) bool) bool {
37+
func (m mapUnstructuredInterface) Iterate(fn func(key string, value Value) bool) bool {
3838
for k, v := range m {
3939
if ks, ok := k.(string); !ok {
4040
continue
@@ -50,11 +50,11 @@ func (m mapInterface) Iterate(fn func(key string, value Value) bool) bool {
5050
return true
5151
}
5252

53-
func (m mapInterface) Length() int {
53+
func (m mapUnstructuredInterface) Length() int {
5454
return len(m)
5555
}
5656

57-
func (m mapInterface) Equals(other Map) bool {
57+
func (m mapUnstructuredInterface) Equals(other Map) bool {
5858
if m.Length() != other.Length() {
5959
return false
6060
}
@@ -79,25 +79,25 @@ func (m mapInterface) Equals(other Map) bool {
7979
return true
8080
}
8181

82-
type mapString map[string]interface{}
82+
type mapUnstructuredString map[string]interface{}
8383

84-
func (m mapString) Set(key string, val Value) {
85-
m[key] = val.Interface()
84+
func (m mapUnstructuredString) Set(key string, val Value) {
85+
m[key] = val.Unstructured()
8686
}
8787

88-
func (m mapString) Get(key string) (Value, bool) {
88+
func (m mapUnstructuredString) Get(key string) (Value, bool) {
8989
if v, ok := m[key]; !ok {
9090
return nil, false
9191
} else {
9292
return NewValueInterface(v), true
9393
}
9494
}
9595

96-
func (m mapString) Delete(key string) {
96+
func (m mapUnstructuredString) Delete(key string) {
9797
delete(m, key)
9898
}
9999

100-
func (m mapString) Iterate(fn func(key string, value Value) bool) bool {
100+
func (m mapUnstructuredString) Iterate(fn func(key string, value Value) bool) bool {
101101
for k, v := range m {
102102
vv := NewValueInterface(v)
103103
if !fn(k, vv) {
@@ -109,11 +109,11 @@ func (m mapString) Iterate(fn func(key string, value Value) bool) bool {
109109
return true
110110
}
111111

112-
func (m mapString) Length() int {
112+
func (m mapUnstructuredString) Length() int {
113113
return len(m)
114114
}
115115

116-
func (m mapString) Equals(other Map) bool {
116+
func (m mapUnstructuredString) Equals(other Map) bool {
117117
if m.Length() != other.Length() {
118118
return false
119119
}

value/value.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ type Value interface {
7272
// value shouldn't be used after this call.
7373
Recycle()
7474

75-
// Converts the Value into an interface{}.
76-
Interface() interface{}
75+
// Converts the Value into an Unstructured interface{}.
76+
Unstructured() interface{}
7777
}
7878

7979
// FromJSON is a helper function for reading a JSON document.
@@ -115,7 +115,7 @@ func ReadJSONIter(iter *jsoniter.Iterator) (Value, error) {
115115

116116
// WriteJSONStream writes a value into a JSON stream.
117117
func WriteJSONStream(v Value, stream *jsoniter.Stream) {
118-
stream.WriteVal(v.Interface())
118+
stream.WriteVal(v.Unstructured())
119119
}
120120

121121
// Equals returns true iff the two values are equal.

value/valueinterface.go renamed to value/valueunstructured.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ import (
2323

2424
var viPool = sync.Pool{
2525
New: func() interface{} {
26-
return &valueInterface{}
26+
return &valueUnstructured{}
2727
},
2828
}
2929

3030
// NewValueInterface creates a Value backed by an "interface{}" type,
3131
// typically an unstructured object in Kubernetes world.
3232
func NewValueInterface(v interface{}) Value {
33-
vi := viPool.Get().(*valueInterface)
33+
vi := viPool.Get().(*valueUnstructured)
3434
vi.Value = v
3535
return Value(vi)
3636
}
3737

38-
type valueInterface struct {
38+
type valueUnstructured struct {
3939
Value interface{}
4040
}
4141

42-
func (v valueInterface) IsMap() bool {
42+
func (v valueUnstructured) IsMap() bool {
4343
if _, ok := v.Value.(map[string]interface{}); ok {
4444
return true
4545
}
@@ -49,32 +49,32 @@ func (v valueInterface) IsMap() bool {
4949
return false
5050
}
5151

52-
func (v valueInterface) Map() Map {
52+
func (v valueUnstructured) Map() Map {
5353
if v.Value == nil {
5454
return nil
5555
}
5656
switch t := v.Value.(type) {
5757
case map[string]interface{}:
58-
return mapString(t)
58+
return mapUnstructuredString(t)
5959
case map[interface{}]interface{}:
60-
return mapInterface(t)
60+
return mapUnstructuredInterface(t)
6161
}
6262
panic(fmt.Errorf("not a map: %#v", v))
6363
}
6464

65-
func (v valueInterface) IsList() bool {
65+
func (v valueUnstructured) IsList() bool {
6666
if v.Value == nil {
6767
return false
6868
}
6969
_, ok := v.Value.([]interface{})
7070
return ok
7171
}
7272

73-
func (v valueInterface) List() List {
74-
return listInterface(v.Value.([]interface{}))
73+
func (v valueUnstructured) List() List {
74+
return listUnstructured(v.Value.([]interface{}))
7575
}
7676

77-
func (v valueInterface) IsFloat() bool {
77+
func (v valueUnstructured) IsFloat() bool {
7878
if v.Value == nil {
7979
return false
8080
} else if _, ok := v.Value.(float64); ok {
@@ -85,14 +85,14 @@ func (v valueInterface) IsFloat() bool {
8585
return false
8686
}
8787

88-
func (v valueInterface) Float() float64 {
88+
func (v valueUnstructured) Float() float64 {
8989
if f, ok := v.Value.(float32); ok {
9090
return float64(f)
9191
}
9292
return v.Value.(float64)
9393
}
9494

95-
func (v valueInterface) IsInt() bool {
95+
func (v valueUnstructured) IsInt() bool {
9696
if v.Value == nil {
9797
return false
9898
} else if _, ok := v.Value.(int); ok {
@@ -117,7 +117,7 @@ func (v valueInterface) IsInt() bool {
117117
return false
118118
}
119119

120-
func (v valueInterface) Int() int64 {
120+
func (v valueUnstructured) Int() int64 {
121121
if i, ok := v.Value.(int); ok {
122122
return int64(i)
123123
} else if i, ok := v.Value.(int8); ok {
@@ -138,38 +138,38 @@ func (v valueInterface) Int() int64 {
138138
return v.Value.(int64)
139139
}
140140

141-
func (v valueInterface) IsString() bool {
141+
func (v valueUnstructured) IsString() bool {
142142
if v.Value == nil {
143143
return false
144144
}
145145
_, ok := v.Value.(string)
146146
return ok
147147
}
148148

149-
func (v valueInterface) String() string {
149+
func (v valueUnstructured) String() string {
150150
return v.Value.(string)
151151
}
152152

153-
func (v valueInterface) IsBool() bool {
153+
func (v valueUnstructured) IsBool() bool {
154154
if v.Value == nil {
155155
return false
156156
}
157157
_, ok := v.Value.(bool)
158158
return ok
159159
}
160160

161-
func (v valueInterface) Bool() bool {
161+
func (v valueUnstructured) Bool() bool {
162162
return v.Value.(bool)
163163
}
164164

165-
func (v valueInterface) IsNull() bool {
165+
func (v valueUnstructured) IsNull() bool {
166166
return v.Value == nil
167167
}
168168

169-
func (v *valueInterface) Recycle() {
169+
func (v *valueUnstructured) Recycle() {
170170
viPool.Put(v)
171171
}
172172

173-
func (v valueInterface) Interface() interface{} {
173+
func (v valueUnstructured) Unstructured() interface{} {
174174
return v.Value
175175
}

0 commit comments

Comments
 (0)