-
Notifications
You must be signed in to change notification settings - Fork 110
admin api: Serial Console Retrieval #4257
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
rajdeepc2792
wants to merge
13
commits into
main
Choose a base branch
from
rajdeepc2792/ARO-17482
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.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6982436
ARO-17482 admin-api nodepool VM serial console logs
rajdeepc2792 303e699
ARO-17482 admin-api serial console unit-test
rajdeepc2792 91a50e6
ARO-17482 admin-api serial console GA e2e
rajdeepc2792 f890a44
ARO-17482 admin-api serial console README update
rajdeepc2792 3021a07
ARO-17482 lint fix
rajdeepc2792 fb55ec2
ARO-17482 resolve PR comments
rajdeepc2792 a642b3e
ARO-17482 resolve copilot comments
rajdeepc2792 cb2e1a7
ARO-17482 update e2e fixtures
rajdeepc2792 007c1bf
ARO-17482 limit blob reader and other fix
rajdeepc2792 5491e73
ARO-17482 get tenant id from subscription doc
rajdeepc2792 0471720
ARO-17482 copilot fixes
rajdeepc2792 f3f21e4
ARO-17482 resolve mockDBClient conflicts
rajdeepc2792 c715df0
ARO-17482 remove the obvious comments
rajdeepc2792 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
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,38 @@ | ||
| // Copyright 2025 Microsoft Corporation | ||
| // | ||
| // 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 hcp | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| ocmerrors "github.com/openshift-online/ocm-sdk-go/errors" | ||
|
|
||
| "github.com/Azure/ARO-HCP/internal/api/arm" | ||
| ) | ||
|
|
||
| // ClusterServiceError checks if err is an OCM not-found error and returns a | ||
| // specific CloudError. This prevents ReportError from misinterpreting it as | ||
| // "HCP resource not found" (the HCP was already found in the database). | ||
| // Non-OCM errors are wrapped for ReportError to handle as internal errors. | ||
| func ClusterServiceError(err error, what string) error { | ||
| var ocmErr *ocmerrors.Error | ||
| if errors.As(err, &ocmErr) && ocmErr.Status() == http.StatusNotFound { | ||
| return arm.NewCloudError(http.StatusNotFound, arm.CloudErrorCodeNotFound, "", | ||
| "%s not found in cluster service", what) | ||
| } | ||
| return fmt.Errorf("failed to get %s from cluster service: %w", what, err) | ||
| } | ||
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,147 @@ | ||
| // Copyright 2025 Microsoft Corporation | ||
| // | ||
| // 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 hcp | ||
|
|
||
| import ( | ||
| "errors" | ||
| "net/http" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| ocmerrors "github.com/openshift-online/ocm-sdk-go/errors" | ||
|
|
||
| "github.com/Azure/ARO-HCP/internal/api/arm" | ||
| ) | ||
|
|
||
| func TestClusterServiceError(t *testing.T) { | ||
| // Helper to create OCM errors | ||
| createOCMError := func(status int) error { | ||
| ocmErr, err := ocmerrors.NewError().Status(status).Build() | ||
| if err != nil { | ||
| t.Fatalf("Failed to create OCM error: %v", err) | ||
| } | ||
| return ocmErr | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| err error | ||
| what string | ||
| expectedStatusCode int | ||
| expectedErrorCode string | ||
| expectedMessage string | ||
| isCloudError bool | ||
| }{ | ||
| { | ||
| name: "OCM not-found error returns 404 CloudError", | ||
| err: createOCMError(http.StatusNotFound), | ||
| what: "cluster data", | ||
| expectedStatusCode: http.StatusNotFound, | ||
| expectedErrorCode: arm.CloudErrorCodeNotFound, | ||
| expectedMessage: "cluster data not found in cluster service", | ||
| isCloudError: true, | ||
| }, | ||
| { | ||
| name: "OCM not-found error for hypershift details", | ||
| err: createOCMError(http.StatusNotFound), | ||
| what: "hypershift details", | ||
| expectedStatusCode: http.StatusNotFound, | ||
| expectedErrorCode: arm.CloudErrorCodeNotFound, | ||
| expectedMessage: "hypershift details not found in cluster service", | ||
| isCloudError: true, | ||
| }, | ||
| { | ||
| name: "OCM internal server error wraps error", | ||
| err: createOCMError(http.StatusInternalServerError), | ||
| what: "cluster data", | ||
| expectedMessage: "failed to get cluster data from cluster service", | ||
| isCloudError: false, | ||
| }, | ||
| { | ||
| name: "OCM bad request error wraps error", | ||
| err: createOCMError(http.StatusBadRequest), | ||
| what: "provision shard", | ||
| expectedMessage: "failed to get provision shard from cluster service", | ||
| isCloudError: false, | ||
| }, | ||
| { | ||
| name: "OCM unauthorized error wraps error", | ||
| err: createOCMError(http.StatusUnauthorized), | ||
| what: "cluster data", | ||
| expectedMessage: "failed to get cluster data from cluster service", | ||
| isCloudError: false, | ||
| }, | ||
| { | ||
| name: "non-OCM error wraps error", | ||
| err: errors.New("network timeout"), | ||
| what: "cluster data", | ||
| expectedMessage: "failed to get cluster data from cluster service", | ||
| isCloudError: false, | ||
| }, | ||
| { | ||
| name: "generic error wraps error", | ||
| err: errors.New("connection refused"), | ||
| what: "hypershift details", | ||
| expectedMessage: "failed to get hypershift details from cluster service", | ||
| isCloudError: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := ClusterServiceError(tt.err, tt.what) | ||
|
|
||
| if result == nil { | ||
| t.Fatal("Expected error but got nil") | ||
| } | ||
|
|
||
| if tt.isCloudError { | ||
| // Check if it's a CloudError | ||
| var cloudErr *arm.CloudError | ||
| if !errors.As(result, &cloudErr) { | ||
| t.Fatalf("Expected CloudError but got %T: %v", result, result) | ||
| } | ||
|
|
||
| if cloudErr.StatusCode != tt.expectedStatusCode { | ||
| t.Errorf("Expected status code %d, got %d", tt.expectedStatusCode, cloudErr.StatusCode) | ||
| } | ||
|
|
||
| if cloudErr.Code != tt.expectedErrorCode { | ||
| t.Errorf("Expected error code %q, got %q", tt.expectedErrorCode, cloudErr.Code) | ||
| } | ||
|
|
||
| if cloudErr.Message != tt.expectedMessage { | ||
| t.Errorf("Expected message %q, got %q", tt.expectedMessage, cloudErr.Message) | ||
| } | ||
| } else { | ||
| // Check if it's a wrapped error (not CloudError) | ||
| var cloudErr *arm.CloudError | ||
| if errors.As(result, &cloudErr) { | ||
| t.Fatalf("Expected wrapped error but got CloudError: %v", result) | ||
| } | ||
|
|
||
| // Verify error message contains expected text | ||
| if !strings.Contains(result.Error(), tt.expectedMessage) { | ||
| t.Errorf("Expected error to contain %q, got %q", tt.expectedMessage, result.Error()) | ||
| } | ||
|
|
||
| // Verify original error is wrapped | ||
| if !errors.Is(result, tt.err) { | ||
| t.Errorf("Expected error to wrap original error") | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Initially in the PR this was being used by the serialconsolelogs implementation, but since it no longer uses it, this can be moved back to breakglass. But decided to keep it here for any similar future use.
Please comment if anyone feel against moving the function here in this PR.