From ce1b69a46346af79dc84b278e00cef0b65decdac Mon Sep 17 00:00:00 2001 From: Danail Branekov Date: Mon, 15 Jan 2024 11:13:56 +0000 Subject: [PATCH] Print cforg namespace in fail handler Hopefully this would give us more information why org deletion times out in smoke tests Co-authored-by: Georgi Sabev --- tests/smoke/smoke_suite_test.go | 42 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/smoke/smoke_suite_test.go b/tests/smoke/smoke_suite_test.go index 54163958f..5f41fe230 100644 --- a/tests/smoke/smoke_suite_test.go +++ b/tests/smoke/smoke_suite_test.go @@ -18,6 +18,7 @@ import ( . "github.com/onsi/gomega/gexec" gomegatypes "github.com/onsi/gomega/types" "gopkg.in/yaml.v2" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/kubernetes/scheme" @@ -126,6 +127,22 @@ func printCfApp(config *rest.Config) { return } + cfOrgNamespaceName, err := sessionOutput(helpers.Cf("org", orgName, "--guid")) + if err != nil { + fmt.Fprintf(GinkgoWriter, "failed to run 'cf org %s --guid': %v\n", orgName, err) + return + } + + err = printObject(k8sClient, &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: cfOrgNamespaceName, + }, + }) + if err != nil { + fmt.Fprintf(GinkgoWriter, "failed printing cforg namespace: %v\n", err) + return + } + cfAppNamespace, err := sessionOutput(helpers.Cf("space", spaceName, "--guid")) if err != nil { fmt.Fprintf(GinkgoWriter, "failed to run 'cf space %s --guid': %v\n", spaceName, err) @@ -137,24 +154,29 @@ func printCfApp(config *rest.Config) { return } - cfApp := &korifiv1alpha1.CFApp{ + err = printObject(k8sClient, &korifiv1alpha1.CFApp{ ObjectMeta: metav1.ObjectMeta{ Name: cfAppGUID, Namespace: cfAppNamespace, }, + }) + if err != nil { + fmt.Fprintf(GinkgoWriter, "failed printing cfapp: %v\n", err) + return } +} - if err = k8sClient.Get(context.Background(), client.ObjectKeyFromObject(cfApp), cfApp); err != nil { - fmt.Fprintf(GinkgoWriter, "failed to get cfapp in namespace %q: %v\n", cfAppNamespace, err) - return +func printObject(k8sClient client.Client, obj client.Object) error { + if err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(obj), obj); err != nil { + return fmt.Errorf("failed to get object %q: %v\n", client.ObjectKeyFromObject(obj), err) } - fmt.Fprintf(GinkgoWriter, "\n\n========== cfapp %s/%s (skipping managed fields) ==========\n", cfApp.Namespace, cfApp.Name) - cfApp.ManagedFields = []metav1.ManagedFieldsEntry{} - cfAppBytes, err := yaml.Marshal(cfApp) + fmt.Fprintf(GinkgoWriter, "\n\n========== %T %s/%s (skipping managed fields) ==========\n", obj, obj.GetNamespace(), obj.GetName()) + obj.SetManagedFields([]metav1.ManagedFieldsEntry{}) + objBytes, err := yaml.Marshal(obj) if err != nil { - fmt.Fprintf(GinkgoWriter, "failed marshalling cfapp: %v\n", err) - return + return fmt.Errorf("failed marshalling object %v: %v\n", obj, err) } - fmt.Fprintln(GinkgoWriter, string(cfAppBytes)) + fmt.Fprintln(GinkgoWriter, string(objBytes)) + return nil }