operator: cleanup resources between tests (#1049)

This commit is contained in:
3u13r 2023-01-20 16:58:13 +01:00 committed by GitHub
parent bb6f35fbf4
commit effe797d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -86,7 +86,7 @@ func NewNodeVersionReconciler(nodeReplacer nodeReplacer, etcdRemover etcdRemover
//+kubebuilder:rbac:groups="",resources=nodes/status,verbs=get
//+kubebuilder:rbac:groups="",resources=configmaps,verbs=list;get
// Reconcile replaces outdated nodes (using an old image) with new nodes (using a new image) as specified in the NodeVersion spec.
// Reconcile replaces outdated nodes with new nodes as specified in the NodeVersion spec.
func (r *NodeVersionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logr := log.FromContext(ctx)
logr.Info("Reconciling NodeVersion")

View File

@ -26,6 +26,39 @@ import (
)
var _ = Describe("NodeVersion controller", func() {
AfterEach(func() {
// cleanup all nodes
nodeList := &corev1.NodeList{}
Expect(k8sClient.List(context.Background(), nodeList)).To(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.
const (
nodeVersionResourceName = "nodeversion"