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
2badf1ff
Commit
2badf1ff
authored
Feb 07, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cache for virtual machines
parent
035c8da6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
49 deletions
+40
-49
azure.go
pkg/cloudprovider/providers/azure/azure.go
+8
-0
azure_controllerCommon.go
pkg/cloudprovider/providers/azure/azure_controllerCommon.go
+2
-2
azure_test.go
pkg/cloudprovider/providers/azure/azure_test.go
+1
-0
azure_wrap.go
pkg/cloudprovider/providers/azure/azure_wrap.go
+29
-47
No files found.
pkg/cloudprovider/providers/azure/azure.go
View file @
2badf1ff
...
@@ -135,6 +135,8 @@ type Cloud struct {
...
@@ -135,6 +135,8 @@ type Cloud struct {
VirtualMachineScaleSetsClient
VirtualMachineScaleSetsClient
VirtualMachineScaleSetsClient
VirtualMachineScaleSetsClient
VirtualMachineScaleSetVMsClient
VirtualMachineScaleSetVMsClient
VirtualMachineScaleSetVMsClient
VirtualMachineScaleSetVMsClient
vmCache
*
timedCache
*
BlobDiskController
*
BlobDiskController
*
ManagedDiskController
*
ManagedDiskController
*
controllerCommon
*
controllerCommon
...
@@ -244,6 +246,12 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
...
@@ -244,6 +246,12 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
az
.
vmSet
=
newAvailabilitySet
(
&
az
)
az
.
vmSet
=
newAvailabilitySet
(
&
az
)
}
}
vmCache
,
err
:=
az
.
newVMCache
()
if
err
!=
nil
{
return
nil
,
err
}
az
.
vmCache
=
vmCache
if
err
:=
initDiskControllers
(
&
az
);
err
!=
nil
{
if
err
:=
initDiskControllers
(
&
az
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/cloudprovider/providers/azure/azure_controllerCommon.go
View file @
2badf1ff
...
@@ -124,7 +124,7 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
...
@@ -124,7 +124,7 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
}
else
{
}
else
{
glog
.
V
(
4
)
.
Info
(
"azureDisk - azure attach succeeded"
)
glog
.
V
(
4
)
.
Info
(
"azureDisk - azure attach succeeded"
)
// Invalidate the cache right after updating
// Invalidate the cache right after updating
vmCache
.
Delete
(
vmName
)
c
.
cloud
.
vmCache
.
Delete
(
vmName
)
}
}
return
err
return
err
}
}
...
@@ -183,7 +183,7 @@ func (c *controllerCommon) DetachDiskByName(diskName, diskURI string, nodeName t
...
@@ -183,7 +183,7 @@ func (c *controllerCommon) DetachDiskByName(diskName, diskURI string, nodeName t
}
else
{
}
else
{
glog
.
V
(
4
)
.
Info
(
"azureDisk - azure disk detach succeeded"
)
glog
.
V
(
4
)
.
Info
(
"azureDisk - azure disk detach succeeded"
)
// Invalidate the cache right after updating
// Invalidate the cache right after updating
vmCache
.
Delete
(
vmName
)
c
.
cloud
.
vmCache
.
Delete
(
vmName
)
}
}
return
err
return
err
}
}
...
...
pkg/cloudprovider/providers/azure/azure_test.go
View file @
2badf1ff
...
@@ -878,6 +878,7 @@ func getTestCloud() (az *Cloud) {
...
@@ -878,6 +878,7 @@ func getTestCloud() (az *Cloud) {
az
.
VirtualMachineScaleSetVMsClient
=
newFakeVirtualMachineScaleSetVMsClient
()
az
.
VirtualMachineScaleSetVMsClient
=
newFakeVirtualMachineScaleSetVMsClient
()
az
.
VirtualMachinesClient
=
newFakeAzureVirtualMachinesClient
()
az
.
VirtualMachinesClient
=
newFakeAzureVirtualMachinesClient
()
az
.
vmSet
=
newAvailabilitySet
(
az
)
az
.
vmSet
=
newAvailabilitySet
(
az
)
az
.
vmCache
,
_
=
az
.
newVMCache
()
return
az
return
az
}
}
...
...
pkg/cloudprovider/providers/azure/azure_wrap.go
View file @
2badf1ff
...
@@ -18,18 +18,20 @@ package azure
...
@@ -18,18 +18,20 @@ package azure
import
(
import
(
"net/http"
"net/http"
"sync"
"time"
"time"
"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"
"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"
)
)
var
(
vmCacheTTL
=
time
.
Minute
)
// 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.
...
@@ -60,59 +62,21 @@ func ignoreStatusNotFoundFromError(err error) error {
...
@@ -60,59 +62,21 @@ func ignoreStatusNotFoundFromError(err error) error {
return
err
return
err
}
}
// cache used by getVirtualMachine
// 15s for expiration duration
var
vmCache
=
newTimedcache
(
15
*
time
.
Second
)
type
vmRequest
struct
{
lock
*
sync
.
Mutex
vm
*
compute
.
VirtualMachine
}
/// getVirtualMachine calls 'VirtualMachinesClient.Get' with a timed cache
/// getVirtualMachine calls 'VirtualMachinesClient.Get' with a timed cache
/// The service side has throttling control that delays responses if there're multiple requests onto certain vm
/// The service side has throttling control that delays responses if there're multiple requests onto certain vm
/// resource request in short period.
/// resource request in short period.
func
(
az
*
Cloud
)
getVirtualMachine
(
nodeName
types
.
NodeName
)
(
vm
compute
.
VirtualMachine
,
err
error
)
{
func
(
az
*
Cloud
)
getVirtualMachine
(
nodeName
types
.
NodeName
)
(
vm
compute
.
VirtualMachine
,
err
error
)
{
vmName
:=
string
(
nodeName
)
vmName
:=
string
(
nodeName
)
cachedVM
,
err
:=
az
.
vmCache
.
Get
(
vmName
)
cachedRequest
,
err
:=
vmCache
.
GetOrCreate
(
vmName
,
func
()
interface
{}
{
return
&
vmRequest
{
lock
:
&
sync
.
Mutex
{},
vm
:
nil
,
}
})
if
err
!=
nil
{
if
err
!=
nil
{
return
compute
.
VirtualMachine
{},
err
return
vm
,
err
}
}
request
:=
cachedRequest
.
(
*
vmRequest
)
if
cachedVM
==
nil
{
if
request
.
vm
==
nil
{
return
vm
,
cloudprovider
.
InstanceNotFound
request
.
lock
.
Lock
()
defer
request
.
lock
.
Unlock
()
if
request
.
vm
==
nil
{
// Currently InstanceView request are used by azure_zones, while the calls come after non-InstanceView
// request. If we first send an InstanceView request and then a non InstanceView request, the second
// request will still hit throttling. This is what happens now for cloud controller manager: In this
// case we do get instance view every time to fulfill the azure_zones requirement without hitting
// throttling.
// Consider adding separate parameter for controlling 'InstanceView' once node update issue #56276 is fixed
vm
,
err
=
az
.
VirtualMachinesClient
.
Get
(
az
.
ResourceGroup
,
vmName
,
compute
.
InstanceView
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
return
vm
,
realErr
}
if
!
exists
{
return
vm
,
cloudprovider
.
InstanceNotFound
}
request
.
vm
=
&
vm
}
return
*
request
.
vm
,
nil
}
}
glog
.
V
(
6
)
.
Infof
(
"getVirtualMachine hits cache for(%s)"
,
vmName
)
return
*
(
cachedVM
.
(
*
compute
.
VirtualMachine
)),
nil
return
*
request
.
vm
,
nil
}
}
func
(
az
*
Cloud
)
getRouteTable
()
(
routeTable
network
.
RouteTable
,
exists
bool
,
err
error
)
{
func
(
az
*
Cloud
)
getRouteTable
()
(
routeTable
network
.
RouteTable
,
exists
bool
,
err
error
)
{
...
@@ -189,3 +153,21 @@ func (az *Cloud) getAzureLoadBalancer(name string) (lb network.LoadBalancer, exi
...
@@ -189,3 +153,21 @@ func (az *Cloud) getAzureLoadBalancer(name string) (lb network.LoadBalancer, exi
return
lb
,
exists
,
err
return
lb
,
exists
,
err
}
}
func
(
az
*
Cloud
)
newVMCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
vm
,
err
:=
az
.
VirtualMachinesClient
.
Get
(
az
.
ResourceGroup
,
key
,
compute
.
InstanceView
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
return
nil
,
realErr
}
if
!
exists
{
return
nil
,
nil
}
return
&
vm
,
nil
}
return
newTimedcache
(
vmCacheTTL
,
getter
)
}
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