Skip to content

Commit

Permalink
Add error output for api-resources command
Browse files Browse the repository at this point in the history
ref: https://issues.redhat.com/browse/ACM-5849
Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
  • Loading branch information
dhaiducek committed Jun 7, 2023
1 parent 6cfcd7e commit 3244778
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
38 changes: 28 additions & 10 deletions test/e2e/case18_discovery_refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
. "github.com/onsi/gomega"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"

"open-cluster-management.io/config-policy-controller/test/utils"
Expand Down Expand Up @@ -61,21 +62,38 @@ var _ = Describe("Test discovery info refresh", Ordered, func() {

By("Checking that the API causes an error during API discovery")
Eventually(
func() error {
cmd := exec.Command("kubectl", "api-resources")

err := cmd.Start()
if err != nil {
return nil // Just retry. If this consistently has an error, the test should fail.
func(g Gomega) {
apiService := utils.GetWithTimeout(
clientManagedDynamic,
gvrAPIService,
"v1beta1.pizza.example.com",
"",
true,
defaultTimeoutSeconds,
)

apiStatus, _, err := unstructured.NestedSlice(apiService.Object, "status", "conditions")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(apiStatus).ToNot(BeEmpty())

statusFound := false
for _, status := range apiStatus {
if status, ok := status.(map[string]interface{}); ok {
if status["type"] == "Available" {
g.Expect(status["status"]).To(Equal("False"))
g.Expect(status["reason"]).To(Equal("ServiceNotFound"))
statusFound = true
}
}
}

err = cmd.Wait()

return err
if !statusFound {
Fail("Failed to find 'Available' status for APIService")
}
},
defaultTimeoutSeconds,
1,
).ShouldNot(BeNil())
).Should(Succeed())

By("Creating the prerequisites on managed")
// This needs to be wrapped in an eventually since the object can't be created immediately after the CRD
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
kubeconfigManaged string
clientManaged kubernetes.Interface
clientManagedDynamic dynamic.Interface
gvrAPIService schema.GroupVersionResource
gvrConfigPolicy schema.GroupVersionResource
gvrCRD schema.GroupVersionResource
gvrPod schema.GroupVersionResource
Expand Down Expand Up @@ -71,6 +72,11 @@ var _ = BeforeSuite(func() {
Version: "v1",
Resource: "configurationpolicies",
}
gvrAPIService = schema.GroupVersionResource{
Group: "apiregistration.k8s.io",
Version: "v1",
Resource: "apiservices",
}
gvrCRD = schema.GroupVersionResource{
Group: "apiextensions.k8s.io",
Version: "v1",
Expand Down

0 comments on commit 3244778

Please sign in to comment.