-
Notifications
You must be signed in to change notification settings - Fork 54
NO-JIRA: Update e2e diagnostics #488
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
Open
theobarberbany
wants to merge
1
commit into
openshift:main
Choose a base branch
from
theobarberbany:tb/fix-e2e-diag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−56
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,10 +70,11 @@ localtestenv: .localtestenv | |
| TEST_DIRS ?= ./pkg/... ./manifests-gen/... | ||
| unit: .localtestenv ## Run unit tests | ||
| ./hack/test.sh "$(TEST_DIRS)" 20m | ||
| go test -count=1 -race -run TestDiagnostics ./e2e/... | ||
|
|
||
| .PHONY: e2e | ||
| e2e: ## Run e2e tests against active kubeconfig | ||
| ./hack/test.sh "./e2e/..." 120m | ||
| GINKGO_EXTRA_ARGS="--tags=e2e $(GINKGO_EXTRA_ARGS)" ./hack/test.sh "./e2e/..." 120m | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the tags doing here? |
||
|
|
||
| run: ## Run the operator against the configured Kubernetes cluster | ||
| oc -n openshift-cluster-api patch lease cluster-capi-operator-leader -p '{"spec":{"acquireTime": null, "holderIdentity": null, "renewTime": null}}' --type=merge | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| //go:build !e2e | ||
|
|
||
| // Copyright 2026 Red Hat, Inc. | ||
| // | ||
| // 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 e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/onsi/ginkgo/v2/types" | ||
| "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| // TestDiagnostics exercises the diagnostics-to-JUnit reporting logic | ||
| // without a live cluster. Run independently via: | ||
| // | ||
| // go test -run TestDiagnostics ./e2e/... | ||
| // | ||
| // BeforeSuite (which requires a cluster) does not fire because RunSpecs | ||
| // is not called. | ||
| func TestDiagnostics(t *testing.T) { | ||
| t.Run("live resource appears in output", func(t *testing.T) { | ||
| g := gomega.NewWithT(t) | ||
| withFakeClient(t, func() { | ||
| cm := &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "test-cm", Namespace: "default"}, | ||
| Data: map[string]string{"key": "value"}, | ||
| } | ||
| g.Expect(cl.Create(ctx, cm)).To(gomega.Succeed()) | ||
|
|
||
| resourcesUnderTest = []client.Object{cm} | ||
|
|
||
| diag := collectTrackedResourceDiagnostics(ctx) | ||
| g.Expect(diag).To(gomega.ContainSubstring("test-cm")) | ||
| g.Expect(diag).To(gomega.ContainSubstring("Test Failure Diagnostics")) | ||
| }) | ||
| }) | ||
|
|
||
| t.Run("deleted resource shows not found", func(t *testing.T) { | ||
| g := gomega.NewWithT(t) | ||
| withFakeClient(t, func() { | ||
| cm := &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "gone-cm", Namespace: "default"}, | ||
| } | ||
| resourcesUnderTest = []client.Object{cm} | ||
|
|
||
| diag := collectTrackedResourceDiagnostics(ctx) | ||
| g.Expect(diag).To(gomega.ContainSubstring("not found (deleted)")) | ||
| g.Expect(diag).To(gomega.ContainSubstring("gone-cm")) | ||
| }) | ||
| }) | ||
|
|
||
| t.Run("diagnosticsFromReport extracts entry", func(t *testing.T) { | ||
| g := gomega.NewWithT(t) | ||
|
|
||
| diagText := "\n=== Test Failure Diagnostics ===\nsome output\n=== End Test Failure Diagnostics ===\n" | ||
| sr := types.SpecReport{ | ||
| ReportEntries: types.ReportEntries{ | ||
| {Name: diagnosticsEntryName, Value: types.WrapEntryValue(diagText)}, | ||
| }, | ||
| } | ||
|
|
||
| result, found := diagnosticsFromReport(sr) | ||
| g.Expect(found).To(gomega.BeTrue()) | ||
| g.Expect(result).To(gomega.Equal(diagText)) | ||
| }) | ||
|
|
||
| t.Run("diagnosticsFromReport returns false when absent", func(t *testing.T) { | ||
| g := gomega.NewWithT(t) | ||
|
|
||
| sr := types.SpecReport{} | ||
|
|
||
| _, found := diagnosticsFromReport(sr) | ||
| g.Expect(found).To(gomega.BeFalse()) | ||
| }) | ||
|
|
||
| t.Run("diagnostics survive JSON round-trip", func(t *testing.T) { | ||
| g := gomega.NewWithT(t) | ||
|
|
||
| diagText := "\n=== Test Failure Diagnostics ===\nresource YAML here\n=== End Test Failure Diagnostics ===\n" | ||
| sr := types.SpecReport{ | ||
| ReportEntries: types.ReportEntries{ | ||
| {Name: diagnosticsEntryName, Value: types.WrapEntryValue(diagText)}, | ||
| }, | ||
| } | ||
|
|
||
| data, err := json.Marshal(sr) | ||
| g.Expect(err).NotTo(gomega.HaveOccurred()) | ||
|
|
||
| var deserialized types.SpecReport | ||
| g.Expect(json.Unmarshal(data, &deserialized)).To(gomega.Succeed()) | ||
|
|
||
| result, found := diagnosticsFromReport(deserialized) | ||
| g.Expect(found).To(gomega.BeTrue()) | ||
| g.Expect(result).To(gomega.Equal(diagText)) | ||
| }) | ||
| } | ||
|
|
||
| // withFakeClient swaps the package-level cl, ctx, and test state to a fake | ||
| // client for the duration of fn, restoring originals via t.Cleanup. | ||
| func withFakeClient(t *testing.T, fn func()) { | ||
| t.Helper() | ||
|
|
||
| origCl, origCtx := cl, ctx | ||
| origResources, origPlatform := resourcesUnderTest, platform | ||
|
|
||
| cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).Build() | ||
| ctx = context.Background() | ||
| resourcesUnderTest = nil | ||
| platform = "" | ||
|
|
||
| t.Cleanup(func() { | ||
| cl, ctx = origCl, origCtx | ||
| resourcesUnderTest, platform = origResources, origPlatform | ||
| }) | ||
|
|
||
| fn() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are TestDiagnostics and why do they run as part of the units now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just calls the e2e_diagnostics_test.go introduced in this PR. It's a quick check that the e2e -> j unit reporting is not broken, so we're not doing anything that will break this additional signal.
I decided to include in units as I didn't want to create another CI job that needs to schedule and run for 1 test. Not in e2e as wanted to be able to run locally / get early feedback.
Am open to moving it / changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the reasoning, but it looks a bit confusing IMO, if we can find a better way to do this, I'd be better I think :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put it in the e2e package, exclude with tags from normal runs and add a make target?