Skip to content

Commit

Permalink
Merge pull request #144 from razo7/va-redudant
Browse files Browse the repository at this point in the history
Remove redundant VoulmeAttachment from testing
  • Loading branch information
openshift-merge-bot[bot] authored Jul 25, 2024
2 parents 4233210 + 6dfd0ed commit ae0561c
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions controllers/fenceagentsremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -44,8 +43,6 @@ const (
fenceAgentIPMI = "fence_ipmilan"
farPodName = "far-pod"
testPodName = "far-pod-test-1"
vaName1 = "va-test-1"
vaName2 = "va-test-2"

// intervals
timeoutPreRemediation = "1s" // this timeout is used for the other steps that occur before remediation is completed
Expand Down Expand Up @@ -134,10 +131,8 @@ var _ = Describe("FAR Controller", func() {

BeforeEach(func() {
// Create two VAs and two pods, and at the end clean them up with DeferCleanup
va1 := createVA(vaName1, workerNode)
va2 := createVA(vaName2, workerNode)
testPod := createRunningPod("far-test-1", testPodName, workerNode)
DeferCleanup(cleanupTestedResources, va1, va2, testPod)
DeferCleanup(cleanupTestedResources, testPod)

farPod := createRunningPod("far-manager-test", farPodName, "")
DeferCleanup(k8sClient.Delete, context.Background(), farPod)
Expand Down Expand Up @@ -499,37 +494,9 @@ func createRunningPod(containerName, podName, nodeName string) *corev1.Pod {
return pod
}

// createVA creates new volume attachment and return its object
func createVA(vaName, unhealthyNodeName string) *storagev1.VolumeAttachment {
va := &storagev1.VolumeAttachment{
ObjectMeta: metav1.ObjectMeta{
Name: vaName,
Namespace: defaultNamespace,
},
Spec: storagev1.VolumeAttachmentSpec{
Attacher: "foo",
Source: storagev1.VolumeAttachmentSource{},
NodeName: unhealthyNodeName,
},
}
foo := "foo"
va.Spec.Source.PersistentVolumeName = &foo
ExpectWithOffset(1, k8sClient.Create(context.Background(), va)).To(Succeed())
return va
}

// cleanupTestedResources fetches all the resources that we have crated for the test
// and if they are still exist at the end of the test, then we clean them up for next test
func cleanupTestedResources(va1, va2 *storagev1.VolumeAttachment, pod *corev1.Pod) {
for _, va := range []*storagev1.VolumeAttachment{va1, va2} {
vaTest := &storagev1.VolumeAttachment{}
key := client.ObjectKeyFromObject(va)
if err := k8sClient.Get(context.Background(), key, vaTest); err == nil {
log.Info("Cleanup: clean volume attachment", "va name", vaTest.Name)
Expect(k8sClient.Delete(context.Background(), vaTest)).To(Succeed())
}
}

func cleanupTestedResources(pod *corev1.Pod) {
podTest := &corev1.Pod{}
key := client.ObjectKeyFromObject(pod)
if err := k8sClient.Get(context.Background(), key, podTest); err == nil {
Expand Down

0 comments on commit ae0561c

Please sign in to comment.