mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 21:53:52 +00:00
Merge pull request #64248 from feiskyer/exact-err-msg
Automatic merge from submit-queue (batch tested with PRs 63319, 64248, 64250, 63890, 64233). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add reason message logs for non-exist Azure resources **What this PR does / why we need it**: In azure_wrap.go the function checkResourceExistsFromError() looks at a received error and determines it to be a ResourceNotFound if the HTTP status is http.StatusNotFound. However, the HTTP status also equals http.StatusNotFound in case of SubscriptionNotFound. this PR adds logs to indict the real error messages for such case. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #64220 **Special notes for your reviewer**: **Release note**: ```release-note Add reason message logs for non-exist Azure resources ```
This commit is contained in:
@@ -67,12 +67,13 @@ func (ss *scaleSet) newVmssCache() (*timedCache, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
result, err := ss.VirtualMachineScaleSetsClient.Get(ctx, ss.ResourceGroup, key)
|
result, err := ss.VirtualMachineScaleSetsClient.Get(ctx, ss.ResourceGroup, key)
|
||||||
exists, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Virtual machine scale set %q not found with message: %q", key, message)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,12 +148,13 @@ func (ss *scaleSet) newVmssVMCache() (*timedCache, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
result, err := ss.VirtualMachineScaleSetVMsClient.Get(ctx, ss.ResourceGroup, ssName, instanceID)
|
result, err := ss.VirtualMachineScaleSetVMsClient.Get(ctx, ss.ResourceGroup, ssName, instanceID)
|
||||||
exists, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Virtual machine scale set VM %q not found with message: %q", key, message)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
|
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
|
||||||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
|
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
@@ -40,18 +41,18 @@ var (
|
|||||||
// checkExistsFromError inspects an error and returns a true if err is nil,
|
// checkExistsFromError inspects an error and returns a true if err is nil,
|
||||||
// false if error is an autorest.Error with StatusCode=404 and will return the
|
// false if error is an autorest.Error with StatusCode=404 and will return the
|
||||||
// error back if error is another status code or another type of error.
|
// error back if error is another status code or another type of error.
|
||||||
func checkResourceExistsFromError(err error) (bool, error) {
|
func checkResourceExistsFromError(err error) (bool, string, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return true, nil
|
return true, "", nil
|
||||||
}
|
}
|
||||||
v, ok := err.(autorest.DetailedError)
|
v, ok := err.(autorest.DetailedError)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, err
|
return false, "", err
|
||||||
}
|
}
|
||||||
if v.StatusCode == http.StatusNotFound {
|
if v.StatusCode == http.StatusNotFound {
|
||||||
return false, nil
|
return false, err.Error(), nil
|
||||||
}
|
}
|
||||||
return false, v
|
return false, "", v
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it is StatusNotFound return nil,
|
// If it is StatusNotFound return nil,
|
||||||
@@ -104,15 +105,17 @@ func (az *Cloud) getPublicIPAddress(pipResourceGroup string, pipName string) (pi
|
|||||||
}
|
}
|
||||||
|
|
||||||
var realErr error
|
var realErr error
|
||||||
|
var message string
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
pip, err = az.PublicIPAddressesClient.Get(ctx, resourceGroup, pipName, "")
|
pip, err = az.PublicIPAddressesClient.Get(ctx, resourceGroup, pipName, "")
|
||||||
exists, realErr = checkResourceExistsFromError(err)
|
exists, message, realErr = checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return pip, false, realErr
|
return pip, false, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Public IP %q not found with message: %q", pipName, message)
|
||||||
return pip, false, nil
|
return pip, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +124,7 @@ func (az *Cloud) getPublicIPAddress(pipResourceGroup string, pipName string) (pi
|
|||||||
|
|
||||||
func (az *Cloud) getSubnet(virtualNetworkName string, subnetName string) (subnet network.Subnet, exists bool, err error) {
|
func (az *Cloud) getSubnet(virtualNetworkName string, subnetName string) (subnet network.Subnet, exists bool, err error) {
|
||||||
var realErr error
|
var realErr error
|
||||||
|
var message string
|
||||||
var rg string
|
var rg string
|
||||||
|
|
||||||
if len(az.VnetResourceGroup) > 0 {
|
if len(az.VnetResourceGroup) > 0 {
|
||||||
@@ -132,12 +136,13 @@ func (az *Cloud) getSubnet(virtualNetworkName string, subnetName string) (subnet
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
subnet, err = az.SubnetsClient.Get(ctx, rg, virtualNetworkName, subnetName, "")
|
subnet, err = az.SubnetsClient.Get(ctx, rg, virtualNetworkName, subnetName, "")
|
||||||
exists, realErr = checkResourceExistsFromError(err)
|
exists, message, realErr = checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return subnet, false, realErr
|
return subnet, false, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Subnet %q not found with message: %q", subnetName, message)
|
||||||
return subnet, false, nil
|
return subnet, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,12 +186,13 @@ func (az *Cloud) newVMCache() (*timedCache, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
vm, err := az.VirtualMachinesClient.Get(ctx, az.ResourceGroup, key, compute.InstanceView)
|
vm, err := az.VirtualMachinesClient.Get(ctx, az.ResourceGroup, key, compute.InstanceView)
|
||||||
exists, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Virtual machine %q not found with message: %q", key, message)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,12 +208,13 @@ func (az *Cloud) newLBCache() (*timedCache, error) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
lb, err := az.LoadBalancerClient.Get(ctx, az.ResourceGroup, key, "")
|
lb, err := az.LoadBalancerClient.Get(ctx, az.ResourceGroup, key, "")
|
||||||
exists, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Load balancer %q not found with message: %q", key, message)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,12 +229,13 @@ func (az *Cloud) newNSGCache() (*timedCache, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
nsg, err := az.SecurityGroupsClient.Get(ctx, az.ResourceGroup, key, "")
|
nsg, err := az.SecurityGroupsClient.Get(ctx, az.ResourceGroup, key, "")
|
||||||
exists, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Security group %q not found with message: %q", key, message)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,12 +250,13 @@ func (az *Cloud) newRouteTableCache() (*timedCache, error) {
|
|||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
rt, err := az.RouteTablesClient.Get(ctx, az.ResourceGroup, key, "")
|
rt, err := az.RouteTablesClient.Get(ctx, az.ResourceGroup, key, "")
|
||||||
exists, realErr := checkResourceExistsFromError(err)
|
exists, message, realErr := checkResourceExistsFromError(err)
|
||||||
if realErr != nil {
|
if realErr != nil {
|
||||||
return nil, realErr
|
return nil, realErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.V(2).Infof("Route table %q not found with message: %q", key, message)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ func TestExtractNotFound(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
exists, err := checkResourceExistsFromError(test.err)
|
exists, _, err := checkResourceExistsFromError(test.err)
|
||||||
if test.exists != exists {
|
if test.exists != exists {
|
||||||
t.Errorf("expected: %v, saw: %v", test.exists, exists)
|
t.Errorf("expected: %v, saw: %v", test.exists, exists)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user