Skip to content

Commit

Permalink
clean kruise object after each
Browse files Browse the repository at this point in the history
  • Loading branch information
daimaxiaxie committed Aug 30, 2024
1 parent f3fbe46 commit 1aa9cb3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/node/termination/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var _ = Describe("Termination", func() {
})

AfterEach(func() {
ExpectCleanedUp(ctx, env.Client)
ExpectCleanedUp(ctx, env.Client, test.KruiseObjects...)
fakeClock.SetTime(time.Now())
cloudProvider.Reset()
queue.Reset()
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/provisioning/scheduling/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var _ = BeforeEach(func() {
})

var _ = AfterEach(func() {
ExpectCleanedUp(ctx, env.Client)
ExpectCleanedUp(ctx, env.Client, test.KruiseObjects...)
cluster.Reset()
scheduling.QueueDepth.Reset()
scheduling.SchedulingDurationSeconds.Reset()
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/provisioning/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var _ = AfterSuite(func() {
})

var _ = AfterEach(func() {
ExpectCleanedUp(ctx, env.Client)
ExpectCleanedUp(ctx, env.Client, test.KruiseObjects...)
cloudProvider.Reset()
cluster.Reset()
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/state/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var _ = BeforeEach(func() {
ExpectApplied(ctx, env.Client, nodePool)
})
var _ = AfterEach(func() {
ExpectCleanedUp(ctx, env.Client)
ExpectCleanedUp(ctx, env.Client, test.KruiseObjects...)
cluster.Reset()
cloudProvider.Reset()
})
Expand Down
10 changes: 3 additions & 7 deletions pkg/test/expectations/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import (
"github.com/awslabs/operatorpkg/status"
. "github.com/onsi/ginkgo/v2" //nolint:revive,stylecheck
. "github.com/onsi/gomega" //nolint:revive,stylecheck
kruisev1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
kruisev1beta1 "github.com/openkruise/kruise/apis/apps/v1beta1"
"github.com/prometheus/client_golang/prometheus"
prometheusmodel "github.com/prometheus/client_model/go"
"github.com/samber/lo"
Expand Down Expand Up @@ -218,13 +216,13 @@ func ExpectDeletionTimestampSet(ctx context.Context, c client.Client, objects ..
}
}

func ExpectCleanedUp(ctx context.Context, c client.Client) {
func ExpectCleanedUp(ctx context.Context, c client.Client, extendedResources ...client.Object) {
GinkgoHelper()
wg := sync.WaitGroup{}
namespaces := &corev1.NamespaceList{}
Expect(c.List(ctx, namespaces)).To(Succeed())
ExpectFinalizersRemovedFromList(ctx, c, &corev1.NodeList{}, &v1.NodeClaimList{}, &corev1.PersistentVolumeClaimList{})
for _, object := range []client.Object{
for _, object := range append([]client.Object{
&corev1.Pod{},
&corev1.Node{},
&appsv1.DaemonSet{},
Expand All @@ -236,9 +234,7 @@ func ExpectCleanedUp(ctx context.Context, c client.Client) {
&v1.NodePool{},
&v1alpha1.TestNodeClass{},
&v1.NodeClaim{},
&kruisev1beta1.StatefulSet{},
&kruisev1alpha1.DaemonSet{},
} {
}, extendedResources...) {
for _, namespace := range namespaces.Items {
wg.Add(1)
go func(object client.Object, namespace string) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/test/kruise.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
v1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// DaemonSetOptions customizes a DaemonSet.
Expand Down Expand Up @@ -1613,3 +1614,8 @@ var KruiseCRDs = []*apiextensionsv1.CustomResourceDefinition{
object.Unmarshal[apiextensionsv1.CustomResourceDefinition](KruiseDaemonSetCRD),
object.Unmarshal[apiextensionsv1.CustomResourceDefinition](KruiseStatefulSetCRD),
}

var KruiseObjects = []client.Object{
&kruisev1alpha1.DaemonSet{},
&kruisev1beta1.StatefulSet{},
}

0 comments on commit 1aa9cb3

Please sign in to comment.