@@ -14,85 +14,87 @@ import (
14
14
"sigs.k8s.io/cli-utils/pkg/apply"
15
15
"sigs.k8s.io/cli-utils/pkg/common"
16
16
"sigs.k8s.io/cli-utils/pkg/inventory"
17
+ "sigs.k8s.io/cli-utils/test/e2e/e2eutil"
18
+ "sigs.k8s.io/cli-utils/test/e2e/invconfig"
17
19
"sigs.k8s.io/controller-runtime/pkg/client"
18
20
)
19
21
20
- func deletionPreventionTest (ctx context.Context , c client.Client , invConfig InventoryConfig , inventoryName , namespaceName string ) {
22
+ func deletionPreventionTest (ctx context.Context , c client.Client , invConfig invconfig. InventoryConfig , inventoryName , namespaceName string ) {
21
23
By ("Apply resources" )
22
24
applier := invConfig .ApplierFactoryFunc ()
23
25
inventoryID := fmt .Sprintf ("%s-%s" , inventoryName , namespaceName )
24
26
25
- inventoryInfo := createInventoryInfo (invConfig , inventoryName , namespaceName , inventoryID )
27
+ inventoryInfo := invconfig . CreateInventoryInfo (invConfig , inventoryName , namespaceName , inventoryID )
26
28
27
29
resources := []* unstructured.Unstructured {
28
- withNamespace ( manifestToUnstructured (deployment1 ), namespaceName ),
29
- withAnnotation ( withNamespace ( manifestToUnstructured (pod1 ), namespaceName ), common .OnRemoveAnnotation , common .OnRemoveKeep ),
30
- withAnnotation ( withNamespace ( manifestToUnstructured (pod2 ), namespaceName ), common .LifecycleDeleteAnnotation , common .PreventDeletion ),
30
+ e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (deployment1 ), namespaceName ),
31
+ e2eutil . WithAnnotation ( e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod1 ), namespaceName ), common .OnRemoveAnnotation , common .OnRemoveKeep ),
32
+ e2eutil . WithAnnotation ( e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod2 ), namespaceName ), common .LifecycleDeleteAnnotation , common .PreventDeletion ),
31
33
}
32
34
33
- runCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
35
+ e2eutil . RunCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
34
36
ReconcileTimeout : 2 * time .Minute ,
35
37
}))
36
38
37
39
By ("Verify deployment created" )
38
- obj := assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (deployment1 ), namespaceName ))
40
+ obj := e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (deployment1 ), namespaceName ))
39
41
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
40
42
41
43
By ("Verify pod1 created" )
42
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (pod1 ), namespaceName ))
44
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod1 ), namespaceName ))
43
45
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
44
46
45
47
By ("Verify pod2 created" )
46
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (pod2 ), namespaceName ))
48
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod2 ), namespaceName ))
47
49
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
48
50
49
51
By ("Verify the inventory size is 3" )
50
52
invConfig .InvSizeVerifyFunc (ctx , c , inventoryName , namespaceName , inventoryID , 3 , 3 )
51
53
52
54
By ("Dry-run apply resources" )
53
55
resources = []* unstructured.Unstructured {
54
- withNamespace ( manifestToUnstructured (deployment1 ), namespaceName ),
56
+ e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (deployment1 ), namespaceName ),
55
57
}
56
58
57
- runCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
59
+ e2eutil . RunCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
58
60
ReconcileTimeout : 2 * time .Minute ,
59
61
DryRunStrategy : common .DryRunClient ,
60
62
}))
61
63
62
64
By ("Verify deployment still exists and has the config.k8s.io/owning-inventory annotation" )
63
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (deployment1 ), namespaceName ))
65
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (deployment1 ), namespaceName ))
64
66
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
65
67
66
68
By ("Verify pod1 still exits and does not have the config.k8s.io/owning-inventory annotation" )
67
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (pod1 ), namespaceName ))
69
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod1 ), namespaceName ))
68
70
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
69
71
70
72
By ("Verify pod2 still exits and does not have the config.k8s.io/owning-inventory annotation" )
71
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (pod2 ), namespaceName ))
73
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod2 ), namespaceName ))
72
74
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
73
75
74
76
By ("Verify the inventory size is still 3" )
75
77
invConfig .InvSizeVerifyFunc (ctx , c , inventoryName , namespaceName , inventoryID , 3 , 3 )
76
78
77
79
By ("Apply resources" )
78
80
resources = []* unstructured.Unstructured {
79
- withNamespace ( manifestToUnstructured (deployment1 ), namespaceName ),
81
+ e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (deployment1 ), namespaceName ),
80
82
}
81
83
82
- runCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
84
+ e2eutil . RunCollect (applier .Run (ctx , inventoryInfo , resources , apply.ApplierOptions {
83
85
ReconcileTimeout : 2 * time .Minute ,
84
86
}))
85
87
86
88
By ("Verify deployment still exists and has the config.k8s.io/owning-inventory annotation" )
87
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (deployment1 ), namespaceName ))
89
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (deployment1 ), namespaceName ))
88
90
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal (inventoryInfo .ID ()))
89
91
90
92
By ("Verify pod1 still exits and does not have the config.k8s.io/owning-inventory annotation" )
91
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (pod1 ), namespaceName ))
93
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod1 ), namespaceName ))
92
94
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal ("" ))
93
95
94
96
By ("Verify pod2 still exits and does not have the config.k8s.io/owning-inventory annotation" )
95
- obj = assertUnstructuredExists (ctx , c , withNamespace ( manifestToUnstructured (pod2 ), namespaceName ))
97
+ obj = e2eutil . AssertUnstructuredExists (ctx , c , e2eutil . WithNamespace ( e2eutil . ManifestToUnstructured (pod2 ), namespaceName ))
96
98
Expect (obj .GetAnnotations ()[inventory .OwningInventoryKey ]).To (Equal ("" ))
97
99
98
100
By ("Verify the inventory size is 1" )
0 commit comments