mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-26 19:35:10 +00:00
When a Gomega failure is converted to an error, the stack at the time when the failure occurs may be useful: error wrapping provides some bread crumbs that can be followed to determine where the failure really occurred, but error wrapping may be missing or ambiguous. To provide the additional information, a FailureError now includes a full stack backtrace. The backtrace intentionally makes no attempt to exclude framework functions besides the gomega support itself because helpers like e2e/framework/pod may be relevant. That backtrace is not included in the failure message for the sake of brevity. Instead, it gets logged as part of the test's output.
367 lines
12 KiB
Go
367 lines
12 KiB
Go
/*
|
|
Copyright 2022 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package pod_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/onsi/ginkgo/v2"
|
|
"github.com/onsi/ginkgo/v2/reporters"
|
|
"github.com/onsi/gomega"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
"k8s.io/kubernetes/test/e2e/framework/internal/output"
|
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
|
_ "k8s.io/kubernetes/test/utils/format" // activate YAML object dumps
|
|
)
|
|
|
|
// The line number of the following code is checked in TestFailureOutput below.
|
|
// Be careful when moving it around or changing the import statements above.
|
|
// Here are some intentionally blank lines that can be removed to compensate
|
|
// for future additional import statements.
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// This must be line #50.
|
|
|
|
var _ = ginkgo.Describe("pod", func() {
|
|
ginkgo.It("not found, must exist", func(ctx context.Context) {
|
|
gomega.Eventually(ctx, framework.HandleRetry(getNoSuchPod)).WithTimeout(timeout).Should(e2epod.BeInPhase(v1.PodRunning))
|
|
})
|
|
|
|
ginkgo.It("not found, retry", func(ctx context.Context) {
|
|
framework.ExpectNoError(e2epod.WaitTimeoutForPodRunningInNamespace(ctx, clientSet, "no-such-pod", "default", timeout))
|
|
})
|
|
|
|
ginkgo.It("not found, retry with wrappers", func(ctx context.Context) {
|
|
gomega.Eventually(ctx, framework.RetryNotFound(framework.HandleRetry(getNoSuchPod))).WithTimeout(timeout).Should(e2epod.BeInPhase(v1.PodRunning))
|
|
})
|
|
|
|
ginkgo.It("not found, retry with inverted wrappers", func(ctx context.Context) {
|
|
gomega.Eventually(ctx, framework.HandleRetry(framework.RetryNotFound(getNoSuchPod))).WithTimeout(timeout).Should(e2epod.BeInPhase(v1.PodRunning))
|
|
})
|
|
|
|
ginkgo.It("not running", func(ctx context.Context) {
|
|
ginkgo.By(fmt.Sprintf("waiting for pod %s to run", podName))
|
|
framework.ExpectNoError(e2epod.WaitTimeoutForPodRunningInNamespace(ctx, clientSet, podName, podNamespace, timeout))
|
|
})
|
|
|
|
ginkgo.It("failed", func(ctx context.Context) {
|
|
framework.ExpectNoError(e2epod.WaitTimeoutForPodRunningInNamespace(ctx, clientSet, failedPodName, podNamespace, timeout))
|
|
})
|
|
})
|
|
|
|
func getNoSuchPod(ctx context.Context) (*v1.Pod, error) {
|
|
return clientSet.CoreV1().Pods("default").Get(ctx, "no-such-pod", metav1.GetOptions{})
|
|
}
|
|
|
|
const (
|
|
podName = "pending-pod"
|
|
podNamespace = "default"
|
|
failedPodName = "failed-pod"
|
|
timeout = time.Second
|
|
)
|
|
|
|
var (
|
|
clientSet = fake.NewSimpleClientset(
|
|
&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: podName, Namespace: podNamespace}, Status: v1.PodStatus{Phase: v1.PodPending}},
|
|
&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: failedPodName, Namespace: podNamespace}, Status: v1.PodStatus{Phase: v1.PodFailed}},
|
|
)
|
|
)
|
|
|
|
func TestFailureOutput(t *testing.T) {
|
|
|
|
expected := output.TestResult{
|
|
NormalizeOutput: func(in string) string {
|
|
return regexp.MustCompile(`wait.go:[[:digit:]]*`).ReplaceAllString(in, `wait.go`)
|
|
},
|
|
Suite: reporters.JUnitTestSuite{
|
|
Tests: 6,
|
|
Failures: 6,
|
|
Errors: 0,
|
|
Disabled: 0,
|
|
Skipped: 0,
|
|
TestCases: []reporters.JUnitTestCase{
|
|
{
|
|
Name: "[It] pod not found, must exist",
|
|
Status: "failed",
|
|
Failure: &reporters.JUnitFailure{
|
|
Type: "failed",
|
|
Description: `[FAILED] Told to stop trying after <after>.
|
|
Unexpected final error while getting *v1.Pod: pods "no-such-pod" not found
|
|
In [It] at: wait_test.go:54 <time>
|
|
`,
|
|
},
|
|
SystemErr: `> Enter [It] not found, must exist - wait_test.go:53 <time>
|
|
[FAILED] Told to stop trying after <after>.
|
|
Unexpected final error while getting *v1.Pod: pods "no-such-pod" not found
|
|
In [It] at: wait_test.go:54 <time>
|
|
< Exit [It] not found, must exist - wait_test.go:53 <time>
|
|
`,
|
|
},
|
|
{
|
|
Name: "[It] pod not found, retry",
|
|
Status: "failed",
|
|
Failure: &reporters.JUnitFailure{
|
|
Type: "failed",
|
|
Description: `[FAILED] Timed out after <after>.
|
|
The function passed to Eventually returned the following error:
|
|
pods "no-such-pod" not found
|
|
<framework.transientError>: {
|
|
error: <*errors.StatusError>{
|
|
ErrStatus: {
|
|
TypeMeta: {Kind: "", APIVersion: ""},
|
|
ListMeta: {
|
|
SelfLink: "",
|
|
ResourceVersion: "",
|
|
Continue: "",
|
|
RemainingItemCount: nil,
|
|
},
|
|
Status: "Failure",
|
|
Message: "pods \"no-such-pod\" not found",
|
|
Reason: "NotFound",
|
|
Details: {Name: "no-such-pod", Group: "", Kind: "pods", UID: "", Causes: nil, RetryAfterSeconds: 0},
|
|
Code: 404,
|
|
},
|
|
},
|
|
}
|
|
In [It] at: wait_test.go:58 <time>
|
|
`,
|
|
},
|
|
SystemErr: `> Enter [It] not found, retry - wait_test.go:57 <time>
|
|
INFO: Failed inside E2E framework:
|
|
k8s.io/kubernetes/test/e2e/framework/pod.WaitTimeoutForPodRunningInNamespace()
|
|
wait.go
|
|
k8s.io/kubernetes/test/e2e/framework/pod_test.glob..func1.2()
|
|
wait_test.go:58
|
|
[FAILED] Timed out after <after>.
|
|
The function passed to Eventually returned the following error:
|
|
pods "no-such-pod" not found
|
|
<framework.transientError>: {
|
|
error: <*errors.StatusError>{
|
|
ErrStatus: {
|
|
TypeMeta: {Kind: "", APIVersion: ""},
|
|
ListMeta: {
|
|
SelfLink: "",
|
|
ResourceVersion: "",
|
|
Continue: "",
|
|
RemainingItemCount: nil,
|
|
},
|
|
Status: "Failure",
|
|
Message: "pods \"no-such-pod\" not found",
|
|
Reason: "NotFound",
|
|
Details: {Name: "no-such-pod", Group: "", Kind: "pods", UID: "", Causes: nil, RetryAfterSeconds: 0},
|
|
Code: 404,
|
|
},
|
|
},
|
|
}
|
|
In [It] at: wait_test.go:58 <time>
|
|
< Exit [It] not found, retry - wait_test.go:57 <time>
|
|
`,
|
|
},
|
|
{
|
|
Name: "[It] pod not found, retry with wrappers",
|
|
Status: "failed",
|
|
Failure: &reporters.JUnitFailure{
|
|
Type: "failed",
|
|
Description: `[FAILED] Timed out after <after>.
|
|
The function passed to Eventually returned the following error:
|
|
pods "no-such-pod" not found
|
|
<framework.transientError>: {
|
|
error: <*errors.StatusError>{
|
|
ErrStatus: {
|
|
TypeMeta: {Kind: "", APIVersion: ""},
|
|
ListMeta: {
|
|
SelfLink: "",
|
|
ResourceVersion: "",
|
|
Continue: "",
|
|
RemainingItemCount: nil,
|
|
},
|
|
Status: "Failure",
|
|
Message: "pods \"no-such-pod\" not found",
|
|
Reason: "NotFound",
|
|
Details: {Name: "no-such-pod", Group: "", Kind: "pods", UID: "", Causes: nil, RetryAfterSeconds: 0},
|
|
Code: 404,
|
|
},
|
|
},
|
|
}
|
|
In [It] at: wait_test.go:62 <time>
|
|
`,
|
|
},
|
|
SystemErr: `> Enter [It] not found, retry with wrappers - wait_test.go:61 <time>
|
|
[FAILED] Timed out after <after>.
|
|
The function passed to Eventually returned the following error:
|
|
pods "no-such-pod" not found
|
|
<framework.transientError>: {
|
|
error: <*errors.StatusError>{
|
|
ErrStatus: {
|
|
TypeMeta: {Kind: "", APIVersion: ""},
|
|
ListMeta: {
|
|
SelfLink: "",
|
|
ResourceVersion: "",
|
|
Continue: "",
|
|
RemainingItemCount: nil,
|
|
},
|
|
Status: "Failure",
|
|
Message: "pods \"no-such-pod\" not found",
|
|
Reason: "NotFound",
|
|
Details: {Name: "no-such-pod", Group: "", Kind: "pods", UID: "", Causes: nil, RetryAfterSeconds: 0},
|
|
Code: 404,
|
|
},
|
|
},
|
|
}
|
|
In [It] at: wait_test.go:62 <time>
|
|
< Exit [It] not found, retry with wrappers - wait_test.go:61 <time>
|
|
`,
|
|
},
|
|
{
|
|
Name: "[It] pod not found, retry with inverted wrappers",
|
|
Status: "failed",
|
|
Failure: &reporters.JUnitFailure{
|
|
Type: "failed",
|
|
Description: `[FAILED] Timed out after <after>.
|
|
The function passed to Eventually returned the following error:
|
|
pods "no-such-pod" not found
|
|
<framework.transientError>: {
|
|
error: <*errors.StatusError>{
|
|
ErrStatus: {
|
|
TypeMeta: {Kind: "", APIVersion: ""},
|
|
ListMeta: {
|
|
SelfLink: "",
|
|
ResourceVersion: "",
|
|
Continue: "",
|
|
RemainingItemCount: nil,
|
|
},
|
|
Status: "Failure",
|
|
Message: "pods \"no-such-pod\" not found",
|
|
Reason: "NotFound",
|
|
Details: {Name: "no-such-pod", Group: "", Kind: "pods", UID: "", Causes: nil, RetryAfterSeconds: 0},
|
|
Code: 404,
|
|
},
|
|
},
|
|
}
|
|
In [It] at: wait_test.go:66 <time>
|
|
`,
|
|
},
|
|
SystemErr: `> Enter [It] not found, retry with inverted wrappers - wait_test.go:65 <time>
|
|
[FAILED] Timed out after <after>.
|
|
The function passed to Eventually returned the following error:
|
|
pods "no-such-pod" not found
|
|
<framework.transientError>: {
|
|
error: <*errors.StatusError>{
|
|
ErrStatus: {
|
|
TypeMeta: {Kind: "", APIVersion: ""},
|
|
ListMeta: {
|
|
SelfLink: "",
|
|
ResourceVersion: "",
|
|
Continue: "",
|
|
RemainingItemCount: nil,
|
|
},
|
|
Status: "Failure",
|
|
Message: "pods \"no-such-pod\" not found",
|
|
Reason: "NotFound",
|
|
Details: {Name: "no-such-pod", Group: "", Kind: "pods", UID: "", Causes: nil, RetryAfterSeconds: 0},
|
|
Code: 404,
|
|
},
|
|
},
|
|
}
|
|
In [It] at: wait_test.go:66 <time>
|
|
< Exit [It] not found, retry with inverted wrappers - wait_test.go:65 <time>
|
|
`,
|
|
},
|
|
{
|
|
Name: "[It] pod not running",
|
|
Status: "failed",
|
|
Failure: &reporters.JUnitFailure{
|
|
Description: `[FAILED] Timed out after <after>.
|
|
Expected Pod to be in <v1.PodPhase>: "Running"
|
|
Got instead:
|
|
<*v1.Pod>:
|
|
metadata:
|
|
creationTimestamp: null
|
|
name: pending-pod
|
|
namespace: default
|
|
spec:
|
|
containers: null
|
|
status:
|
|
phase: Pending
|
|
In [It] at: wait_test.go:71 <time>
|
|
`,
|
|
Type: "failed",
|
|
},
|
|
SystemErr: `> Enter [It] not running - wait_test.go:69 <time>
|
|
STEP: waiting for pod pending-pod to run - wait_test.go:70 <time>
|
|
INFO: Failed inside E2E framework:
|
|
k8s.io/kubernetes/test/e2e/framework/pod.WaitTimeoutForPodRunningInNamespace()
|
|
wait.go
|
|
k8s.io/kubernetes/test/e2e/framework/pod_test.glob..func1.5()
|
|
wait_test.go:71
|
|
[FAILED] Timed out after <after>.
|
|
Expected Pod to be in <v1.PodPhase>: "Running"
|
|
Got instead:
|
|
<*v1.Pod>:
|
|
metadata:
|
|
creationTimestamp: null
|
|
name: pending-pod
|
|
namespace: default
|
|
spec:
|
|
containers: null
|
|
status:
|
|
phase: Pending
|
|
In [It] at: wait_test.go:71 <time>
|
|
< Exit [It] not running - wait_test.go:69 <time>
|
|
`,
|
|
},
|
|
{
|
|
Name: "[It] pod failed",
|
|
Status: "failed",
|
|
Failure: &reporters.JUnitFailure{
|
|
Description: `[FAILED] Told to stop trying after <after>.
|
|
Expected pod to reach phase "Running", got final phase "Failed" instead.
|
|
In [It] at: wait_test.go:75 <time>
|
|
`,
|
|
Type: "failed",
|
|
},
|
|
SystemErr: `> Enter [It] failed - wait_test.go:74 <time>
|
|
INFO: Failed inside E2E framework:
|
|
k8s.io/kubernetes/test/e2e/framework/pod.WaitTimeoutForPodRunningInNamespace()
|
|
wait.go
|
|
k8s.io/kubernetes/test/e2e/framework/pod_test.glob..func1.6()
|
|
wait_test.go:75
|
|
[FAILED] Told to stop trying after <after>.
|
|
Expected pod to reach phase "Running", got final phase "Failed" instead.
|
|
In [It] at: wait_test.go:75 <time>
|
|
< Exit [It] failed - wait_test.go:74 <time>
|
|
`,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
output.TestGinkgoOutput(t, expected)
|
|
}
|