-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added IT log file to gitignore * mapped RunInstances error codes to MCM ResourceExhausted error code if possible * added unit tests and license headers * lint errors addressed * addressed review comments
- Loading branch information
1 parent
d6dc30a
commit bf32415
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/tmp/* | ||
/dev | ||
/logs | ||
.ci/controllers-test/logs | ||
|
||
.vscode | ||
.idea | ||
|
This file contains 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,45 @@ | ||
/* | ||
Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. | ||
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 errors contains the error codes returned by Alicloud APIs | ||
package errors | ||
|
||
// constants for alicloud `RunInstances()` response error code which map to MCM `ResourceExhausted` code | ||
const ( | ||
// QuotaExceededDiskCapacity: The used capacity of disk type has exceeded the quota in the zone | ||
QuotaExceededDiskCapacity = "QuotaExceed.DiskCapacity" | ||
// QuotaExceededElasticQuota: The number of vCPUs assigned to the ECS instances has exceeded the quota in the zone. Please sign-on to Alibaba Cloud Console, and submit a quota increase application. | ||
QuotaExceededElasticQuota = "QuotaExceed.ElasticQuota" | ||
// OperationDeniedZoneSystemCategoryNotMatch: The specified Zone or cluster does not offer the specified disk category or the specified zone and cluster do not match. | ||
OperationDeniedZoneSystemCategoryNotMatch = "OperationDenied.ZoneSystemCategoryNotMatch" | ||
// OperationDeniedCloudSSDNotSupported: The specified available zone does not offer the cloud_ssd disk, use cloud_essd instead. | ||
OperationDeniedCloudSSDNotSupported = "OperationDenied.CloudSSDNotSupported" | ||
// OperationDeniedZoneNotAllowed: The creation of Instance to the specified Zone is not allowed. | ||
OperationDeniedZoneNotAllowed = "OperationDenied.ZoneNotAllowed" | ||
// OperationDeniedNoStock: The requested resource is sold out in the specified zone; try other types of resources or other regions and zones. | ||
OperationDeniedNoStock = "OperationDenied.NoStock" | ||
// ZoneNotOnSale: The resource in the specified zone is no longer available for sale. Please try other regions and zones. | ||
ZoneNotOnSale = "Zone.NotOnSale" | ||
// ZoneNotOpen: The specified zone is not granted to you to buy resources yet. | ||
ZoneNotOpen = "Zone.NotOpen" | ||
// InvalidVpcZone.NotSupported: The specified operation is not allowed in the zone to which your VPC belongs, please try in other zones. | ||
InvalidVpcZoneNotSupported = "InvalidVpcZone.NotSupported" | ||
// InvalidZoneIDNotSupportShareEncryptedImage: Creating instances by shared encrypted images is not supported in this zone. | ||
InvalidZoneIDNotSupportShareEncryptedImage = "InvalidZoneId.NotSupportShareEncryptedImage" | ||
// InvalidInstanceType.ZoneNotSupported: The specified zone does not support this instancetype. | ||
InvalidInstanceTypeZoneNotSupported = "InvalidInstanceType.ZoneNotSupported" | ||
// ResourceNotAvailable: Resource you requested is not available in this region or zone. | ||
ResourceNotAvailable = "ResourceNotAvailable" | ||
) |
This file contains 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 @@ | ||
/* | ||
Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. | ||
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 errors contains the error codes returned by Alicloud APIs | ||
package errors | ||
|
||
import ( | ||
alierr "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" | ||
"github.com/gardener/machine-controller-manager/pkg/util/provider/machinecodes/codes" | ||
) | ||
|
||
// GetMCMErrorCodeForCreateMachine takes the error returned from the EC2API during the CreateMachine call and returns the corresponding MCM error code. | ||
func GetMCMErrorCodeForCreateMachine(err error) codes.Code { | ||
aliErr, ok := err.(*alierr.ServerError) | ||
if ok { | ||
switch aliErr.ErrorCode() { | ||
case QuotaExceededDiskCapacity, QuotaExceededElasticQuota, OperationDeniedCloudSSDNotSupported, OperationDeniedNoStock, OperationDeniedZoneNotAllowed, OperationDeniedZoneSystemCategoryNotMatch, ZoneNotOnSale, ZoneNotOpen, InvalidVpcZoneNotSupported, InvalidInstanceTypeZoneNotSupported, InvalidZoneIDNotSupportShareEncryptedImage, ResourceNotAvailable: | ||
return codes.ResourceExhausted | ||
default: | ||
return codes.Internal | ||
} | ||
} | ||
return codes.Internal | ||
} |
This file contains 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,48 @@ | ||
/* | ||
Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved. | ||
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 errors | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
alierr "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" | ||
"github.com/gardener/machine-controller-manager/pkg/util/provider/machinecodes/codes" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
type input struct { | ||
inputAliErrorCode string | ||
expectedCode codes.Code | ||
} | ||
|
||
type responseContent struct { | ||
Code string | ||
} | ||
|
||
func TestCreateMachineErrorToMCMErrorCode(t *testing.T) { | ||
table := []input{ | ||
{inputAliErrorCode: OperationDeniedNoStock, expectedCode: codes.ResourceExhausted}, | ||
// InvalidImageId can't be resolved by trying another zone, so not treated as ResourceExhausted | ||
{inputAliErrorCode: "InvalidImageId.NotFound", expectedCode: codes.Internal}, | ||
} | ||
g := NewWithT(t) | ||
for _, entry := range table { | ||
jsonResponse, err := json.Marshal(responseContent{entry.inputAliErrorCode}) | ||
g.Expect(err).To(BeNil()) | ||
inputError := alierr.NewServerError(403, string(jsonResponse), "some error happened on the server side") | ||
g.Expect(GetMCMErrorCodeForCreateMachine(inputError)).To(Equal(entry.expectedCode)) | ||
} | ||
} |
This file contains 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