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
bde2989c
Commit
bde2989c
authored
Feb 12, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for extractVmssVMName
parent
f32bd6a0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
3 deletions
+68
-3
BUILD
pkg/cloudprovider/providers/azure/BUILD
+1
-0
azure_vmss_cache.go
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
+5
-3
azure_vmss_cache_test.go
pkg/cloudprovider/providers/azure/azure_vmss_cache_test.go
+62
-0
No files found.
pkg/cloudprovider/providers/azure/BUILD
View file @
bde2989c
...
...
@@ -75,6 +75,7 @@ go_test(
"azure_storage_test.go",
"azure_storageaccount_test.go",
"azure_test.go",
"azure_vmss_cache_test.go",
"azure_vmss_test.go",
"azure_wrap_test.go",
],
...
...
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
View file @
bde2989c
...
...
@@ -27,6 +27,8 @@ import (
)
var
(
vmssNameSeparator
=
"_"
nodeNameToScaleSetMappingKey
=
"k8sNodeNameToScaleSetMappingKey"
availabilitySetNodesKey
=
"k8sAvailabilitySetNodesKey"
...
...
@@ -41,11 +43,11 @@ var (
type
nodeNameToScaleSetMapping
map
[
string
]
string
func
(
ss
*
scaleSet
)
makeVmssVMName
(
scaleSetName
,
instanceID
string
)
string
{
return
fmt
.
Sprintf
(
"%s
_%s"
,
scaleSetName
,
instanceID
)
return
fmt
.
Sprintf
(
"%s
%s%s"
,
scaleSetName
,
vmssNameSeparator
,
instanceID
)
}
func
(
ss
*
scaleSet
)
extractVmssVMName
(
name
string
)
(
string
,
string
,
error
)
{
ret
:=
strings
.
Split
(
name
,
"_"
)
ret
:=
strings
.
Split
(
name
,
vmssNameSeparator
)
if
len
(
ret
)
!=
2
{
glog
.
Errorf
(
"Failed to extract vmssVMName %q"
,
name
)
return
""
,
""
,
ErrorNotVmssInstance
...
...
@@ -88,7 +90,7 @@ func (ss *scaleSet) newNodeNameToScaleSetMappingCache() (*timedCache, error) {
for
_
,
vm
:=
range
vms
{
if
vm
.
OsProfile
==
nil
||
vm
.
OsProfile
.
ComputerName
==
nil
{
glog
.
Warningf
(
"failed to get computerName for vmssVM (%q)"
,
*
vm
.
Name
)
glog
.
Warningf
(
"failed to get computerName for vmssVM (%q)"
,
vm
.
Name
)
continue
}
...
...
pkg/cloudprovider/providers/azure/azure_vmss_cache_test.go
0 → 100644
View file @
bde2989c
/*
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
(
"testing"
"github.com/stretchr/testify/assert"
)
func
TestExtractVmssVMName
(
t
*
testing
.
T
)
{
ss
:=
&
scaleSet
{}
cases
:=
[]
struct
{
description
string
vmName
string
expectError
bool
expectedScaleSet
string
expectedInstanceID
string
}{
{
description
:
"wrong vmss VM name should report error"
,
vmName
:
"vm1234"
,
expectError
:
true
,
},
{
description
:
"wrong VM name separator should report error"
,
vmName
:
"vm-1234"
,
expectError
:
true
,
},
{
description
:
"correct vmss VM name should return correct scaleSet and instanceID"
,
vmName
:
"vm_1234"
,
expectedScaleSet
:
"vm"
,
expectedInstanceID
:
"1234"
,
},
}
for
_
,
c
:=
range
cases
{
ssName
,
instanceID
,
err
:=
ss
.
extractVmssVMName
(
c
.
vmName
)
if
c
.
expectError
{
assert
.
Error
(
t
,
err
,
c
.
description
)
continue
}
assert
.
Equal
(
t
,
c
.
expectedScaleSet
,
ssName
,
c
.
description
)
assert
.
Equal
(
t
,
c
.
expectedInstanceID
,
instanceID
,
c
.
description
)
}
}
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