Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 4d0b961

Browse files
committed
group related functions together
1 parent 462d923 commit 4d0b961

File tree

1 file changed

+65
-66
lines changed

1 file changed

+65
-66
lines changed

test/e2e/util.go

Lines changed: 65 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,71 @@ func ensureNamespaceExists(ctx context.Context) {
7373
Expect(client.IgnoreAlreadyExists(err)).NotTo(HaveOccurred())
7474
}
7575

76+
func cleanupTestObjectsPtr(ctx context.Context, appwrappersPtr *[]*arbv1.AppWrapper) {
77+
cleanupTestObjectsPtrVerbose(ctx, appwrappersPtr, true)
78+
}
79+
80+
func cleanupTestObjectsPtrVerbose(ctx context.Context, appwrappersPtr *[]*arbv1.AppWrapper, verbose bool) {
81+
if appwrappersPtr == nil {
82+
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjectsPtr] No AppWrappers to cleanup.\n")
83+
} else {
84+
cleanupTestObjects(ctx, *appwrappersPtr)
85+
}
86+
}
87+
88+
func cleanupTestObjects(ctx context.Context, appwrappers []*arbv1.AppWrapper) {
89+
cleanupTestObjectsVerbose(ctx, appwrappers, true)
90+
}
91+
92+
func cleanupTestObjectsVerbose(ctx context.Context, appwrappers []*arbv1.AppWrapper, verbose bool) {
93+
if appwrappers == nil {
94+
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] No AppWrappers to cleanup.\n")
95+
return
96+
}
97+
98+
for _, aw := range appwrappers {
99+
pods := getPodsOfAppWrapper(ctx, aw)
100+
awNamespace := aw.Namespace
101+
awName := aw.Name
102+
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] Deleting AW %s.\n", aw.Name)
103+
err := deleteAppWrapper(ctx, aw.Name, aw.Namespace)
104+
Expect(err).NotTo(HaveOccurred())
105+
106+
// Wait for the pods of the deleted the appwrapper to be destroyed
107+
for _, pod := range pods {
108+
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] Awaiting pod %s/%s to be deleted for AW %s.\n",
109+
pod.Namespace, pod.Name, aw.Name)
110+
}
111+
err = waitAWPodsDeleted(ctx, awNamespace, awName, pods)
112+
113+
// Final check to see if pod exists
114+
if err != nil {
115+
var podsStillExisting []*v1.Pod
116+
for _, pod := range pods {
117+
podExist := &v1.Pod{}
118+
err = getClient(ctx).Get(ctx, client.ObjectKey{Namespace: pod.Namespace, Name: pod.Name}, podExist)
119+
if err != nil {
120+
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] Found pod %s/%s %s, not completedly deleted for AW %s.\n", podExist.Namespace, podExist.Name, podExist.Status.Phase, aw.Name)
121+
podsStillExisting = append(podsStillExisting, podExist)
122+
}
123+
}
124+
if len(podsStillExisting) > 0 {
125+
err = waitAWPodsDeleted(ctx, awNamespace, awName, podsStillExisting)
126+
}
127+
}
128+
Expect(err).NotTo(HaveOccurred())
129+
}
130+
}
131+
132+
func deleteAppWrapper(ctx context.Context, name string, namespace string) error {
133+
foreground := metav1.DeletePropagationForeground
134+
aw := &arbv1.AppWrapper{ObjectMeta: metav1.ObjectMeta{
135+
Name: name,
136+
Namespace: namespace,
137+
}}
138+
return getClient(ctx).Delete(ctx, aw, &client.DeleteOptions{PropagationPolicy: &foreground})
139+
}
140+
76141
func anyPodsExist(ctx context.Context, awNamespace string, awName string) wait.ConditionFunc {
77142
return func() (bool, error) {
78143
podList := &v1.PodList{}
@@ -149,62 +214,6 @@ func podPhase(ctx context.Context, awNamespace string, awName string, pods []*v1
149214
}
150215
}
151216

152-
func cleanupTestObjectsPtr(ctx context.Context, appwrappersPtr *[]*arbv1.AppWrapper) {
153-
cleanupTestObjectsPtrVerbose(ctx, appwrappersPtr, true)
154-
}
155-
156-
func cleanupTestObjectsPtrVerbose(ctx context.Context, appwrappersPtr *[]*arbv1.AppWrapper, verbose bool) {
157-
if appwrappersPtr == nil {
158-
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjectsPtr] No AppWrappers to cleanup.\n")
159-
} else {
160-
cleanupTestObjects(ctx, *appwrappersPtr)
161-
}
162-
}
163-
164-
func cleanupTestObjects(ctx context.Context, appwrappers []*arbv1.AppWrapper) {
165-
cleanupTestObjectsVerbose(ctx, appwrappers, true)
166-
}
167-
168-
func cleanupTestObjectsVerbose(ctx context.Context, appwrappers []*arbv1.AppWrapper, verbose bool) {
169-
if appwrappers == nil {
170-
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] No AppWrappers to cleanup.\n")
171-
return
172-
}
173-
174-
for _, aw := range appwrappers {
175-
pods := getPodsOfAppWrapper(ctx, aw)
176-
awNamespace := aw.Namespace
177-
awName := aw.Name
178-
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] Deleting AW %s.\n", aw.Name)
179-
err := deleteAppWrapper(ctx, aw.Name, aw.Namespace)
180-
Expect(err).NotTo(HaveOccurred())
181-
182-
// Wait for the pods of the deleted the appwrapper to be destroyed
183-
for _, pod := range pods {
184-
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] Awaiting pod %s/%s to be deleted for AW %s.\n",
185-
pod.Namespace, pod.Name, aw.Name)
186-
}
187-
err = waitAWPodsDeleted(ctx, awNamespace, awName, pods)
188-
189-
// Final check to see if pod exists
190-
if err != nil {
191-
var podsStillExisting []*v1.Pod
192-
for _, pod := range pods {
193-
podExist := &v1.Pod{}
194-
err = getClient(ctx).Get(ctx, client.ObjectKey{Namespace: pod.Namespace, Name: pod.Name}, podExist)
195-
if err != nil {
196-
fmt.Fprintf(GinkgoWriter, "[cleanupTestObjects] Found pod %s/%s %s, not completedly deleted for AW %s.\n", podExist.Namespace, podExist.Name, podExist.Status.Phase, aw.Name)
197-
podsStillExisting = append(podsStillExisting, podExist)
198-
}
199-
}
200-
if len(podsStillExisting) > 0 {
201-
err = waitAWPodsDeleted(ctx, awNamespace, awName, podsStillExisting)
202-
}
203-
}
204-
Expect(err).NotTo(HaveOccurred())
205-
}
206-
}
207-
208217
func awPodPhase(ctx context.Context, aw *arbv1.AppWrapper, phase []v1.PodPhase, taskNum int, quite bool) wait.ConditionFunc {
209218
return func() (bool, error) {
210219
defer GinkgoRecover()
@@ -342,16 +351,6 @@ func waitAWPodsTerminatedExVerbose(ctx context.Context, namespace string, name s
342351
[]v1.PodPhase{v1.PodRunning, v1.PodSucceeded, v1.PodUnknown, v1.PodFailed, v1.PodPending}, taskNum))
343352
}
344353

345-
func deleteAppWrapper(ctx context.Context, name string, namespace string) error {
346-
foreground := metav1.DeletePropagationForeground
347-
aw := &arbv1.AppWrapper{ObjectMeta: metav1.ObjectMeta{
348-
Name: name,
349-
Namespace: namespace,
350-
}}
351-
return getClient(ctx).Delete(ctx, aw, &client.DeleteOptions{PropagationPolicy: &foreground})
352-
353-
}
354-
355354
func getPodsOfAppWrapper(ctx context.Context, aw *arbv1.AppWrapper) []*v1.Pod {
356355
awIgnored := &arbv1.AppWrapper{}
357356
err := getClient(ctx).Get(ctx, client.ObjectKeyFromObject(aw), awIgnored) // TODO: Do we actually need to do this Get?

0 commit comments

Comments
 (0)