@@ -17,6 +17,7 @@ import (
17
17
apierrors "k8s.io/apimachinery/pkg/api/errors"
18
18
"k8s.io/apimachinery/pkg/api/meta"
19
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
+ "k8s.io/apimachinery/pkg/runtime"
20
21
"k8s.io/apimachinery/pkg/util/sets"
21
22
"k8s.io/cli-runtime/pkg/resource"
22
23
"k8s.io/client-go/dynamic"
@@ -133,14 +134,7 @@ func (po *PruneOptions) Prune(currentObjects []*resource.Info, eventChannel chan
133
134
// Handle lifecycle directive preventing deletion.
134
135
if preventDeleteAnnotation (metadata .GetAnnotations ()) {
135
136
klog .V (7 ).Infof ("prune object lifecycle directive; do not prune: %s" , uid )
136
- eventChannel <- event.Event {
137
- Type : event .PruneType ,
138
- PruneEvent : event.PruneEvent {
139
- Type : event .PruneEventResourceUpdate ,
140
- Operation : event .PruneSkipped ,
141
- Object : obj ,
142
- },
143
- }
137
+ eventChannel <- createPruneEvent (obj , event .PruneSkipped )
144
138
continue
145
139
}
146
140
if ! o .DryRun {
@@ -150,14 +144,7 @@ func (po *PruneOptions) Prune(currentObjects []*resource.Info, eventChannel chan
150
144
return err
151
145
}
152
146
}
153
- eventChannel <- event.Event {
154
- Type : event .PruneType ,
155
- PruneEvent : event.PruneEvent {
156
- Type : event .PruneEventResourceUpdate ,
157
- Operation : event .Pruned ,
158
- Object : obj ,
159
- },
160
- }
147
+ eventChannel <- createPruneEvent (obj , event .Pruned )
161
148
}
162
149
// Delete previous inventory objects.
163
150
pastInventories , err := po .invClient .GetPreviousInventoryObjects (currentInventoryObject )
@@ -177,14 +164,7 @@ func (po *PruneOptions) Prune(currentObjects []*resource.Info, eventChannel chan
177
164
return err
178
165
}
179
166
}
180
- eventChannel <- event.Event {
181
- Type : event .PruneType ,
182
- PruneEvent : event.PruneEvent {
183
- Type : event .PruneEventResourceUpdate ,
184
- Operation : event .Pruned ,
185
- Object : pastGroupInfo .Object ,
186
- },
187
- }
167
+ eventChannel <- createPruneEvent (pastGroupInfo .Object , event .Pruned )
188
168
}
189
169
return nil
190
170
}
@@ -201,3 +181,15 @@ func preventDeleteAnnotation(annotations map[string]string) bool {
201
181
}
202
182
return false
203
183
}
184
+
185
+ // createPruneEvent is a helper function to package a prune event.
186
+ func createPruneEvent (obj runtime.Object , op event.PruneEventOperation ) event.Event {
187
+ return event.Event {
188
+ Type : event .PruneType ,
189
+ PruneEvent : event.PruneEvent {
190
+ Type : event .PruneEventResourceUpdate ,
191
+ Operation : op ,
192
+ Object : obj ,
193
+ },
194
+ }
195
+ }
0 commit comments