Skip to content

Commit 81cd6fb

Browse files
committed
test: make CreateInventoryInfo return an error
Instead of a panic, have CreateInventoryInfo and invWrapperFunc return an error, and then check the error in the tests calling these functions. Take this oportunity to make all the calls more consistent.
1 parent d8c50d5 commit 81cd6fb

24 files changed

+129
-86
lines changed

test/e2e/apply_and_destroy_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import (
2525
func applyAndDestroyTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
2626
By("Apply resources")
2727
applier := invConfig.ApplierFactoryFunc()
28-
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
2928

30-
inventoryInfo := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
29+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
30+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
31+
Expect(err).ToNot(HaveOccurred())
3132

3233
deployment1Obj := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName)
3334
resources := []*unstructured.Unstructured{

test/e2e/continue_on_error_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package e2e
55

66
import (
77
"context"
8+
"fmt"
89

910
. "github.com/onsi/ginkgo/v2" //nolint:revive
1011
. "github.com/onsi/gomega" //nolint:revive
@@ -28,7 +29,9 @@ func continueOnErrorTest(ctx context.Context, c client.Client, invConfig invconf
2829
By("apply an invalid CRD")
2930
applier := invConfig.ApplierFactoryFunc()
3031

31-
inv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, "test"))
32+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
33+
inv, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
34+
Expect(err).ToNot(HaveOccurred())
3235

3336
invalidCrdObj := e2eutil.ManifestToUnstructured(invalidCrd)
3437
pod1Obj := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod1), namespaceName)

test/e2e/current_uid_filter_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ type: Warning
5959
// - inventory should not double-track the object i.e. we should hold reference only to the object with the groupKind that was most recently applied
6060
func currentUIDFilterTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
6161
applier := invConfig.ApplierFactoryFunc()
62+
6263
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
63-
inventoryInfo := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
64+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
65+
Expect(err).ToNot(HaveOccurred())
6466

6567
templateFields := struct{ Namespace string }{Namespace: namespaceName}
6668
v1Event := e2eutil.TemplateToUnstructured(v1EventTemplate, templateFields)
@@ -70,7 +72,7 @@ func currentUIDFilterTest(ctx context.Context, c client.Client, invConfig invcon
7072
resources := []*unstructured.Unstructured{
7173
v1Event,
7274
}
73-
err := e2eutil.Run(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{}))
75+
err = e2eutil.Run(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{}))
7476
Expect(err).ToNot(HaveOccurred())
7577

7678
By("Verify resource available in both apiGroups")

test/e2e/customprovider/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func WrapInventoryObj(obj *unstructured.Unstructured) (inventory.Storage, error)
129129
return &InventoryCustomType{inv: obj}, nil
130130
}
131131

132-
func WrapInventoryInfoObj(obj *unstructured.Unstructured) inventory.Info {
133-
return &InventoryCustomType{inv: obj}
132+
func WrapInventoryInfoObj(obj *unstructured.Unstructured) (inventory.Info, error) {
133+
return &InventoryCustomType{inv: obj}, nil
134134
}
135135

136136
var _ inventory.Storage = &InventoryCustomType{}

test/e2e/deletion_prevention_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
func deletionPreventionTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
2323
By("Apply resources")
2424
applier := invConfig.ApplierFactoryFunc()
25-
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
2625

27-
inventoryInfo := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
26+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
27+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
28+
Expect(err).ToNot(HaveOccurred())
2829

2930
resources := []*unstructured.Unstructured{
3031
e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName),

test/e2e/dependency_filter_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func dependencyFilterTest(ctx context.Context, c client.Client, invConfig invcon
2727
By("apply resources in order based on depends-on annotation")
2828
applier := invConfig.ApplierFactoryFunc()
2929

30-
inv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, "test"))
30+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
31+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
32+
Expect(err).ToNot(HaveOccurred())
3133

3234
pod1Obj := e2eutil.WithDependsOn(e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod1), namespaceName), fmt.Sprintf("/namespaces/%s/Pod/pod2", namespaceName))
3335
pod2Obj := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod2), namespaceName)
@@ -45,7 +47,7 @@ func dependencyFilterTest(ctx context.Context, c client.Client, invConfig invcon
4547
e2eutil.DeleteUnstructuredIfExists(ctx, c, pod2Obj)
4648
}(ctx, c)
4749

48-
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inv, resources, apply.ApplierOptions{
50+
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
4951
EmitStatusEvents: false,
5052
}))
5153

@@ -245,7 +247,7 @@ func dependencyFilterTest(ctx context.Context, c client.Client, invConfig invcon
245247
pod1Obj,
246248
}
247249

248-
applierEvents = e2eutil.RunCollect(applier.Run(ctx, inv, resources, apply.ApplierOptions{
250+
applierEvents = e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
249251
EmitStatusEvents: false,
250252
ValidationPolicy: validation.SkipInvalid,
251253
}))

test/e2e/depends_on_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
2424
By("apply resources in order based on depends-on annotation")
2525
applier := invConfig.ApplierFactoryFunc()
2626

27-
inv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, "test"))
27+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
28+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
29+
Expect(err).ToNot(HaveOccurred())
2830

2931
namespace1Name := fmt.Sprintf("%s-ns1", namespaceName)
3032
namespace1Obj := e2eutil.UnstructuredNamespace(namespace1Name)
@@ -53,7 +55,7 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
5355
pod3Obj,
5456
}
5557

56-
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inv, resources, apply.ApplierOptions{
58+
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
5759
EmitStatusEvents: false,
5860
}))
5961

@@ -421,7 +423,7 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
421423
By("destroy resources in opposite order")
422424
destroyer := invConfig.DestroyerFactoryFunc()
423425
options := apply.DestroyerOptions{InventoryPolicy: inventory.PolicyAdoptIfNoInventory}
424-
destroyerEvents := e2eutil.RunCollect(destroyer.Run(ctx, inv, options))
426+
destroyerEvents := e2eutil.RunCollect(destroyer.Run(ctx, inventoryInfo, options))
425427

426428
expEvents = []testutil.ExpEvent{
427429
{

test/e2e/destroy_reconciliation_failure_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func destroyReconciliationFailureTest(ctx context.Context, c client.Client, invC
2424
applier := invConfig.ApplierFactoryFunc()
2525

2626
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
27-
28-
inv := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
27+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
28+
Expect(err).ToNot(HaveOccurred())
2929

3030
podObject := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod1), namespaceName)
3131
podWithFinalizerObject := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod2), namespaceName)
@@ -37,7 +37,7 @@ func destroyReconciliationFailureTest(ctx context.Context, c client.Client, invC
3737
podWithFinalizerObject,
3838
}
3939

40-
_ = e2eutil.RunCollect(applier.Run(ctx, inv, resource1, apply.ApplierOptions{
40+
_ = e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resource1, apply.ApplierOptions{
4141
EmitStatusEvents: false,
4242
}))
4343

@@ -83,7 +83,7 @@ func destroyReconciliationFailureTest(ctx context.Context, c client.Client, invC
8383
},
8484
}
8585
for _, ec := range expectedCounts {
86-
_ = e2eutil.RunCollect(destroyer.Run(ctx, inv, options))
86+
_ = e2eutil.RunCollect(destroyer.Run(ctx, inventoryInfo, options))
8787

8888
By("Verify pod1 is deleted")
8989
e2eutil.AssertUnstructuredDoesNotExist(ctx, c, podObject)
@@ -99,7 +99,7 @@ func destroyReconciliationFailureTest(ctx context.Context, c client.Client, invC
9999
podWithFinalizerObject = e2eutil.WithoutFinalizers(podWithFinalizerObject)
100100
e2eutil.ApplyUnstructured(ctx, c, podWithFinalizerObject)
101101
// re-run the destroyer and verify the object is removed from the inventory
102-
_ = e2eutil.RunCollect(destroyer.Run(ctx, inv, options))
102+
_ = e2eutil.RunCollect(destroyer.Run(ctx, inventoryInfo, options))
103103

104104
By("Verify pod1 is deleted")
105105
e2eutil.AssertUnstructuredDoesNotExist(ctx, c, podObject)

test/e2e/dry_run_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import (
2626
func dryRunTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
2727
By("Apply with DryRun")
2828
applier := invConfig.ApplierFactoryFunc()
29-
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
3029

31-
inventoryInfo := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
30+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
31+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
32+
Expect(err).ToNot(HaveOccurred())
3233

3334
namespace1Name := fmt.Sprintf("%s-ns1", namespaceName)
3435

test/e2e/empty_set_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func emptySetTest(ctx context.Context, c client.Client, invConfig invconfig.Inve
2525
applier := invConfig.ApplierFactoryFunc()
2626

2727
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
28-
inventoryInfo := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, inventoryID))
28+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
29+
Expect(err).ToNot(HaveOccurred())
2930

3031
resources := []*unstructured.Unstructured{}
3132

test/e2e/exit_early_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ func exitEarlyTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
2525
By("exit early on invalid object")
2626
applier := invConfig.ApplierFactoryFunc()
2727

28-
inv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, "test"))
28+
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
29+
inventoryInfo, err := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
30+
Expect(err).ToNot(HaveOccurred())
2931

3032
fields := struct{ Namespace string }{Namespace: namespaceName}
3133
// valid pod
@@ -42,7 +44,7 @@ func exitEarlyTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
4244
invalidPodObj,
4345
}
4446

45-
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inv, resources, apply.ApplierOptions{
47+
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
4648
EmitStatusEvents: false,
4749
ValidationPolicy: validation.ExitEarly,
4850
}))

test/e2e/invconfig/configmap.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/onsi/gomega"
1010
v1 "k8s.io/api/core/v1"
11-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1211
"k8s.io/client-go/rest"
1312
"sigs.k8s.io/cli-utils/pkg/apply"
1413
"sigs.k8s.io/cli-utils/pkg/common"
@@ -18,14 +17,10 @@ import (
1817

1918
func NewConfigMapTypeInvConfig(cfg *rest.Config) InventoryConfig {
2019
return InventoryConfig{
21-
ClientConfig: cfg,
22-
Strategy: inventory.LabelStrategy,
23-
FactoryFunc: cmInventoryManifest,
24-
InvWrapperFunc: func(obj *unstructured.Unstructured) inventory.Info {
25-
info, err := inventory.ConfigMapToInventoryInfo(obj)
26-
gomega.Expect(err).ToNot(gomega.HaveOccurred())
27-
return info
28-
},
20+
ClientConfig: cfg,
21+
Strategy: inventory.LabelStrategy,
22+
FactoryFunc: cmInventoryManifest,
23+
InvWrapperFunc: inventory.ConfigMapToInventoryInfo,
2924
ApplierFactoryFunc: newDefaultInvApplierFactory(cfg),
3025
DestroyerFactoryFunc: newDefaultInvDestroyerFactory(cfg),
3126
InvSizeVerifyFunc: defaultInvSizeVerifyFunc,

test/e2e/invconfig/invconfig.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
type inventoryFactoryFunc func(name, namespace, id string) *unstructured.Unstructured
22-
type invWrapperFunc func(*unstructured.Unstructured) inventory.Info
22+
type invWrapperFunc func(*unstructured.Unstructured) (inventory.Info, error)
2323
type applierFactoryFunc func() *apply.Applier
2424
type destroyerFactoryFunc func() *apply.Destroyer
2525
type invSizeVerifyFunc func(ctx context.Context, c client.Client, name, namespace, id string, specCount, statusCount int)
@@ -38,14 +38,14 @@ type InventoryConfig struct {
3838
InvNotExistsFunc invNotExistsFunc
3939
}
4040

41-
func CreateInventoryInfo(invConfig InventoryConfig, inventoryName, namespaceName, inventoryID string) inventory.Info {
41+
func CreateInventoryInfo(invConfig InventoryConfig, inventoryName, namespaceName, inventoryID string) (inventory.Info, error) {
4242
switch invConfig.Strategy {
4343
case inventory.NameStrategy:
4444
return invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, e2eutil.RandomString("inventory-")))
4545
case inventory.LabelStrategy:
4646
return invConfig.InvWrapperFunc(invConfig.FactoryFunc(e2eutil.RandomString("inventory-"), namespaceName, inventoryID))
4747
default:
48-
panic(fmt.Errorf("unknown inventory strategy %q", invConfig.Strategy))
48+
return nil, fmt.Errorf("unknown inventory strategy %q", invConfig.Strategy)
4949
}
5050
}
5151

test/e2e/inventory_policy_test.go

+34-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package e2e
55

66
import (
77
"context"
8+
"fmt"
89
"time"
910

1011
. "github.com/onsi/ginkgo/v2" //nolint:revive
@@ -26,27 +27,33 @@ func inventoryPolicyMustMatchTest(ctx context.Context, c client.Client, invConfi
2627
By("Apply first set of resources")
2728
applier := invConfig.ApplierFactoryFunc()
2829

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+
3135
deployment1Obj := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName)
3236
firstResources := []*unstructured.Unstructured{
3337
deployment1Obj,
3438
}
3539

36-
e2eutil.RunWithNoErr(applier.Run(ctx, firstInv, firstResources, apply.ApplierOptions{
40+
e2eutil.RunWithNoErr(applier.Run(ctx, firstInventoryInfo, firstResources, apply.ApplierOptions{
3741
ReconcileTimeout: 2 * time.Minute,
3842
EmitStatusEvents: true,
3943
}))
4044

4145
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+
4451
deployment1Obj = e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName)
4552
secondResources := []*unstructured.Unstructured{
4653
e2eutil.WithReplicas(deployment1Obj, 6),
4754
}
4855

49-
applierEvents := e2eutil.RunCollect(applier.Run(ctx, secondInv, secondResources, apply.ApplierOptions{
56+
applierEvents := e2eutil.RunCollect(applier.Run(ctx, secondInventoryInfo, secondResources, apply.ApplierOptions{
5057
ReconcileTimeout: 2 * time.Minute,
5158
EmitStatusEvents: true,
5259
InventoryPolicy: inventory.PolicyMustMatch,
@@ -200,14 +207,17 @@ func inventoryPolicyAdoptIfNoInventoryTest(ctx context.Context, c client.Client,
200207
By("Apply resources")
201208
applier := invConfig.ApplierFactoryFunc()
202209

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+
205215
deployment1Obj = e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName)
206216
resources := []*unstructured.Unstructured{
207217
e2eutil.WithReplicas(deployment1Obj, 6),
208218
}
209219

210-
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inv, resources, apply.ApplierOptions{
220+
applierEvents := e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
211221
ReconcileTimeout: 2 * time.Minute,
212222
EmitStatusEvents: true,
213223
InventoryPolicy: inventory.PolicyAdoptIfNoInventory,
@@ -361,37 +371,43 @@ func inventoryPolicyAdoptIfNoInventoryTest(ctx context.Context, c client.Client,
361371
value, found, err := object.NestedField(result.Object, "metadata", "annotations", "config.k8s.io/owning-inventory")
362372
Expect(err).NotTo(HaveOccurred())
363373
Expect(found).To(BeTrue())
364-
Expect(value).To(Equal(invName))
374+
Expect(value).To(Equal(inventoryID))
365375

366376
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)
368378
}
369379

370380
func inventoryPolicyAdoptAllTest(ctx context.Context, c client.Client, invConfig invconfig.InventoryConfig, namespaceName string) {
371381
By("Apply an initial set of resources")
372382
applier := invConfig.ApplierFactoryFunc()
373383

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+
376389
deployment1Obj := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName)
377390
firstResources := []*unstructured.Unstructured{
378391
deployment1Obj,
379392
}
380393

381-
e2eutil.RunWithNoErr(applier.Run(ctx, firstInv, firstResources, apply.ApplierOptions{
394+
e2eutil.RunWithNoErr(applier.Run(ctx, firstInventoryInfo, firstResources, apply.ApplierOptions{
382395
ReconcileTimeout: 2 * time.Minute,
383396
EmitStatusEvents: true,
384397
}))
385398

386399
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+
389405
deployment1Obj = e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(deployment1), namespaceName)
390406
secondResources := []*unstructured.Unstructured{
391407
e2eutil.WithReplicas(deployment1Obj, 6),
392408
}
393409

394-
applierEvents := e2eutil.RunCollect(applier.Run(ctx, secondInv, secondResources, apply.ApplierOptions{
410+
applierEvents := e2eutil.RunCollect(applier.Run(ctx, secondInventoryInfo, secondResources, apply.ApplierOptions{
395411
ReconcileTimeout: 2 * time.Minute,
396412
EmitStatusEvents: true,
397413
InventoryPolicy: inventory.PolicyAdoptAll,
@@ -545,7 +561,7 @@ func inventoryPolicyAdoptAllTest(ctx context.Context, c client.Client, invConfig
545561
value, found, err := object.NestedField(result.Object, "metadata", "annotations", "config.k8s.io/owning-inventory")
546562
Expect(err).NotTo(HaveOccurred())
547563
Expect(found).To(BeTrue())
548-
Expect(value).To(Equal(secondInvName))
564+
Expect(value).To(Equal(secondInventoryID))
549565

550566
invConfig.InvCountVerifyFunc(ctx, c, namespaceName, 2)
551567
}

0 commit comments

Comments
 (0)