This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
retrieving deployment error details during upgrade #1995
Merged
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5c6541b
return deployment status during upgrade
d0f23ae
Merge branch 'upstream-master' into ds-depl-err
37953d3
added deployment error
73e5020
Merge branch 'upstream-master' into ds-depl-err
b12322f
removed debug info
5e20b45
removed unrelated changes
9cca8cf
addressed comments
1ba9c12
Merge branch 'upstream-master' into ds-depl-err
a88c55b
tmp
46698a3
Merge branch 'upstream-master' into ds-depl-err
283ef52
revised logic
c4cae2c
refactored deployment error
7c40de0
fixed apierror_test
50669a1
Merge branch 'upstream-master' into ds-depl-err
283e3ac
fixed lint warning
59cce2a
changed func signature
8a84f96
added unittests for DeployTemplateSync
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 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,110 @@ | ||
package armhelpers | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/Azure/acs-engine/pkg/api" | ||
"github.com/Azure/azure-sdk-for-go/arm/resources/resources" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Error is the OData v4 format, used by the RPC and | ||
// will go into the v2.2 Azure REST API guidelines | ||
type Error struct { | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
Target string `json:"target,omitempty"` | ||
Details []Error `json:"details,omitempty"` | ||
} | ||
|
||
// ErrorResponse defines Resource Provider API 2.0 Error Response Content structure | ||
type ErrorResponse struct { | ||
Body Error `json:"error"` | ||
} | ||
|
||
// Error implements error interface to return error in json | ||
func (e *ErrorResponse) Error() string { | ||
return e.Body.Error() | ||
} | ||
|
||
// Error implements error interface to return error in json | ||
func (e *Error) Error() string { | ||
output, err := json.MarshalIndent(e, " ", " ") | ||
if err != nil { | ||
return err.Error() | ||
} | ||
return string(output) | ||
} | ||
|
||
func toArmError(logger *logrus.Entry, operation resources.DeploymentOperation) (*ErrorResponse, error) { | ||
errresp := &ErrorResponse{} | ||
if operation.Properties != nil && operation.Properties.StatusMessage != nil { | ||
b, err := json.MarshalIndent(operation.Properties.StatusMessage, "", " ") | ||
if err != nil { | ||
logger.Errorf("Error occurred marshalling JSON: '%v'", err) | ||
return nil, err | ||
} | ||
if err := json.Unmarshal(b, errresp); err != nil { | ||
logger.Errorf("Error occurred unmarshalling JSON: '%v' JSON: '%s'", err, string(b)) | ||
return nil, err | ||
} | ||
} | ||
return errresp, nil | ||
} | ||
|
||
func toArmErrors(logger *logrus.Entry, deploymentName string, operationsList resources.DeploymentOperationsListResult) ([]*ErrorResponse, error) { | ||
ret := []*ErrorResponse{} | ||
|
||
if operationsList.Value == nil { | ||
return ret, nil | ||
} | ||
|
||
for _, operation := range *operationsList.Value { | ||
if operation.Properties == nil || operation.Properties.ProvisioningState == nil || *operation.Properties.ProvisioningState != string(api.Failed) { | ||
continue | ||
} | ||
|
||
errresp, err := toArmError(logger, operation) | ||
if err != nil { | ||
logger.Warnf("unable to convert deployment operation to error response in deployment %s from ARM. error: %v", deploymentName, err) | ||
continue | ||
} | ||
|
||
if len(errresp.Body.Code) > 0 { | ||
logger.Warnf("got failed deployment operation in deployment %s. error: %v", deploymentName, errresp.Error()) | ||
} | ||
ret = append(ret, errresp) | ||
} | ||
return ret, nil | ||
} | ||
|
||
// GetDeploymentError returns deployment error | ||
func GetDeploymentError(az ACSEngineClient, logger *logrus.Entry, resourceGroupName, deploymentName string) ([]*ErrorResponse, error) { | ||
errList := []*ErrorResponse{} | ||
logger.Infof("Getting detailed deployment errors for %s", deploymentName) | ||
|
||
var top int32 = 1 | ||
operationList, err := az.ListDeploymentOperations(resourceGroupName, deploymentName, &top) | ||
if err != nil { | ||
logger.Warnf("unable to list deployment operations: %v", err) | ||
return nil, err | ||
} | ||
eList, err := toArmErrors(logger, deploymentName, operationList) | ||
if err != nil { | ||
return nil, err | ||
} | ||
errList = append(errList, eList...) | ||
for operationList.NextLink != nil { | ||
operationList, err = az.ListDeploymentOperationsNextResults(operationList) | ||
if err != nil { | ||
logger.Warnf("unable to list next deployment operations: %v", err) | ||
break | ||
} | ||
eList, err := toArmErrors(logger, deploymentName, operationList) | ||
if err != nil { | ||
return nil, err | ||
} | ||
errList = append(errList, eList...) | ||
} | ||
return errList, nil | ||
} |
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
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ package kubernetesupgrade | |
import ( | ||
"fmt" | ||
"math/rand" | ||
"strings" | ||
"time" | ||
|
||
"k8s.io/client-go/pkg/api/v1/node" | ||
|
@@ -87,11 +88,23 @@ func (kan *UpgradeAgentNode) CreateNode(poolName string, agentNo int) error { | |
kan.ParametersMap, | ||
nil) | ||
|
||
if err != nil { | ||
return err | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
return nil | ||
kan.logger.Errorf("Deployment %s failed with error %v", deploymentName, err) | ||
// Get deployment error details | ||
errRespList, e := armhelpers.GetDeploymentError(kan.Client, kan.logger, kan.ResourceGroup, deploymentName) | ||
if e != nil || len(errRespList) == 0 { | ||
kan.logger.Errorf("Failed to get error details for deployment %s: %v", deploymentName, e) | ||
// return original deployment error | ||
return err | ||
} | ||
errStrList := make([]string, len(errRespList)) | ||
for i, errResp := range errRespList { | ||
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. I thought you are changing it to return an array. why changed your mind? 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. I returned an array, but eventually have to turn it into an error |
||
errStrList[i] = errResp.Error() | ||
} | ||
return fmt.Errorf("%s", strings.Join(errStrList, " | ")) | ||
} | ||
|
||
// Validate will verify that agent node has been upgraded as expected. | ||
|
@@ -100,7 +113,7 @@ func (kan *UpgradeAgentNode) Validate(vmName *string) error { | |
kan.logger.Warningf("VM name was empty. Skipping node condition check") | ||
return nil | ||
} | ||
|
||
kan.logger.Infof("Validating %s", *vmName) | ||
var masterURL string | ||
if kan.UpgradeContainerService.Properties.HostedMasterProfile != nil { | ||
masterURL = kan.UpgradeContainerService.Properties.HostedMasterProfile.FQDN | ||
|
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.
is this recursive at all? I remember in C# there were errors stuffed inside other errors, and turtles all the way down.
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.
yes, Error.Error() is recursive.