Skip to content

Commit d43a45b

Browse files
authored
Merge pull request #53 from apelisse/remove-hardcoded-version
Remove hard-coded version number
2 parents d45b5c3 + 0483b06 commit d43a45b

File tree

4 files changed

+73
-46
lines changed

4 files changed

+73
-46
lines changed

internal/fixture/state.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ func (s *State) checkInit() error {
9797
}
9898

9999
// Update the current state with the passed in object
100-
func (s *State) Update(obj typed.YAMLObject, manager string) error {
100+
func (s *State) Update(obj typed.YAMLObject, version fieldpath.APIVersion, manager string) error {
101101
obj = FixTabsOrDie(obj)
102102
if err := s.checkInit(); err != nil {
103103
return err
104104
}
105105
tv, err := s.Parser.FromYAML(obj)
106-
managers, err := s.Updater.Update(*s.Live, tv, s.Managers, manager)
106+
managers, err := s.Updater.Update(*s.Live, tv, version, s.Managers, manager)
107107
if err != nil {
108108
return err
109109
}
@@ -114,7 +114,7 @@ func (s *State) Update(obj typed.YAMLObject, manager string) error {
114114
}
115115

116116
// Apply the passed in object to the current state
117-
func (s *State) Apply(obj typed.YAMLObject, manager string, force bool) error {
117+
func (s *State) Apply(obj typed.YAMLObject, version fieldpath.APIVersion, manager string, force bool) error {
118118
obj = FixTabsOrDie(obj)
119119
if err := s.checkInit(); err != nil {
120120
return err
@@ -123,7 +123,7 @@ func (s *State) Apply(obj typed.YAMLObject, manager string, force bool) error {
123123
if err != nil {
124124
return err
125125
}
126-
new, managers, err := s.Updater.Apply(*s.Live, tv, s.Managers, manager, force)
126+
new, managers, err := s.Updater.Apply(*s.Live, tv, version, s.Managers, manager, force)
127127
if err != nil {
128128
return err
129129
}
@@ -165,15 +165,16 @@ type Operation interface {
165165
// conflict, the user can specify the expected conflicts. If conflicts
166166
// don't match, an error will occur.
167167
type Apply struct {
168-
Manager string
169-
Object typed.YAMLObject
170-
Conflicts merge.Conflicts
168+
Manager string
169+
APIVersion fieldpath.APIVersion
170+
Object typed.YAMLObject
171+
Conflicts merge.Conflicts
171172
}
172173

173174
var _ Operation = &Apply{}
174175

175176
func (a Apply) run(state *State) error {
176-
err := state.Apply(a.Object, a.Manager, false)
177+
err := state.Apply(a.Object, a.APIVersion, a.Manager, false)
177178
if (err != nil || a.Conflicts != nil) && !reflect.DeepEqual(err, a.Conflicts) {
178179
return fmt.Errorf("expected conflicts: %v, got %v", a.Conflicts, err)
179180
}
@@ -184,27 +185,29 @@ func (a Apply) run(state *State) error {
184185
// ForceApply is a type of operation. It is a forced-apply run by a
185186
// manager with a given object. Any error will be returned.
186187
type ForceApply struct {
187-
Manager string
188-
Object typed.YAMLObject
188+
Manager string
189+
APIVersion fieldpath.APIVersion
190+
Object typed.YAMLObject
189191
}
190192

191193
var _ Operation = &ForceApply{}
192194

193195
func (f ForceApply) run(state *State) error {
194-
return state.Apply(f.Object, f.Manager, true)
196+
return state.Apply(f.Object, f.APIVersion, f.Manager, true)
195197
}
196198

197199
// Update is a type of operation. It is a controller type of
198200
// update. Errors are passed along.
199201
type Update struct {
200-
Manager string
201-
Object typed.YAMLObject
202+
Manager string
203+
APIVersion fieldpath.APIVersion
204+
Object typed.YAMLObject
202205
}
203206

204207
var _ Operation = &Update{}
205208

206209
func (u Update) run(state *State) error {
207-
return state.Update(u.Object, u.Manager)
210+
return state.Update(u.Object, u.APIVersion, u.Manager)
208211
}
209212

210213
// TestCase is the list of operations that need to be run, as well as

merge/leaf_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import (
2020
"testing"
2121

2222
"sigs.k8s.io/structured-merge-diff/fieldpath"
23+
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
2324
"sigs.k8s.io/structured-merge-diff/merge"
2425
"sigs.k8s.io/structured-merge-diff/typed"
25-
26-
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
2726
)
2827

2928
var leafFieldsParser = func() *typed.ParseableType {
@@ -56,6 +55,7 @@ func TestUpdateLeaf(t *testing.T) {
5655
numeric: 1
5756
string: "string"
5857
`,
58+
APIVersion: "v1",
5959
},
6060
Apply{
6161
Manager: "default",
@@ -64,6 +64,7 @@ func TestUpdateLeaf(t *testing.T) {
6464
string: "string"
6565
bool: false
6666
`,
67+
APIVersion: "v1",
6768
},
6869
},
6970
Object: `
@@ -83,22 +84,25 @@ func TestUpdateLeaf(t *testing.T) {
8384
"apply_update_apply_no_conflict": {
8485
Ops: []Operation{
8586
Apply{
86-
Manager: "default",
87+
Manager: "default",
88+
APIVersion: "v1",
8789
Object: `
8890
numeric: 1
8991
string: "string"
9092
`,
9193
},
9294
Update{
93-
Manager: "controller",
95+
Manager: "controller",
96+
APIVersion: "v1",
9497
Object: `
9598
numeric: 1
9699
string: "string"
97100
bool: true
98101
`,
99102
},
100103
Apply{
101-
Manager: "default",
104+
Manager: "default",
105+
APIVersion: "v1",
102106
Object: `
103107
numeric: 2
104108
string: "string"
@@ -128,22 +132,25 @@ func TestUpdateLeaf(t *testing.T) {
128132
"apply_update_apply_with_conflict": {
129133
Ops: []Operation{
130134
Apply{
131-
Manager: "default",
135+
Manager: "default",
136+
APIVersion: "v1",
132137
Object: `
133138
numeric: 1
134139
string: "string"
135140
`,
136141
},
137142
Update{
138-
Manager: "controller",
143+
Manager: "controller",
144+
APIVersion: "v1",
139145
Object: `
140146
numeric: 1
141147
string: "controller string"
142148
bool: true
143149
`,
144150
},
145151
Apply{
146-
Manager: "default",
152+
Manager: "default",
153+
APIVersion: "v1",
147154
Object: `
148155
numeric: 2
149156
string: "user string"
@@ -153,7 +160,8 @@ func TestUpdateLeaf(t *testing.T) {
153160
},
154161
},
155162
ForceApply{
156-
Manager: "default",
163+
Manager: "default",
164+
APIVersion: "v1",
157165
Object: `
158166
numeric: 2
159167
string: "user string"
@@ -183,15 +191,17 @@ func TestUpdateLeaf(t *testing.T) {
183191
"apply_twice_dangling": {
184192
Ops: []Operation{
185193
Apply{
186-
Manager: "default",
194+
Manager: "default",
195+
APIVersion: "v1",
187196
Object: `
188197
numeric: 1
189198
string: "string"
190199
bool: false
191200
`,
192201
},
193202
Apply{
194-
Manager: "default",
203+
Manager: "default",
204+
APIVersion: "v1",
195205
Object: `
196206
string: "new string"
197207
`,

merge/set_test.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import (
2020
"testing"
2121

2222
"sigs.k8s.io/structured-merge-diff/fieldpath"
23-
"sigs.k8s.io/structured-merge-diff/typed"
24-
2523
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
24+
"sigs.k8s.io/structured-merge-diff/typed"
2625
)
2726

2827
var setFieldsParser = func() *typed.ParseableType {
@@ -47,15 +46,17 @@ func TestUpdateSet(t *testing.T) {
4746
"apply_twice": {
4847
Ops: []Operation{
4948
Apply{
50-
Manager: "default",
49+
Manager: "default",
50+
APIVersion: "v1",
5151
Object: `
5252
list:
5353
- a
5454
- c
5555
`,
5656
},
5757
Apply{
58-
Manager: "default",
58+
Manager: "default",
59+
APIVersion: "v1",
5960
Object: `
6061
list:
6162
- a
@@ -87,15 +88,17 @@ func TestUpdateSet(t *testing.T) {
8788
"apply_update_apply_no_overlap": {
8889
Ops: []Operation{
8990
Apply{
90-
Manager: "default",
91+
Manager: "default",
92+
APIVersion: "v1",
9193
Object: `
9294
list:
9395
- a
9496
- c
9597
`,
9698
},
9799
Update{
98-
Manager: "controller",
100+
Manager: "controller",
101+
APIVersion: "v1",
99102
Object: `
100103
list:
101104
- a
@@ -105,7 +108,8 @@ func TestUpdateSet(t *testing.T) {
105108
`,
106109
},
107110
Apply{
108-
Manager: "default",
111+
Manager: "default",
112+
APIVersion: "v1",
109113
Object: `
110114
list:
111115
- a
@@ -146,15 +150,17 @@ func TestUpdateSet(t *testing.T) {
146150
"apply_update_apply_with_overlap": {
147151
Ops: []Operation{
148152
Apply{
149-
Manager: "default",
153+
Manager: "default",
154+
APIVersion: "v1",
150155
Object: `
151156
list:
152157
- a
153158
- c
154159
`,
155160
},
156161
Update{
157-
Manager: "controller",
162+
Manager: "controller",
163+
APIVersion: "v1",
158164
Object: `
159165
list:
160166
- a
@@ -164,7 +170,8 @@ func TestUpdateSet(t *testing.T) {
164170
`,
165171
},
166172
Apply{
167-
Manager: "default",
173+
Manager: "default",
174+
APIVersion: "v1",
168175
Object: `
169176
list:
170177
- a
@@ -201,7 +208,8 @@ func TestUpdateSet(t *testing.T) {
201208
"apply_twice_reorder": {
202209
Ops: []Operation{
203210
Apply{
204-
Manager: "default",
211+
Manager: "default",
212+
APIVersion: "v1",
205213
Object: `
206214
list:
207215
- a
@@ -211,7 +219,8 @@ func TestUpdateSet(t *testing.T) {
211219
`,
212220
},
213221
Apply{
214-
Manager: "default",
222+
Manager: "default",
223+
APIVersion: "v1",
215224
Object: `
216225
list:
217226
- a
@@ -243,7 +252,8 @@ func TestUpdateSet(t *testing.T) {
243252
"apply_update_apply_reorder": {
244253
Ops: []Operation{
245254
Apply{
246-
Manager: "default",
255+
Manager: "default",
256+
APIVersion: "v1",
247257
Object: `
248258
list:
249259
- a
@@ -253,7 +263,8 @@ func TestUpdateSet(t *testing.T) {
253263
`,
254264
},
255265
Update{
256-
Manager: "controller",
266+
Manager: "controller",
267+
APIVersion: "v1",
257268
Object: `
258269
list:
259270
- a
@@ -263,7 +274,8 @@ func TestUpdateSet(t *testing.T) {
263274
`,
264275
},
265276
Apply{
266-
Manager: "default",
277+
Manager: "default",
278+
APIVersion: "v1",
267279
Object: `
268280
list:
269281
- a
@@ -308,7 +320,8 @@ func TestUpdateSetBroken(t *testing.T) {
308320
"apply_twice_remove": {
309321
Ops: []Operation{
310322
Apply{
311-
Manager: "default",
323+
Manager: "default",
324+
APIVersion: "v1",
312325
Object: `
313326
list:
314327
- a
@@ -318,7 +331,8 @@ func TestUpdateSetBroken(t *testing.T) {
318331
`,
319332
},
320333
Apply{
321-
Manager: "default",
334+
Manager: "default",
335+
APIVersion: "v1",
322336
Object: `
323337
list:
324338
- a

0 commit comments

Comments
 (0)