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
4d5e7b7c
Commit
4d5e7b7c
authored
Feb 11, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use generic cache for vmss
parent
f0e573d6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
195 additions
and
1 deletion
+195
-1
azure.go
pkg/cloudprovider/providers/azure/azure.go
+4
-1
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+0
-0
azure_vmss_cache.go
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
+191
-0
No files found.
pkg/cloudprovider/providers/azure/azure.go
View file @
4d5e7b7c
...
@@ -244,7 +244,10 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
...
@@ -244,7 +244,10 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
}
}
if
strings
.
EqualFold
(
vmTypeVMSS
,
az
.
Config
.
VMType
)
{
if
strings
.
EqualFold
(
vmTypeVMSS
,
az
.
Config
.
VMType
)
{
az
.
vmSet
=
newScaleSet
(
&
az
)
az
.
vmSet
,
err
=
newScaleSet
(
&
az
)
if
err
!=
nil
{
return
nil
,
err
}
}
else
{
}
else
{
az
.
vmSet
=
newAvailabilitySet
(
&
az
)
az
.
vmSet
=
newAvailabilitySet
(
&
az
)
}
}
...
...
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
4d5e7b7c
This diff is collapsed.
Click to expand it.
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
0 → 100644
View file @
4d5e7b7c
/*
Copyright 2018 The Kubernetes Authors.
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
azure
import
(
"fmt"
"strings"
"time"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
)
var
(
nodeNameToScaleSetMappingKey
=
"k8sNodeNameToScaleSetMappingKey"
availabilitySetNodesKey
=
"k8sAvailabilitySetNodesKey"
vmssCacheTTL
=
time
.
Minute
vmssVMCacheTTL
=
time
.
Minute
availabilitySetNodesCacheTTL
=
15
*
time
.
Minute
nodeNameToScaleSetMappingCacheTTL
=
15
*
time
.
Minute
)
// nodeNameToScaleSetMapping maps nodeName to scaleSet name.
// The map is required because vmss nodeName is not equal to its vmName.
type
nodeNameToScaleSetMapping
map
[
string
]
string
func
(
ss
*
scaleSet
)
makeVmssVMName
(
scaleSetName
,
instanceID
string
)
string
{
return
fmt
.
Sprintf
(
"%s_%s"
,
scaleSetName
,
instanceID
)
}
func
(
ss
*
scaleSet
)
extractVmssVMName
(
name
string
)
(
string
,
string
,
error
)
{
ret
:=
strings
.
Split
(
name
,
"_"
)
if
len
(
ret
)
!=
2
{
glog
.
Errorf
(
"Failed to extract vmssVMName %q"
,
name
)
return
""
,
""
,
ErrorNotVmssInstance
}
return
ret
[
0
],
ret
[
1
],
nil
}
func
(
ss
*
scaleSet
)
newVmssCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
result
,
err
:=
ss
.
VirtualMachineScaleSetsClient
.
Get
(
ss
.
ResourceGroup
,
key
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
return
nil
,
realErr
}
if
!
exists
{
return
nil
,
nil
}
return
&
result
,
nil
}
return
newTimedcache
(
vmssCacheTTL
,
getter
)
}
func
(
ss
*
scaleSet
)
newNodeNameToScaleSetMappingCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
scaleSetNames
,
err
:=
ss
.
listScaleSetsWithRetry
()
if
err
!=
nil
{
return
nil
,
err
}
localCache
:=
make
(
nodeNameToScaleSetMapping
)
for
_
,
ssName
:=
range
scaleSetNames
{
vms
,
err
:=
ss
.
listScaleSetVMsWithRetry
(
ssName
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
vm
:=
range
vms
{
if
vm
.
OsProfile
==
nil
||
vm
.
OsProfile
.
ComputerName
==
nil
{
glog
.
Warningf
(
"failed to get computerName for vmssVM (%q)"
,
*
vm
.
Name
)
continue
}
computerName
:=
strings
.
ToLower
(
*
vm
.
OsProfile
.
ComputerName
)
localCache
[
computerName
]
=
ssName
}
}
return
localCache
,
nil
}
return
newTimedcache
(
nodeNameToScaleSetMappingCacheTTL
,
getter
)
}
func
(
ss
*
scaleSet
)
newAvailabilitySetNodesCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
vmList
,
err
:=
ss
.
Cloud
.
VirtualMachineClientListWithRetry
()
if
err
!=
nil
{
return
nil
,
err
}
localCache
:=
sets
.
NewString
()
for
_
,
vm
:=
range
vmList
{
localCache
.
Insert
(
*
vm
.
Name
)
}
return
localCache
,
nil
}
return
newTimedcache
(
availabilitySetNodesCacheTTL
,
getter
)
}
func
(
ss
*
scaleSet
)
newVmssVMCache
()
(
*
timedCache
,
error
)
{
getter
:=
func
(
key
string
)
(
interface
{},
error
)
{
// vmssVM name's format is 'scaleSetName_instanceID'
ssName
,
instanceID
,
err
:=
ss
.
extractVmssVMName
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
// Not found, the VM doesn't belong to any known scale sets.
if
ssName
==
""
{
return
nil
,
nil
}
result
,
err
:=
ss
.
VirtualMachineScaleSetVMsClient
.
Get
(
ss
.
ResourceGroup
,
ssName
,
instanceID
)
exists
,
realErr
:=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
return
nil
,
realErr
}
if
!
exists
{
return
nil
,
nil
}
return
&
result
,
nil
}
return
newTimedcache
(
vmssVMCacheTTL
,
getter
)
}
func
(
ss
*
scaleSet
)
getScaleSetNameByNodeName
(
nodeName
string
)
(
string
,
error
)
{
getScaleSetName
:=
func
(
nodeName
string
)
(
string
,
error
)
{
nodeNameMapping
,
err
:=
ss
.
nodeNameToScaleSetMappingCache
.
Get
(
nodeNameToScaleSetMappingKey
)
if
err
!=
nil
{
return
""
,
err
}
realMapping
:=
nodeNameMapping
.
(
nodeNameToScaleSetMapping
)
if
ssName
,
ok
:=
realMapping
[
nodeName
];
ok
{
return
ssName
,
nil
}
return
""
,
nil
}
ssName
,
err
:=
getScaleSetName
(
nodeName
)
if
err
!=
nil
{
return
""
,
err
}
if
ssName
!=
""
{
return
ssName
,
nil
}
// ssName is still not found, it is likely that new Nodes are created.
// Force refresh the cache and try again.
ss
.
nodeNameToScaleSetMappingCache
.
Delete
(
nodeNameToScaleSetMappingKey
)
return
getScaleSetName
(
nodeName
)
}
func
(
ss
*
scaleSet
)
isNodeManagedByAvailabilitySet
(
nodeName
string
)
(
bool
,
error
)
{
cached
,
err
:=
ss
.
availabilitySetNodesCache
.
Get
(
availabilitySetNodesKey
)
if
err
!=
nil
{
return
false
,
err
}
availabilitySetNodes
:=
cached
.
(
sets
.
String
)
return
availabilitySetNodes
.
Has
(
nodeName
),
nil
}
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