@@ -150,6 +150,18 @@ var _ = Describe("Hook", func() {
150
150
Expect (c .WatchCalls [0 ].Handler ).To (BeAssignableToTypeOf (& handler.EnqueueRequestForOwner {}))
151
151
Expect (c .WatchCalls [1 ].Handler ).To (BeAssignableToTypeOf (& handler.EnqueueRequestForOwner {}))
152
152
})
153
+ It ("should watch resource policy keep resources with annotation handler" , func () {
154
+ rel = & release.Release {
155
+ Manifest : strings .Join ([]string {rsOwnerNamespaceWithKeep , ssOtherNamespaceWithKeep , clusterRoleWithKeep , clusterRoleBindingWithKeep }, "---\n " ),
156
+ }
157
+ drw = internalhook .NewDependentResourceWatcher (c , rm )
158
+ Expect (drw .Exec (owner , * rel , log )).To (Succeed ())
159
+ Expect (c .WatchCalls ).To (HaveLen (4 ))
160
+ Expect (c .WatchCalls [0 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
161
+ Expect (c .WatchCalls [1 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
162
+ Expect (c .WatchCalls [2 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
163
+ Expect (c .WatchCalls [3 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
164
+ })
153
165
})
154
166
155
167
Context ("when the owner is namespace-scoped" , func () {
@@ -165,7 +177,6 @@ var _ = Describe("Hook", func() {
165
177
},
166
178
}
167
179
})
168
-
169
180
It ("should watch namespace-scoped dependent resources in the same namespace with ownerRef handler" , func () {
170
181
rel = & release.Release {
171
182
Manifest : strings .Join ([]string {rsOwnerNamespace }, "---\n " ),
@@ -175,7 +186,6 @@ var _ = Describe("Hook", func() {
175
186
Expect (c .WatchCalls ).To (HaveLen (1 ))
176
187
Expect (c .WatchCalls [0 ].Handler ).To (BeAssignableToTypeOf (& handler.EnqueueRequestForOwner {}))
177
188
})
178
-
179
189
It ("should watch cluster-scoped resources with annotation handler" , func () {
180
190
rel = & release.Release {
181
191
Manifest : strings .Join ([]string {clusterRole }, "---\n " ),
@@ -185,7 +195,6 @@ var _ = Describe("Hook", func() {
185
195
Expect (c .WatchCalls ).To (HaveLen (1 ))
186
196
Expect (c .WatchCalls [0 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
187
197
})
188
-
189
198
It ("should watch namespace-scoped resources in a different namespace with annotation handler" , func () {
190
199
rel = & release.Release {
191
200
Manifest : strings .Join ([]string {ssOtherNamespace }, "---\n " ),
@@ -195,6 +204,17 @@ var _ = Describe("Hook", func() {
195
204
Expect (c .WatchCalls ).To (HaveLen (1 ))
196
205
Expect (c .WatchCalls [0 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
197
206
})
207
+ It ("should watch resource policy keep resources with annotation handler" , func () {
208
+ rel = & release.Release {
209
+ Manifest : strings .Join ([]string {rsOwnerNamespaceWithKeep , ssOtherNamespaceWithKeep , clusterRoleWithKeep }, "---\n " ),
210
+ }
211
+ drw = internalhook .NewDependentResourceWatcher (c , rm )
212
+ Expect (drw .Exec (owner , * rel , log )).To (Succeed ())
213
+ Expect (c .WatchCalls ).To (HaveLen (3 ))
214
+ Expect (c .WatchCalls [0 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
215
+ Expect (c .WatchCalls [1 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
216
+ Expect (c .WatchCalls [2 ].Handler ).To (BeAssignableToTypeOf (& sdkhandler.EnqueueRequestForAnnotation {}))
217
+ })
198
218
})
199
219
})
200
220
})
@@ -207,24 +227,58 @@ kind: ReplicaSet
207
227
metadata:
208
228
name: testReplicaSet
209
229
namespace: ownerNamespace
230
+ `
231
+ rsOwnerNamespaceWithKeep = `
232
+ apiVersion: apps/v1
233
+ kind: ReplicaSet
234
+ metadata:
235
+ name: testReplicaSet
236
+ namespace: ownerNamespace
237
+ annotations:
238
+ helm.sh/resource-policy: keep
210
239
`
211
240
ssOtherNamespace = `
212
241
apiVersion: apps/v1
213
242
kind: StatefulSet
214
243
metadata:
215
244
name: otherTestStatefulSet
216
245
namespace: otherNamespace
246
+ `
247
+ ssOtherNamespaceWithKeep = `
248
+ apiVersion: apps/v1
249
+ kind: StatefulSet
250
+ metadata:
251
+ name: otherTestStatefulSet
252
+ namespace: otherNamespace
253
+ annotations:
254
+ helm.sh/resource-policy: keep
217
255
`
218
256
clusterRole = `
219
257
apiVersion: rbac.authorization.k8s.io/v1
220
258
kind: ClusterRole
221
259
metadata:
222
260
name: testClusterRole
261
+ `
262
+ clusterRoleWithKeep = `
263
+ apiVersion: rbac.authorization.k8s.io/v1
264
+ kind: ClusterRole
265
+ metadata:
266
+ name: testClusterRole
267
+ annotations:
268
+ helm.sh/resource-policy: keep
223
269
`
224
270
clusterRoleBinding = `
225
271
apiVersion: rbac.authorization.k8s.io/v1
226
272
kind: ClusterRoleBinding
227
273
metadata:
228
274
name: testClusterRoleBinding
275
+ `
276
+ clusterRoleBindingWithKeep = `
277
+ apiVersion: rbac.authorization.k8s.io/v1
278
+ kind: ClusterRoleBinding
279
+ metadata:
280
+ name: testClusterRoleBinding
281
+ annotations:
282
+ helm.sh/resource-policy: keep
229
283
`
230
284
)
0 commit comments