@@ -173,37 +173,41 @@ type Interface interface {
173
173
// ListControllerRevisions lists all ControllerRevisions matching selector and owned by parent or no other
174
174
// controller. If the returned error is nil the returned slice of ControllerRevisions is valid. If the
175
175
// returned error is not nil, the returned slice is not valid.
176
- ListControllerRevisions (parent client.Object , selector labels.Selector ) ([]* appsv1.ControllerRevision , error )
176
+ ListControllerRevisions (ctx context. Context , parent client.Object , selector labels.Selector ) ([]* appsv1.ControllerRevision , error )
177
177
// CreateControllerRevision attempts to create the revision as owned by parent via a ControllerRef. If name
178
178
// collision occurs, collisionCount (incremented each time collision occurs except for the first time) is
179
179
// added to the hash of the revision, and it is renamed using ControllerRevisionName. Implementations may
180
180
// cease to attempt to retry creation after some number of attempts and return an error. If the returned
181
181
// error is not nil, creation failed. If the returned error is nil, the returned ControllerRevision has been
182
182
// created.
183
183
// Callers must make sure that collisionCount is not nil. An error is returned if it is.
184
- CreateControllerRevision (parent client.Object , revision * appsv1.ControllerRevision , collisionCount * int32 ) (* appsv1.ControllerRevision , error )
184
+ CreateControllerRevision (ctx context. Context , parent client.Object , revision * appsv1.ControllerRevision , collisionCount * int32 ) (* appsv1.ControllerRevision , error )
185
185
// DeleteControllerRevision attempts to delete revision. If the returned error is not nil, deletion has failed.
186
- DeleteControllerRevision (revision * appsv1.ControllerRevision ) error
186
+ DeleteControllerRevision (ctx context. Context , revision * appsv1.ControllerRevision ) error
187
187
// UpdateControllerRevision updates revision such that its Revision is equal to newRevision. Implementations
188
188
// may retry on conflict. If the returned error is nil, the update was successful and returned ControllerRevision
189
189
// is valid. If the returned error is not nil, the update failed and the returned ControllerRevision is invalid.
190
- UpdateControllerRevision (revision * appsv1.ControllerRevision , newRevision int64 ) (* appsv1.ControllerRevision , error )
190
+ UpdateControllerRevision (ctx context. Context , revision * appsv1.ControllerRevision , newRevision int64 ) (* appsv1.ControllerRevision , error )
191
191
}
192
192
193
193
// NewClient returns an instance of Interface that uses client to communicate with the API Server and lister to list
194
194
// ControllerRevisions. This method should be used to create an Interface for all scenarios other than testing.
195
- func NewClient (cli client.Client ) Interface {
196
- return & realHistory {cli : cli }
195
+ func NewClient (cli client.Client , component string ) Interface {
196
+ return & realHistory {
197
+ cli : cli ,
198
+ component : component ,
199
+ }
197
200
}
198
201
199
202
type realHistory struct {
200
- cli client.Client
203
+ cli client.Client
204
+ component string
201
205
}
202
206
203
- func (rh * realHistory ) ListControllerRevisions (parent client.Object , selector labels.Selector ) ([]* appsv1.ControllerRevision , error ) {
207
+ func (rh * realHistory ) ListControllerRevisions (ctx context. Context , parent client.Object , selector labels.Selector ) ([]* appsv1.ControllerRevision , error ) {
204
208
// List all revisions in the namespace that match the selector
205
209
var list appsv1.ControllerRevisionList
206
- if err := rh .cli .List (context . TODO () , & list , & client.ListOptions {
210
+ if err := rh .cli .List (ctx , & list , & client.ListOptions {
207
211
Namespace : parent .GetNamespace (),
208
212
LabelSelector : selector ,
209
213
}); err != nil {
@@ -220,21 +224,22 @@ func (rh *realHistory) ListControllerRevisions(parent client.Object, selector la
220
224
return owned , nil
221
225
}
222
226
223
- func (rh * realHistory ) CreateControllerRevision (parent client.Object , revision * appsv1.ControllerRevision , collisionCount * int32 ) (* appsv1.ControllerRevision , error ) {
227
+ func (rh * realHistory ) CreateControllerRevision (ctx context. Context , parent client.Object , revision * appsv1.ControllerRevision , collisionCount * int32 ) (* appsv1.ControllerRevision , error ) {
224
228
if collisionCount == nil {
225
229
return nil , fmt .Errorf ("collisionCount should not be nil" )
226
230
}
227
231
228
232
// Clone the input
229
233
clone := revision .DeepCopy ()
230
234
235
+ namePrefix := parent .GetName () + "-" + rh .component
231
236
// Continue to attempt to create the revision updating the name with a new hash on each iteration
232
237
for {
233
238
hash := HashControllerRevision (revision , collisionCount )
234
239
// Update the revisions name
235
- clone .Name = ControllerRevisionName (parent . GetName () , hash )
240
+ clone .Name = ControllerRevisionName (namePrefix , hash )
236
241
clone .Namespace = parent .GetNamespace ()
237
- err := rh .cli .Create (context . TODO () , clone )
242
+ err := rh .cli .Create (ctx , clone )
238
243
if errors .IsAlreadyExists (err ) {
239
244
var exists appsv1.ControllerRevision
240
245
if err := rh .cli .Get (context .TODO (), client.ObjectKey {
@@ -253,19 +258,19 @@ func (rh *realHistory) CreateControllerRevision(parent client.Object, revision *
253
258
}
254
259
}
255
260
256
- func (rh * realHistory ) UpdateControllerRevision (revision * appsv1.ControllerRevision , newRevision int64 ) (* appsv1.ControllerRevision , error ) {
261
+ func (rh * realHistory ) UpdateControllerRevision (ctx context. Context , revision * appsv1.ControllerRevision , newRevision int64 ) (* appsv1.ControllerRevision , error ) {
257
262
clone := revision .DeepCopy ()
258
263
err := retry .RetryOnConflict (retry .DefaultBackoff , func () error {
259
264
if clone .Revision == newRevision {
260
265
return nil
261
266
}
262
267
clone .Revision = newRevision
263
- updateErr := rh .cli .Update (context . TODO () , clone )
268
+ updateErr := rh .cli .Update (ctx , clone )
264
269
if updateErr == nil {
265
270
return nil
266
271
}
267
272
var updated appsv1.ControllerRevision
268
- if err := rh .cli .Get (context . TODO () , client.ObjectKey {
273
+ if err := rh .cli .Get (ctx , client.ObjectKey {
269
274
Namespace : clone .Namespace ,
270
275
Name : clone .Name ,
271
276
}, & updated ); err == nil {
@@ -277,6 +282,6 @@ func (rh *realHistory) UpdateControllerRevision(revision *appsv1.ControllerRevis
277
282
return clone , err
278
283
}
279
284
280
- func (rh * realHistory ) DeleteControllerRevision (revision * appsv1.ControllerRevision ) error {
281
- return rh .cli .Delete (context . TODO () , revision )
285
+ func (rh * realHistory ) DeleteControllerRevision (ctx context. Context , revision * appsv1.ControllerRevision ) error {
286
+ return rh .cli .Delete (ctx , revision )
282
287
}
0 commit comments