operator: isolate integration tests (#1651)

This commit is contained in:
3u13r 2023-04-18 14:20:41 +02:00 committed by GitHub
parent e335421dd2
commit bf0d169cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 123 additions and 31 deletions

View File

@ -23,6 +23,12 @@ import (
) )
var _ = Describe("AutoscalingStrategy controller", func() { var _ = Describe("AutoscalingStrategy controller", func() {
AfterEach(func() {
Eventually(func() error {
return resetEnv()
}, 30*time.Second, 1*time.Second).Should(Succeed())
})
// Define utility constants for object names and testing timeouts/durations and intervals. // Define utility constants for object names and testing timeouts/durations and intervals.
const ( const (
ClusterAutoscalerDeploymentName = "cluster-autoscaler" ClusterAutoscalerDeploymentName = "cluster-autoscaler"
@ -331,7 +337,7 @@ var _ = Describe("AutoscalingStrategy controller", func() {
return nil return nil
} }
return createdDeployment.Spec.Template.Spec.Containers[0].Command return createdDeployment.Spec.Template.Spec.Containers[0].Command
}, timeout, interval).Should(Equal([]string{ }, 2*time.Second, interval).Should(Equal([]string{
"./cluster-autoscaler", "./cluster-autoscaler",
"--baz=qux", "--baz=qux",
"--foo=bar", "--foo=bar",

View File

@ -27,36 +27,9 @@ import (
var _ = Describe("NodeVersion controller", func() { var _ = Describe("NodeVersion controller", func() {
AfterEach(func() { AfterEach(func() {
// cleanup all nodes Eventually(func() error {
nodeList := &corev1.NodeList{} return resetEnv()
Expect(k8sClient.List(context.Background(), nodeList)).To(Succeed()) }, 30*time.Second, 1*time.Second).Should(Succeed())
for _, node := range nodeList.Items {
Expect(k8sClient.Delete(context.Background(), &node)).To(Succeed())
}
// cleanup all node versions
nodeVersionList := &updatev1alpha1.NodeVersionList{}
Expect(k8sClient.List(context.Background(), nodeVersionList)).To(Succeed())
for _, nodeVersion := range nodeVersionList.Items {
Expect(k8sClient.Delete(context.Background(), &nodeVersion)).To(Succeed())
}
// cleanup all scaling groups
scalingGroupList := &updatev1alpha1.ScalingGroupList{}
Expect(k8sClient.List(context.Background(), scalingGroupList)).To(Succeed())
for _, scalingGroup := range scalingGroupList.Items {
Expect(k8sClient.Delete(context.Background(), &scalingGroup)).To(Succeed())
}
// cleanup all pending nodes
pendingNodeList := &updatev1alpha1.PendingNodeList{}
Expect(k8sClient.List(context.Background(), pendingNodeList)).To(Succeed())
for _, pendingNode := range pendingNodeList.Items {
Expect(k8sClient.Delete(context.Background(), &pendingNode)).To(Succeed())
}
// cleanup all joining nodes
joiningNodeList := &updatev1alpha1.JoiningNodeList{}
Expect(k8sClient.List(context.Background(), joiningNodeList)).To(Succeed())
for _, joiningNode := range joiningNodeList.Items {
Expect(k8sClient.Delete(context.Background(), &joiningNode)).To(Succeed())
}
}) })
// Define utility constants for object names and testing timeouts/durations and intervals. // Define utility constants for object names and testing timeouts/durations and intervals.

View File

@ -816,6 +816,17 @@ func (r *stubNodeReplacer) setCreatedNode(nodeName, providerID string, err error
r.createErr = err r.createErr = err
} }
func (r *stubNodeReplacer) reset() {
r.Lock()
defer r.Unlock()
r.nodeImages = nil
r.scalingGroups = nil
r.createNodeName = ""
r.createProviderID = ""
r.createErr = nil
r.deleteErr = nil
}
type stubKubernetesServerVersionGetter struct { type stubKubernetesServerVersionGetter struct {
version string version string
err error err error

View File

@ -24,6 +24,12 @@ import (
) )
var _ = Describe("PendingNode controller", func() { var _ = Describe("PendingNode controller", func() {
AfterEach(func() {
Eventually(func() error {
return resetEnv()
}, 30*time.Second, 1*time.Second).Should(Succeed())
})
// Define utility constants for object names and testing timeouts/durations and intervals. // Define utility constants for object names and testing timeouts/durations and intervals.
const ( const (
pendingNodeName = "pending-node" pendingNodeName = "pending-node"

View File

@ -21,6 +21,12 @@ import (
) )
var _ = Describe("ScalingGroup controller", func() { var _ = Describe("ScalingGroup controller", func() {
AfterEach(func() {
Eventually(func() error {
return resetEnv()
}, 30*time.Second, 1*time.Second).Should(Succeed())
})
// Define utility constants for object names and testing timeouts/durations and intervals. // Define utility constants for object names and testing timeouts/durations and intervals.
const ( const (
nodeVersionName = "node-version" nodeVersionName = "node-version"

View File

@ -34,3 +34,9 @@ func (u *fakeScalingGroupUpdater) SetScalingGroupImage(_ context.Context, scalin
u.scalingGroupImage[scalingGroupID] = imageURI u.scalingGroupImage[scalingGroupID] = imageURI
return nil return nil
} }
func (u *fakeScalingGroupUpdater) reset() {
u.Lock()
defer u.Unlock()
u.scalingGroupImage = make(map[string]string)
}

View File

@ -19,6 +19,8 @@ import (
nodemaintenancev1beta1 "github.com/edgelesssys/constellation/v2/3rdparty/node-maintenance-operator/api/v1beta1" nodemaintenancev1beta1 "github.com/edgelesssys/constellation/v2/3rdparty/node-maintenance-operator/api/v1beta1"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
testclock "k8s.io/utils/clock/testing" testclock "k8s.io/utils/clock/testing"
@ -45,6 +47,7 @@ var (
func TestAPIs(t *testing.T) { func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
// config.GinkgoConfig.RandomSeed = 1679587116
RunSpecs(t, "Controller Suite") RunSpecs(t, "Controller Suite")
} }
@ -141,6 +144,12 @@ type fakeCollection struct {
clock *testclock.FakeClock clock *testclock.FakeClock
} }
func (c *fakeCollection) reset() {
c.scalingGroupUpdater.reset()
c.nodeStateGetter.setNodeState("")
c.nodeReplacer.reset()
}
func newFakes() fakeCollection { func newFakes() fakeCollection {
return fakeCollection{ return fakeCollection{
scalingGroupUpdater: newFakeScalingGroupUpdater(), scalingGroupUpdater: newFakeScalingGroupUpdater(),
@ -150,3 +159,78 @@ func newFakes() fakeCollection {
clock: testclock.NewFakeClock(time.Now()), clock: testclock.NewFakeClock(time.Now()),
} }
} }
func resetEnv() error {
// cleanup all nodes
nodeList := &corev1.NodeList{}
if err := k8sClient.List(context.Background(), nodeList); err != nil {
return err
}
for _, node := range nodeList.Items {
if err := k8sClient.Delete(context.Background(), &node); err != nil {
return err
}
}
// cleanup all node versions
nodeVersionList := &updatev1alpha1.NodeVersionList{}
if err := k8sClient.List(context.Background(), nodeVersionList); err != nil {
return err
}
for _, nodeVersion := range nodeVersionList.Items {
if err := k8sClient.Delete(context.Background(), &nodeVersion); err != nil {
return err
}
}
// cleanup all scaling groups
scalingGroupList := &updatev1alpha1.ScalingGroupList{}
if err := k8sClient.List(context.Background(), scalingGroupList); err != nil {
return err
}
for _, scalingGroup := range scalingGroupList.Items {
if err := k8sClient.Delete(context.Background(), &scalingGroup); err != nil {
return err
}
}
// cleanup all pending nodes
pendingNodeList := &updatev1alpha1.PendingNodeList{}
if err := k8sClient.List(context.Background(), pendingNodeList); err != nil {
return err
}
for _, pendingNode := range pendingNodeList.Items {
if err := k8sClient.Delete(context.Background(), &pendingNode); err != nil {
return err
}
}
// cleanup all joining nodes
joiningNodeList := &updatev1alpha1.JoiningNodeList{}
if err := k8sClient.List(context.Background(), joiningNodeList); err != nil {
return err
}
for _, joiningNode := range joiningNodeList.Items {
if err := k8sClient.Delete(context.Background(), &joiningNode); err != nil {
return err
}
}
// cleanup all autoscaling strategies
autoscalingStrategyList := &updatev1alpha1.AutoscalingStrategyList{}
if err := k8sClient.List(context.Background(), autoscalingStrategyList); err != nil {
return err
}
for _, autoscalingStrategy := range autoscalingStrategyList.Items {
if err := k8sClient.Delete(context.Background(), &autoscalingStrategy); err != nil {
return err
}
}
// cleanup all deployments
deploymentList := &appsv1.DeploymentList{}
if err := k8sClient.List(context.Background(), deploymentList); err != nil {
return err
}
for _, deployment := range deploymentList.Items {
if err := k8sClient.Delete(context.Background(), &deployment); err != nil {
return err
}
}
fakes.reset()
return nil
}