Skip to content

Commit

Permalink
Print all org namespaces on org deletion timeout
Browse files Browse the repository at this point in the history
Co-authored-by: Georgi Sabev <[email protected]>
  • Loading branch information
danail-branekov and georgethebeatle committed Mar 13, 2024
1 parent bcc7014 commit b263ac7
Showing 1 changed file with 27 additions and 13 deletions.
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

0 comments on commit b263ac7

Please sign in to comment.