-
Notifications
You must be signed in to change notification settings - Fork 108
feat: AKS machine API interface and clients #1183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f6143e2
chore: bump armcontainerservice to v7.3.0-beta.1
comtalyst 9047922
Merge remote-tracking branch 'origin/main' into comtalyst/bump-acs-v7…
comtalyst 7f8ad37
Merge branch 'main' into comtalyst/bump-acs-v7.3.0-beta
comtalyst 543dddc
chore: merge conflict
comtalyst db9c0b8
feat: AKS machine API interface and clients
comtalyst 381467f
feat: reachability toggle with no-client
comtalyst 51f99d4
refactor: rename AKS_MACHINES_REACHABLE to MANAGE_EXISTING_AKS_MACHINES
comtalyst b7c96bc
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst 9624690
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst 68d027d
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst a4ad618
chore: update module to v8
comtalyst 872a80a
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst 0a9bc70
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst 2c19bd3
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst 17bbf00
refactor: apply suggestions
comtalyst 919575a
docs: add clarifications on no-client
comtalyst ed49a5d
refactor: rename dry client to no-client
comtalyst a8816ae
Merge branch 'main' into comtalyst/aks-machine-api-clients
comtalyst 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,36 @@ | ||
| /* | ||
| Portions Copyright (c) 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 instance | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| sdkerrors "github.com/Azure/azure-sdk-for-go-extensions/pkg/errors" | ||
| ) | ||
|
|
||
| func IsAKSMachineOrMachinesPoolNotFound(err error) bool { | ||
| if err == nil { | ||
| return false | ||
| } | ||
| azErr := sdkerrors.IsResponseError(err) | ||
| if azErr != nil && (azErr.StatusCode == http.StatusNotFound || // Covers AKS machines pool not found on PUT machine, GET machine, GET (list) machines, POST agent pool (DELETE machines), and AKS machine not found on GET machine | ||
| (azErr.StatusCode == http.StatusBadRequest && azErr.ErrorCode == "InvalidParameter" && strings.Contains(azErr.Error(), "Cannot find any valid machines"))) { // Covers AKS machine not found on POST agent pool (DELETE machines) | ||
| return true | ||
| } | ||
| return false | ||
| } |
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,105 @@ | ||
| /* | ||
| Portions Copyright (c) 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 instance | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| // createAzureResponseError creates a proper Azure SDK error with the given error code and message | ||
| func createAzureResponseError(errorCode, errorMessage string, statusCode int) error { | ||
| errorBody := fmt.Sprintf(`{"error": {"code": "%s", "message": "%s"}}`, errorCode, errorMessage) | ||
| return &azcore.ResponseError{ | ||
| ErrorCode: errorCode, | ||
| StatusCode: statusCode, | ||
| RawResponse: &http.Response{ | ||
| Body: io.NopCloser(strings.NewReader(errorBody)), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| var _ = Describe("AKSMachineInstanceUtils Helper Functions", func() { | ||
|
|
||
| Context("IsAKSMachineOrMachinesPoolNotFound", func() { | ||
| It("should return false for nil error", func() { | ||
| result := IsAKSMachineOrMachinesPoolNotFound(nil) | ||
| Expect(result).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("should return true for HTTP 404 status code", func() { | ||
| azureError := &azcore.ResponseError{ | ||
| ErrorCode: "lol", | ||
| StatusCode: 404, | ||
| RawResponse: nil, | ||
| } | ||
|
|
||
| result := IsAKSMachineOrMachinesPoolNotFound(azureError) | ||
| Expect(result).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("should return true for InvalidParameter error with 'Cannot find any valid machines' message", func() { | ||
| // Create the exact error message from your example | ||
| errorMessage := "Cannot find any valid machines to delete. Please check your input machine names. The valid machines to delete in agent pool 'testmpool' are: testmachine." | ||
| azureError := createAzureResponseError("InvalidParameter", errorMessage, 400) | ||
|
|
||
| result := IsAKSMachineOrMachinesPoolNotFound(azureError) | ||
| Expect(result).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("should return false for HTTP 400 with InvalidParameter but different message", func() { | ||
| // Create an InvalidParameter error with a different message that shouldn't match | ||
| differentMessage := "InvalidParameter: Some other validation error" | ||
| azureError := createAzureResponseError("InvalidParameter", differentMessage, 400) | ||
|
|
||
| result := IsAKSMachineOrMachinesPoolNotFound(azureError) | ||
| Expect(result).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("should return false for other HTTP status codes", func() { | ||
| azureError := &azcore.ResponseError{ | ||
| ErrorCode: "Unauthorized", | ||
| StatusCode: 401, | ||
| RawResponse: nil, | ||
| } | ||
|
|
||
| result := IsAKSMachineOrMachinesPoolNotFound(azureError) | ||
| Expect(result).To(BeFalse()) | ||
|
|
||
| azureError = &azcore.ResponseError{ | ||
| ErrorCode: "InternalOperationError", | ||
| StatusCode: 500, | ||
| RawResponse: nil, | ||
| } | ||
|
|
||
| result = IsAKSMachineOrMachinesPoolNotFound(azureError) | ||
| Expect(result).To(BeFalse()) | ||
| }) | ||
|
|
||
| It("should return false for non-Azure SDK errors", func() { | ||
| result := IsAKSMachineOrMachinesPoolNotFound(fmt.Errorf("some generic error")) | ||
| Expect(result).To(BeFalse()) | ||
| }) | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.