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 all org namespaces on org deletion timeout #3166

Merged
merged 1 commit into from
Mar 13, 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
40 changes: 27 additions & 13 deletions tests/smoke/smoke_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"testing"

"code.cloudfoundry.org/korifi/api/repositories"
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/tests/helpers"
"code.cloudfoundry.org/korifi/tests/helpers/fail_handler"
Expand Down Expand Up @@ -60,6 +61,9 @@ func TestSmoke(t *testing.T) {
},
})
},
ContainSubstring("Org deletion timed out"): func(config *rest.Config, _ string) {
printOrgNamespaces(config)
},
}))
SetDefaultEventuallyTimeout(helpers.EventuallyTimeout())
SetDefaultEventuallyPollingInterval(helpers.EventuallyPollingInterval())
Expand Down Expand Up @@ -119,27 +123,38 @@ func sessionOutput(session *Session) (string, error) {
return strings.TrimSpace(string(session.Out.Contents())), nil
}

func printCfApp(config *rest.Config) {
func printOrgNamespaces(config *rest.Config) {
utilruntime.Must(korifiv1alpha1.AddToScheme(scheme.Scheme))
k8sClient, err := client.New(config, client.Options{Scheme: scheme.Scheme})
if err != nil {
fmt.Fprintf(GinkgoWriter, "failed to create k8s client: %v\n", err)
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)
namespaces := &corev1.NamespaceList{}
if err := k8sClient.List(context.Background(), namespaces); err != nil {
fmt.Fprintf(GinkgoWriter, "failed to list namespaces: %v\n", err)
return
}

err = printObject(k8sClient, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: cfOrgNamespaceName,
},
})
for _, namespace := range namespaces.Items {
if !strings.Contains(namespace.Name, repositories.OrgPrefix) {
continue
}

fmt.Fprintln(GinkgoWriter, "CFOrg deletion timed out! Printing all Org namespaces:")
if err := printObject(k8sClient, &namespace); err != nil {
fmt.Fprintf(GinkgoWriter, "failed printing namespace: %v\n", err)
return
}
}
}

func printCfApp(config *rest.Config) {
utilruntime.Must(korifiv1alpha1.AddToScheme(scheme.Scheme))
k8sClient, err := client.New(config, client.Options{Scheme: scheme.Scheme})
if err != nil {
fmt.Fprintf(GinkgoWriter, "failed printing cforg namespace: %v\n", err)
fmt.Fprintf(GinkgoWriter, "failed to create k8s client: %v\n", err)
return
}

Expand All @@ -154,13 +169,12 @@ func printCfApp(config *rest.Config) {
return
}

err = printObject(k8sClient, &korifiv1alpha1.CFApp{
if err := printObject(k8sClient, &korifiv1alpha1.CFApp{
ObjectMeta: metav1.ObjectMeta{
Name: cfAppGUID,
Namespace: cfAppNamespace,
},
})
if err != nil {
}); err != nil {
fmt.Fprintf(GinkgoWriter, "failed printing cfapp: %v\n", err)
return
}
Expand Down
Loading