@@ -20,7 +20,7 @@ type PlacementBindingBuilder struct {
20
20
// created placementBinding object.
21
21
Object * policiesv1.PlacementBinding
22
22
// api client to interact with the cluster.
23
- apiClient * clients. Settings
23
+ apiClient runtimeclient. Client
24
24
// used to store latest error message upon defining or mutating placementBinding definition.
25
25
errorMsg string
26
26
}
@@ -36,8 +36,21 @@ func NewPlacementBindingBuilder(
36
36
"Initializing new placement binding structure with the following params: name: %s, nsname: %s" ,
37
37
name , nsname )
38
38
39
+ if apiClient == nil {
40
+ glog .V (100 ).Info ("The apiClient of the PlacementBinding is nil" )
41
+
42
+ return nil
43
+ }
44
+
45
+ err := apiClient .AttachScheme (policiesv1 .AddToScheme )
46
+ if err != nil {
47
+ glog .V (100 ).Info ("Failed to add PlacementBinding scheme to client schemes" )
48
+
49
+ return nil
50
+ }
51
+
39
52
builder := PlacementBindingBuilder {
40
- apiClient : apiClient ,
53
+ apiClient : apiClient . Client ,
41
54
Definition : & policiesv1.PlacementBinding {
42
55
ObjectMeta : metav1.ObjectMeta {
43
56
Name : name ,
@@ -77,8 +90,15 @@ func PullPlacementBinding(apiClient *clients.Settings, name, nsname string) (*Pl
77
90
return nil , fmt .Errorf ("placementBinding's 'apiClient' cannot be empty" )
78
91
}
79
92
93
+ err := apiClient .AttachScheme (policiesv1 .AddToScheme )
94
+ if err != nil {
95
+ glog .V (100 ).Info ("Failed to add PlacementBinding scheme to client schemes" )
96
+
97
+ return nil , err
98
+ }
99
+
80
100
builder := PlacementBindingBuilder {
81
- apiClient : apiClient ,
101
+ apiClient : apiClient . Client ,
82
102
Definition : & policiesv1.PlacementBinding {
83
103
ObjectMeta : metav1.ObjectMeta {
84
104
Name : name ,
@@ -196,23 +216,29 @@ func (builder *PlacementBindingBuilder) Update(force bool) (*PlacementBindingBui
196
216
return builder , err
197
217
}
198
218
219
+ if ! builder .Exists () {
220
+ glog .V (100 ).Infof (
221
+ "PlacementBinding %s does not exist in namespace %s" , builder .Definition .Name , builder .Definition .Namespace )
222
+
223
+ return nil , fmt .Errorf ("cannot update non-existent placementBinding" )
224
+ }
225
+
199
226
glog .V (100 ).Infof ("Updating the placementBinding object: %s in namespace: %s" ,
200
227
builder .Definition .Name , builder .Definition .Namespace )
201
228
229
+ builder .Definition .ResourceVersion = builder .Object .ResourceVersion
202
230
err := builder .apiClient .Update (context .TODO (), builder .Definition )
203
231
204
232
if err != nil {
205
233
if force {
206
234
glog .V (100 ).Infof (
207
- "Failed to update the placementBinding object %s. " +
208
- "Note: Force flag set, executed delete/create methods instead" , builder .Definition .Name )
235
+ msg .FailToUpdateNotification ("placementBinding" , builder .Definition .Name , builder .Definition .Namespace ))
209
236
210
237
builder , err := builder .Delete ()
238
+ builder .Definition .ResourceVersion = ""
211
239
212
240
if err != nil {
213
- glog .V (100 ).Infof (
214
- "Failed to update the placementBinding object %s, " +
215
- "due to error in delete function" , builder .Definition .Name )
241
+ glog .V (100 ).Infof (msg .FailToUpdateError ("placementBinding" , builder .Definition .Name , builder .Definition .Namespace ))
216
242
217
243
return nil , err
218
244
}
@@ -221,9 +247,7 @@ func (builder *PlacementBindingBuilder) Update(force bool) (*PlacementBindingBui
221
247
}
222
248
}
223
249
224
- if err == nil {
225
- builder .Object = builder .Definition
226
- }
250
+ builder .Object = builder .Definition
227
251
228
252
return builder , err
229
253
}
0 commit comments