Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print cforg namespace in fail handler #3062

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions tests/smoke/smoke_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}