@@ -5,6 +5,7 @@ package e2e
5
5
6
6
import (
7
7
"context"
8
+ "fmt"
8
9
"time"
9
10
10
11
. "github.com/onsi/ginkgo/v2" //nolint:revive
@@ -26,27 +27,33 @@ func inventoryPolicyMustMatchTest(ctx context.Context, c client.Client, invConfi
26
27
By ("Apply first set of resources" )
27
28
applier := invConfig .ApplierFactoryFunc ()
28
29
29
- firstInvName := e2eutil .RandomString ("first-inv-" )
30
- firstInv := invConfig .InvWrapperFunc (invConfig .FactoryFunc (firstInvName , namespaceName , firstInvName ))
30
+ firstInventoryName := e2eutil .RandomString ("first-inv-" )
31
+ firstInventoryID := fmt .Sprintf ("%s-%s" , firstInventoryName , namespaceName )
32
+ firstInventoryInfo , err := invconfig .CreateInventoryInfo (invConfig , firstInventoryName , namespaceName , firstInventoryID )
33
+ Expect (err ).ToNot (HaveOccurred ())
34
+
31
35
deployment1Obj := e2eutil .WithNamespace (e2eutil .ManifestToUnstructured (deployment1 ), namespaceName )
32
36
firstResources := []* unstructured.Unstructured {
33
37
deployment1Obj ,
34
38
}
35
39
36
- e2eutil .RunWithNoErr (applier .Run (ctx , firstInv , firstResources , apply.ApplierOptions {
40
+ e2eutil .RunWithNoErr (applier .Run (ctx , firstInventoryInfo , firstResources , apply.ApplierOptions {
37
41
ReconcileTimeout : 2 * time .Minute ,
38
42
EmitStatusEvents : true ,
39
43
}))
40
44
41
45
By ("Apply second set of resources" )
42
- secondInvName := e2eutil .RandomString ("second-inv-" )
43
- secondInv := invConfig .InvWrapperFunc (invConfig .FactoryFunc (secondInvName , namespaceName , secondInvName ))
46
+ secondInventoryName := e2eutil .RandomString ("second-inv-" )
47
+ secondInventoryID := fmt .Sprintf ("%s-%s" , firstInventoryName , namespaceName )
48
+ secondInventoryInfo , err := invconfig .CreateInventoryInfo (invConfig , secondInventoryName , namespaceName , secondInventoryID )
49
+ Expect (err ).ToNot (HaveOccurred ())
50
+
44
51
deployment1Obj = e2eutil .WithNamespace (e2eutil .ManifestToUnstructured (deployment1 ), namespaceName )
45
52
secondResources := []* unstructured.Unstructured {
46
53
e2eutil .WithReplicas (deployment1Obj , 6 ),
47
54
}
48
55
49
- applierEvents := e2eutil .RunCollect (applier .Run (ctx , secondInv , secondResources , apply.ApplierOptions {
56
+ applierEvents := e2eutil .RunCollect (applier .Run (ctx , secondInventoryInfo , secondResources , apply.ApplierOptions {
50
57
ReconcileTimeout : 2 * time .Minute ,
51
58
EmitStatusEvents : true ,
52
59
InventoryPolicy : inventory .PolicyMustMatch ,
@@ -200,14 +207,17 @@ func inventoryPolicyAdoptIfNoInventoryTest(ctx context.Context, c client.Client,
200
207
By ("Apply resources" )
201
208
applier := invConfig .ApplierFactoryFunc ()
202
209
203
- invName := e2eutil .RandomString ("test-inv-" )
204
- inv := invConfig .InvWrapperFunc (invConfig .FactoryFunc (invName , namespaceName , invName ))
210
+ inventoryName := e2eutil .RandomString ("test-inv-" )
211
+ inventoryID := fmt .Sprintf ("%s-%s" , inventoryName , namespaceName )
212
+ inventoryInfo , err := invconfig .CreateInventoryInfo (invConfig , inventoryName , namespaceName , inventoryID )
213
+ Expect (err ).ToNot (HaveOccurred ())
214
+
205
215
deployment1Obj = e2eutil .WithNamespace (e2eutil .ManifestToUnstructured (deployment1 ), namespaceName )
206
216
resources := []* unstructured.Unstructured {
207
217
e2eutil .WithReplicas (deployment1Obj , 6 ),
208
218
}
209
219
210
- applierEvents := e2eutil .RunCollect (applier .Run (ctx , inv , resources , apply.ApplierOptions {
220
+ applierEvents := e2eutil .RunCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
211
221
ReconcileTimeout : 2 * time .Minute ,
212
222
EmitStatusEvents : true ,
213
223
InventoryPolicy : inventory .PolicyAdoptIfNoInventory ,
@@ -361,37 +371,43 @@ func inventoryPolicyAdoptIfNoInventoryTest(ctx context.Context, c client.Client,
361
371
value , found , err := object .NestedField (result .Object , "metadata" , "annotations" , "config.k8s.io/owning-inventory" )
362
372
Expect (err ).NotTo (HaveOccurred ())
363
373
Expect (found ).To (BeTrue ())
364
- Expect (value ).To (Equal (invName ))
374
+ Expect (value ).To (Equal (inventoryID ))
365
375
366
376
invConfig .InvCountVerifyFunc (ctx , c , namespaceName , 1 )
367
- invConfig .InvSizeVerifyFunc (ctx , c , invName , namespaceName , invName , 1 , 1 )
377
+ invConfig .InvSizeVerifyFunc (ctx , c , inventoryName , namespaceName , inventoryID , 1 , 1 )
368
378
}
369
379
370
380
func inventoryPolicyAdoptAllTest (ctx context.Context , c client.Client , invConfig invconfig.InventoryConfig , namespaceName string ) {
371
381
By ("Apply an initial set of resources" )
372
382
applier := invConfig .ApplierFactoryFunc ()
373
383
374
- firstInvName := e2eutil .RandomString ("first-inv-" )
375
- firstInv := invConfig .InvWrapperFunc (invConfig .FactoryFunc (firstInvName , namespaceName , firstInvName ))
384
+ firstInventoryName := e2eutil .RandomString ("first-inv-" )
385
+ firstInventoryID := fmt .Sprintf ("%s-%s" , firstInventoryName , namespaceName )
386
+ firstInventoryInfo , err := invconfig .CreateInventoryInfo (invConfig , firstInventoryName , namespaceName , firstInventoryID )
387
+ Expect (err ).ToNot (HaveOccurred ())
388
+
376
389
deployment1Obj := e2eutil .WithNamespace (e2eutil .ManifestToUnstructured (deployment1 ), namespaceName )
377
390
firstResources := []* unstructured.Unstructured {
378
391
deployment1Obj ,
379
392
}
380
393
381
- e2eutil .RunWithNoErr (applier .Run (ctx , firstInv , firstResources , apply.ApplierOptions {
394
+ e2eutil .RunWithNoErr (applier .Run (ctx , firstInventoryInfo , firstResources , apply.ApplierOptions {
382
395
ReconcileTimeout : 2 * time .Minute ,
383
396
EmitStatusEvents : true ,
384
397
}))
385
398
386
399
By ("Apply resources" )
387
- secondInvName := e2eutil .RandomString ("test-inv-" )
388
- secondInv := invConfig .InvWrapperFunc (invConfig .FactoryFunc (secondInvName , namespaceName , secondInvName ))
400
+ secondInventoryName := e2eutil .RandomString ("second-inv-" )
401
+ secondInventoryID := fmt .Sprintf ("%s-%s" , firstInventoryName , namespaceName )
402
+ secondInventoryInfo , err := invconfig .CreateInventoryInfo (invConfig , secondInventoryName , namespaceName , secondInventoryID )
403
+ Expect (err ).ToNot (HaveOccurred ())
404
+
389
405
deployment1Obj = e2eutil .WithNamespace (e2eutil .ManifestToUnstructured (deployment1 ), namespaceName )
390
406
secondResources := []* unstructured.Unstructured {
391
407
e2eutil .WithReplicas (deployment1Obj , 6 ),
392
408
}
393
409
394
- applierEvents := e2eutil .RunCollect (applier .Run (ctx , secondInv , secondResources , apply.ApplierOptions {
410
+ applierEvents := e2eutil .RunCollect (applier .Run (ctx , secondInventoryInfo , secondResources , apply.ApplierOptions {
395
411
ReconcileTimeout : 2 * time .Minute ,
396
412
EmitStatusEvents : true ,
397
413
InventoryPolicy : inventory .PolicyAdoptAll ,
@@ -545,7 +561,7 @@ func inventoryPolicyAdoptAllTest(ctx context.Context, c client.Client, invConfig
545
561
value , found , err := object .NestedField (result .Object , "metadata" , "annotations" , "config.k8s.io/owning-inventory" )
546
562
Expect (err ).NotTo (HaveOccurred ())
547
563
Expect (found ).To (BeTrue ())
548
- Expect (value ).To (Equal (secondInvName ))
564
+ Expect (value ).To (Equal (secondInventoryID ))
549
565
550
566
invConfig .InvCountVerifyFunc (ctx , c , namespaceName , 2 )
551
567
}
0 commit comments