-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow empty set of apply objects
- Add e2e test to ensure the inventory is still correctly created and destroyed when the apply object set is empty.
- Loading branch information
Showing
5 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2020 The Kubernetes Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"sigs.k8s.io/cli-utils/pkg/apply" | ||
"sigs.k8s.io/cli-utils/pkg/apply/event" | ||
"sigs.k8s.io/cli-utils/pkg/inventory" | ||
"sigs.k8s.io/cli-utils/pkg/testutil" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
//nolint:dupl // expEvents similar to other tests | ||
func emptySetTest(ctx context.Context, c client.Client, invConfig InventoryConfig, inventoryName, namespaceName string) { | ||
By("Apply zero resources") | ||
applier := invConfig.ApplierFactoryFunc() | ||
|
||
inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName) | ||
inventoryInfo := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, inventoryID)) | ||
|
||
resources := []*unstructured.Unstructured{} | ||
|
||
applierEvents := runCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{ | ||
EmitStatusEvents: true, | ||
})) | ||
|
||
expEvents := []testutil.ExpEvent{ | ||
{ | ||
// InitTask | ||
EventType: event.InitType, | ||
InitEvent: &testutil.ExpInitEvent{}, | ||
}, | ||
{ | ||
// InvAddTask start | ||
EventType: event.ActionGroupType, | ||
ActionGroupEvent: &testutil.ExpActionGroupEvent{ | ||
Action: event.InventoryAction, | ||
GroupName: "inventory-add-0", | ||
Type: event.Started, | ||
}, | ||
}, | ||
{ | ||
// InvAddTask finished | ||
EventType: event.ActionGroupType, | ||
ActionGroupEvent: &testutil.ExpActionGroupEvent{ | ||
Action: event.InventoryAction, | ||
GroupName: "inventory-add-0", | ||
Type: event.Finished, | ||
}, | ||
}, | ||
{ | ||
// InvSetTask start | ||
EventType: event.ActionGroupType, | ||
ActionGroupEvent: &testutil.ExpActionGroupEvent{ | ||
Action: event.InventoryAction, | ||
GroupName: "inventory-set-0", | ||
Type: event.Started, | ||
}, | ||
}, | ||
{ | ||
// InvSetTask finished | ||
EventType: event.ActionGroupType, | ||
ActionGroupEvent: &testutil.ExpActionGroupEvent{ | ||
Action: event.InventoryAction, | ||
GroupName: "inventory-set-0", | ||
Type: event.Finished, | ||
}, | ||
}, | ||
} | ||
Expect(testutil.EventsToExpEvents(applierEvents)).To(testutil.Equal(expEvents)) | ||
|
||
By("Verify inventory created") | ||
invConfig.InvSizeVerifyFunc(ctx, c, inventoryName, namespaceName, inventoryID, 0) | ||
|
||
By("Destroy zero resources") | ||
destroyer := invConfig.DestroyerFactoryFunc() | ||
|
||
options := apply.DestroyerOptions{InventoryPolicy: inventory.PolicyAdoptIfNoInventory} | ||
destroyerEvents := runCollect(destroyer.Run(ctx, inventoryInfo, options)) | ||
|
||
expEvents = []testutil.ExpEvent{ | ||
{ | ||
// InitTask | ||
EventType: event.InitType, | ||
InitEvent: &testutil.ExpInitEvent{}, | ||
}, | ||
{ | ||
// DeleteInvTask start | ||
EventType: event.ActionGroupType, | ||
ActionGroupEvent: &testutil.ExpActionGroupEvent{ | ||
Action: event.InventoryAction, | ||
GroupName: "delete-inventory-0", | ||
Type: event.Started, | ||
}, | ||
}, | ||
{ | ||
// DeleteInvTask finished | ||
EventType: event.ActionGroupType, | ||
ActionGroupEvent: &testutil.ExpActionGroupEvent{ | ||
Action: event.InventoryAction, | ||
GroupName: "delete-inventory-0", | ||
Type: event.Finished, | ||
}, | ||
}, | ||
} | ||
|
||
Expect(testutil.EventsToExpEvents(destroyerEvents)).To(testutil.Equal(expEvents)) | ||
|
||
By("Verify inventory deleted") | ||
invConfig.InvNotExistsFunc(ctx, c, inventoryName, namespaceName, inventoryID) | ||
} |