-
Notifications
You must be signed in to change notification settings - Fork 244
OCPBUGS-14392: make sync status Failure logs human-readable #1440
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
pdudley
wants to merge
1
commit into
openshift:main
Choose a base branch
from
pdudley:OCPBUGS-14392
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.
+140
−6
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
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,107 @@ | ||
| package cvo | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
|
|
||
| "github.com/openshift/cluster-version-operator/pkg/payload" | ||
| ) | ||
|
|
||
| func TestSyncWorkerStatus_String(t *testing.T) { | ||
| hexAddr := regexp.MustCompile(`0x[0-9a-fA-F]+`) | ||
|
|
||
| t.Run("nil failures", func(t *testing.T) { | ||
| got := SyncWorkerStatus{}.String() | ||
| if strings.Contains(got, "0x") && hexAddr.MatchString(got) { | ||
| t.Fatalf("zero-value String() should not dump pointer addresses: %s", got) | ||
| } | ||
| if !strings.Contains(got, `failure="<none>"`) { | ||
| t.Fatalf("expected nil Failure as <none>: %s", got) | ||
| } | ||
| if !strings.Contains(got, `loadPayloadFailure="<none>"`) { | ||
| t.Fatalf("expected nil loadPayload Failure as <none>: %s", got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("apply sync failure", func(t *testing.T) { | ||
| msg := `Could not update deployment "openshift-cluster-version/cluster-version-operator" (33 of 33): timed out waiting for the condition` | ||
| status := SyncWorkerStatus{ | ||
| Generation: 4, | ||
| Failure: &payload.UpdateError{Reason: "UpdatePayloadResourceFailed", Message: msg}, | ||
| Done: 3, | ||
| Total: 33, | ||
| Completed: 0, | ||
| Reconciling: false, | ||
| Initial: true, | ||
| Actual: configv1.Release{ | ||
| Version: "4.14.0-0.nightly-2023-05-28-215458", | ||
| Image: "registry.ci.openshift.org/ocp/release@sha256:abc", | ||
| }, | ||
| loadPayloadStatus: LoadPayloadStatus{Step: "PayloadLoaded"}, | ||
| } | ||
| got := status.String() | ||
| if !strings.Contains(got, "Could not update deployment") || !strings.Contains(got, "timed out waiting for the condition") { | ||
| t.Fatalf("missing apply failure message:\n%s", got) | ||
| } | ||
| if !strings.Contains(got, `generation=4`) || !strings.Contains(got, `done=3/33`) { | ||
| t.Fatalf("missing scalar fields:\n%s", got) | ||
| } | ||
| if !strings.Contains(got, `loadPayloadStep="PayloadLoaded"`) { | ||
| t.Fatalf("missing loadPayloadStep:\n%s", got) | ||
| } | ||
| if hexAddr.MatchString(got) { | ||
| t.Fatalf("String() must not contain pointer addresses:\n%s", got) | ||
| } | ||
| // Contrast with %#v, which is the old buggy log format. | ||
| bad := fmt.Sprintf("%#v", &status) | ||
| if !strings.Contains(bad, "(*payload.UpdateError)") { | ||
| t.Fatalf("test assumption failed: %%#v should still dump UpdateError as a pointer:\n%s", bad) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("payload load failure", func(t *testing.T) { | ||
| loadMsg := `Retrieving payload failed version="4.14.0" image="img" failure=no such host` | ||
| status := SyncWorkerStatus{ | ||
| Generation: 5, | ||
| Failure: nil, | ||
| Actual: configv1.Release{Version: "4.14.0", Image: "img"}, | ||
| loadPayloadStatus: LoadPayloadStatus{ | ||
| Step: "RetrievePayload", | ||
| Message: loadMsg, | ||
| Failure: fmt.Errorf("%s", loadMsg), | ||
| }, | ||
| } | ||
| got := status.String() | ||
| if !strings.Contains(got, `failure="<none>"`) { | ||
| t.Fatalf("expected apply Failure <none>:\n%s", got) | ||
| } | ||
| if !strings.Contains(got, `loadPayloadStep="RetrievePayload"`) { | ||
| t.Fatalf("missing loadPayloadStep:\n%s", got) | ||
| } | ||
| if !strings.Contains(got, `loadPayloadFailure="`) || !strings.Contains(got, "Retrieving payload failed") || !strings.Contains(got, "no such host") { | ||
| t.Fatalf("missing loadPayloadFailure text:\n%s", got) | ||
| } | ||
| if hexAddr.MatchString(got) { | ||
| t.Fatalf("String() must not contain pointer addresses:\n%s", got) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestLoadPayloadStatus_String(t *testing.T) { | ||
| got := LoadPayloadStatus{ | ||
| Step: "VerifyPayloadVersion", | ||
| Message: "verifying", | ||
| Failure: fmt.Errorf("version mismatch"), | ||
| }.String() | ||
| wantSub := `step="VerifyPayloadVersion" message="verifying" failure="version mismatch"` | ||
| if got != wantSub { | ||
| t.Fatalf("got %q, want %q", got, wantSub) | ||
| } | ||
| if (LoadPayloadStatus{}).String() != `step="" message="" failure="<none>"` { | ||
| t.Fatalf("unexpected zero value: %s", (LoadPayloadStatus{}).String()) | ||
| } | ||
| } |
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.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/cluster-version-operator
Length of output: 50390
Information Disclosure (CWE-532): Insertion of Sensitive Information into Log File
Reachability: Internal
Reachability path
Redact sensitive fields in
SyncWorkerStatus.String()before klog writes them.String()returnsActual.Imageand unfiltered failure text; the klog sites log this shared string unchanged. Use an allow-listed, redacted image and failure representation in the formatter and pass that sanitized status into theklogcall sites inpkg/cvo/sync_worker.goandpkg/cvo/status.go.📍 Affects 2 files
pkg/cvo/sync_worker.go#L164-L176(this comment)pkg/cvo/sync_worker.go#L742-L742pkg/cvo/sync_worker.go#L944-L950pkg/cvo/sync_worker.go#L972-L978pkg/cvo/status.go#L165-L165🤖 Prompt for AI Agents
Source: Coding guidelines