Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5042cea8
Commit
5042cea8
authored
Feb 09, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new clients for vmss cache
parent
3b7cc3dd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
5 deletions
+59
-5
azure_backoff.go
pkg/cloudprovider/providers/azure/azure_backoff.go
+47
-1
azure_client.go
pkg/cloudprovider/providers/azure/azure_client.go
+4
-0
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+0
-0
azure_vmss_cache.go
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
+8
-4
No files found.
pkg/cloudprovider/providers/azure/azure_backoff.go
View file @
5042cea8
...
@@ -17,13 +17,17 @@ limitations under the License.
...
@@ -17,13 +17,17 @@ limitations under the License.
package
azure
package
azure
import
(
import
(
"k8s.io/apimachinery/pkg/util/wait"
"context"
"net/http"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/Azure/azure-sdk-for-go/arm/network"
computepreview
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
)
)
// requestBackoff if backoff is disabled in cloud provider it
// requestBackoff if backoff is disabled in cloud provider it
...
@@ -345,6 +349,15 @@ func (az *Cloud) CreateOrUpdateVMWithRetry(vmName string, newVM compute.VirtualM
...
@@ -345,6 +349,15 @@ func (az *Cloud) CreateOrUpdateVMWithRetry(vmName string, newVM compute.VirtualM
})
})
}
}
// UpdateVmssVMWithRetry invokes az.VirtualMachineScaleSetVMsClient.Update with exponential backoff retry
func
(
az
*
Cloud
)
UpdateVmssVMWithRetry
(
ctx
context
.
Context
,
resourceGroupName
string
,
VMScaleSetName
string
,
instanceID
string
,
parameters
computepreview
.
VirtualMachineScaleSetVM
)
error
{
return
wait
.
ExponentialBackoff
(
az
.
requestBackoff
(),
func
()
(
bool
,
error
)
{
resp
,
err
:=
az
.
VirtualMachineScaleSetVMsClient
.
Update
(
ctx
,
resourceGroupName
,
VMScaleSetName
,
instanceID
,
parameters
)
glog
.
V
(
10
)
.
Infof
(
"VirtualMachinesClient.CreateOrUpdate(%s,%s): end"
,
VMScaleSetName
,
instanceID
)
return
processHTTPRetryResponse
(
resp
,
err
)
})
}
// A wait.ConditionFunc function to deal with common HTTP backoff response conditions
// A wait.ConditionFunc function to deal with common HTTP backoff response conditions
func
processRetryResponse
(
resp
autorest
.
Response
,
err
error
)
(
bool
,
error
)
{
func
processRetryResponse
(
resp
autorest
.
Response
,
err
error
)
(
bool
,
error
)
{
if
isSuccessHTTPResponse
(
resp
)
{
if
isSuccessHTTPResponse
(
resp
)
{
...
@@ -380,3 +393,36 @@ func isSuccessHTTPResponse(resp autorest.Response) bool {
...
@@ -380,3 +393,36 @@ func isSuccessHTTPResponse(resp autorest.Response) bool {
}
}
return
false
return
false
}
}
func
shouldRetryHTTPRequest
(
resp
*
http
.
Response
,
err
error
)
bool
{
if
err
!=
nil
{
return
true
}
if
resp
!=
nil
{
// HTTP 4xx or 5xx suggests we should retry
if
399
<
resp
.
StatusCode
&&
resp
.
StatusCode
<
600
{
return
true
}
}
return
false
}
func
processHTTPRetryResponse
(
resp
*
http
.
Response
,
err
error
)
(
bool
,
error
)
{
if
resp
!=
nil
{
// HTTP 2xx suggests a successful response
if
199
<
resp
.
StatusCode
&&
resp
.
StatusCode
<
300
{
return
true
,
nil
}
}
if
shouldRetryHTTPRequest
(
resp
,
err
)
{
glog
.
Errorf
(
"backoff: failure, will retry, HTTP response=%d, err=%v"
,
resp
.
StatusCode
,
err
)
// suppress the error object so that backoff process continues
return
false
,
nil
}
// Fall-through: stop periodic backoff
return
true
,
nil
}
pkg/cloudprovider/providers/azure/azure_client.go
View file @
5042cea8
...
@@ -140,6 +140,10 @@ type azVirtualMachinesClient struct {
...
@@ -140,6 +140,10 @@ type azVirtualMachinesClient struct {
rateLimiter
flowcontrol
.
RateLimiter
rateLimiter
flowcontrol
.
RateLimiter
}
}
func
getContextWithCancel
()
(
context
.
Context
,
context
.
CancelFunc
)
{
return
context
.
WithCancel
(
context
.
Background
())
}
func
newAzVirtualMachinesClient
(
config
*
azClientConfig
)
*
azVirtualMachinesClient
{
func
newAzVirtualMachinesClient
(
config
*
azClientConfig
)
*
azVirtualMachinesClient
{
virtualMachinesClient
:=
compute
.
NewVirtualMachinesClient
(
config
.
subscriptionID
)
virtualMachinesClient
:=
compute
.
NewVirtualMachinesClient
(
config
.
subscriptionID
)
virtualMachinesClient
.
BaseURI
=
config
.
resourceManagerEndpoint
virtualMachinesClient
.
BaseURI
=
config
.
resourceManagerEndpoint
...
...
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
5042cea8
This diff is collapsed.
Click to expand it.
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
View file @
5042cea8
...
@@ -58,7 +58,9 @@ func (ss *scaleSet) extractVmssVMName(name string) (string, string, error) {
...
@@ -58,7 +58,9 @@ func (ss *scaleSet) extractVmssVMName(name string) (string, string, error) {
func
(
ss
*
scaleSet
)
newVmssCache
()
(
*
timedCache
,
error
)
{
func
(
ss
*
scaleSet
)
newVmssCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
result
,
err
:=
ss
.
VirtualMachineScaleSetsClient
.
Get
(
ss
.
ResourceGroup
,
key
)
ctx
,
cancel
:=
getContextWithCancel
()
defer
cancel
()
result
,
err
:=
ss
.
VirtualMachineScaleSetsClient
.
Get
(
ctx
,
ss
.
ResourceGroup
,
key
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
if
realErr
!=
nil
{
return
nil
,
realErr
return
nil
,
realErr
...
@@ -76,14 +78,14 @@ func (ss *scaleSet) newVmssCache() (*timedCache, error) {
...
@@ -76,14 +78,14 @@ func (ss *scaleSet) newVmssCache() (*timedCache, error) {
func
(
ss
*
scaleSet
)
newNodeNameToScaleSetMappingCache
()
(
*
timedCache
,
error
)
{
func
(
ss
*
scaleSet
)
newNodeNameToScaleSetMappingCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
scaleSetNames
,
err
:=
ss
.
listScaleSets
WithRetry
()
scaleSetNames
,
err
:=
ss
.
listScaleSets
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
localCache
:=
make
(
nodeNameToScaleSetMapping
)
localCache
:=
make
(
nodeNameToScaleSetMapping
)
for
_
,
ssName
:=
range
scaleSetNames
{
for
_
,
ssName
:=
range
scaleSetNames
{
vms
,
err
:=
ss
.
listScaleSetVMs
WithRetry
(
ssName
)
vms
,
err
:=
ss
.
listScaleSetVMs
(
ssName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -136,7 +138,9 @@ func (ss *scaleSet) newVmssVMCache() (*timedCache, error) {
...
@@ -136,7 +138,9 @@ func (ss *scaleSet) newVmssVMCache() (*timedCache, error) {
return
nil
,
nil
return
nil
,
nil
}
}
result
,
err
:=
ss
.
VirtualMachineScaleSetVMsClient
.
Get
(
ss
.
ResourceGroup
,
ssName
,
instanceID
)
ctx
,
cancel
:=
getContextWithCancel
()
defer
cancel
()
result
,
err
:=
ss
.
VirtualMachineScaleSetVMsClient
.
Get
(
ctx
,
ss
.
ResourceGroup
,
ssName
,
instanceID
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
if
realErr
!=
nil
{
return
nil
,
realErr
return
nil
,
realErr
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment