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
69da1f83
Unverified
Commit
69da1f83
authored
Sep 24, 2018
by
k8s-ci-robot
Committed by
GitHub
Sep 24, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68498 from feiskyer/vmss-pip
Get public IP for Azure vmss nodes
parents
6b1af84d
f8b2781f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
146 additions
and
11 deletions
+146
-11
azure_fakes.go
pkg/cloudprovider/providers/azure/azure_fakes.go
+25
-1
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+24
-4
azure_vmss_test.go
pkg/cloudprovider/providers/azure/azure_vmss_test.go
+97
-6
No files found.
pkg/cloudprovider/providers/azure/azure_fakes.go
View file @
69da1f83
...
...
@@ -207,6 +207,13 @@ func (fAPC *fakeAzurePIPClient) List(ctx context.Context, resourceGroupName stri
return
value
,
nil
}
func
(
fAPC
*
fakeAzurePIPClient
)
setFakeStore
(
store
map
[
string
]
map
[
string
]
network
.
PublicIPAddress
)
{
fAPC
.
mutex
.
Lock
()
defer
fAPC
.
mutex
.
Unlock
()
fAPC
.
FakeStore
=
store
}
type
fakeAzureInterfacesClient
struct
{
mutex
*
sync
.
Mutex
FakeStore
map
[
string
]
map
[
string
]
network
.
Interface
...
...
@@ -247,7 +254,24 @@ func (fIC *fakeAzureInterfacesClient) Get(ctx context.Context, resourceGroupName
}
func
(
fIC
*
fakeAzureInterfacesClient
)
GetVirtualMachineScaleSetNetworkInterface
(
ctx
context
.
Context
,
resourceGroupName
string
,
virtualMachineScaleSetName
string
,
virtualmachineIndex
string
,
networkInterfaceName
string
,
expand
string
)
(
result
network
.
Interface
,
err
error
)
{
return
result
,
nil
fIC
.
mutex
.
Lock
()
defer
fIC
.
mutex
.
Unlock
()
if
_
,
ok
:=
fIC
.
FakeStore
[
resourceGroupName
];
ok
{
if
entity
,
ok
:=
fIC
.
FakeStore
[
resourceGroupName
][
networkInterfaceName
];
ok
{
return
entity
,
nil
}
}
return
result
,
autorest
.
DetailedError
{
StatusCode
:
http
.
StatusNotFound
,
Message
:
"Not such Interface"
,
}
}
func
(
fIC
*
fakeAzureInterfacesClient
)
setFakeStore
(
store
map
[
string
]
map
[
string
]
network
.
Interface
)
{
fIC
.
mutex
.
Lock
()
defer
fIC
.
mutex
.
Unlock
()
fIC
.
FakeStore
=
store
}
type
fakeAzureVirtualMachinesClient
struct
{
...
...
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
69da1f83
...
...
@@ -291,8 +291,6 @@ func (ss *scaleSet) GetPrimaryVMSetName() string {
}
// GetIPByNodeName gets machine private IP and public IP by node name.
// TODO(feiskyer): Azure vmss doesn't support associating a public IP to single virtual machine yet,
// fix this after it is supported.
func
(
ss
*
scaleSet
)
GetIPByNodeName
(
nodeName
string
)
(
string
,
string
,
error
)
{
nic
,
err
:=
ss
.
GetPrimaryInterface
(
nodeName
)
if
err
!=
nil
{
...
...
@@ -306,8 +304,30 @@ func (ss *scaleSet) GetIPByNodeName(nodeName string) (string, string, error) {
return
""
,
""
,
err
}
targetIP
:=
*
ipConfig
.
PrivateIPAddress
return
targetIP
,
""
,
nil
internalIP
:=
*
ipConfig
.
PrivateIPAddress
publicIP
:=
""
if
ipConfig
.
PublicIPAddress
!=
nil
&&
ipConfig
.
PublicIPAddress
.
ID
!=
nil
{
pipID
:=
*
ipConfig
.
PublicIPAddress
.
ID
pipName
,
err
:=
getLastSegment
(
pipID
)
if
err
!=
nil
{
return
""
,
""
,
fmt
.
Errorf
(
"failed to get publicIP name for node %q with pipID %q"
,
nodeName
,
pipID
)
}
resourceGroup
,
err
:=
ss
.
GetNodeResourceGroup
(
nodeName
)
if
err
!=
nil
{
return
""
,
""
,
err
}
pip
,
existsPip
,
err
:=
ss
.
getPublicIPAddress
(
resourceGroup
,
pipName
)
if
err
!=
nil
{
return
""
,
""
,
err
}
if
existsPip
{
publicIP
=
*
pip
.
IPAddress
}
}
return
internalIP
,
publicIP
,
nil
}
// This returns the full identifier of the primary NIC for the given VM.
...
...
pkg/cloudprovider/providers/azure/azure_vmss_test.go
View file @
69da1f83
...
...
@@ -21,9 +21,16 @@ import (
"testing"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2017-09-01/network"
"github.com/Azure/go-autorest/autorest/to"
"github.com/stretchr/testify/assert"
)
const
(
fakePrivateIP
=
"10.240.0.10"
fakePublicIP
=
"10.10.10.10"
)
func
newTestScaleSet
(
scaleSetName
,
zone
string
,
faultDomain
int32
,
vmList
[]
string
)
(
*
scaleSet
,
error
)
{
cloud
:=
getTestCloud
()
setTestVirtualMachineCloud
(
cloud
,
scaleSetName
,
zone
,
faultDomain
,
vmList
)
...
...
@@ -37,6 +44,11 @@ func newTestScaleSet(scaleSetName, zone string, faultDomain int32, vmList []stri
func
setTestVirtualMachineCloud
(
ss
*
Cloud
,
scaleSetName
,
zone
string
,
faultDomain
int32
,
vmList
[]
string
)
{
virtualMachineScaleSetsClient
:=
newFakeVirtualMachineScaleSetsClient
()
virtualMachineScaleSetVMsClient
:=
newFakeVirtualMachineScaleSetVMsClient
()
publicIPAddressesClient
:=
newFakeAzurePIPClient
(
"rg"
)
interfaceClient
:=
newFakeAzureInterfacesClient
()
// set test scale sets.
scaleSets
:=
make
(
map
[
string
]
map
[
string
]
compute
.
VirtualMachineScaleSet
)
scaleSets
[
"rg"
]
=
map
[
string
]
compute
.
VirtualMachineScaleSet
{
scaleSetName
:
{
...
...
@@ -45,17 +57,27 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
}
virtualMachineScaleSetsClient
.
setFakeStore
(
scaleSets
)
virtualMachineScaleSetVMsClient
:=
newFakeVirtualMachineScaleSetVMsClient
()
ssVMs
:=
make
(
map
[
string
]
map
[
string
]
compute
.
VirtualMachineScaleSetVM
)
ssVMs
[
"rg"
]
=
make
(
map
[
string
]
compute
.
VirtualMachineScaleSetVM
)
testInterfaces
:=
map
[
string
]
map
[
string
]
network
.
Interface
{
"rg"
:
make
(
map
[
string
]
network
.
Interface
),
}
testPIPs
:=
map
[
string
]
map
[
string
]
network
.
PublicIPAddress
{
"rg"
:
make
(
map
[
string
]
network
.
PublicIPAddress
),
}
ssVMs
:=
map
[
string
]
map
[
string
]
compute
.
VirtualMachineScaleSetVM
{
"rg"
:
make
(
map
[
string
]
compute
.
VirtualMachineScaleSetVM
),
}
for
i
:=
range
vmList
{
ID
:=
fmt
.
Sprintf
(
"/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d"
,
scaleSetName
,
i
)
nodeName
:=
vmList
[
i
]
ID
:=
fmt
.
Sprintf
(
"/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d"
,
scaleSetName
,
i
)
interfaceID
:=
fmt
.
Sprintf
(
"/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d/networkInterfaces/%s"
,
scaleSetName
,
i
,
nodeName
)
publicAddressID
:=
fmt
.
Sprintf
(
"/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%d/networkInterfaces/%s/ipConfigurations/ipconfig1/publicIPAddresses/%s"
,
scaleSetName
,
i
,
nodeName
,
nodeName
)
instanceID
:=
fmt
.
Sprintf
(
"%d"
,
i
)
vmName
:=
fmt
.
Sprintf
(
"%s_%s"
,
scaleSetName
,
instanceID
)
// set vmss virtual machine.
networkInterfaces
:=
[]
compute
.
NetworkInterfaceReference
{
{
ID
:
&
nodeName
,
ID
:
&
interfaceID
,
},
}
vmssVM
:=
compute
.
VirtualMachineScaleSetVM
{
...
...
@@ -75,17 +97,46 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
Name
:
&
vmName
,
Location
:
&
ss
.
Location
,
}
if
zone
!=
""
{
zones
:=
[]
string
{
zone
}
vmssVM
.
Zones
=
&
zones
}
ssVMs
[
"rg"
][
vmName
]
=
vmssVM
// set interfaces.
testInterfaces
[
"rg"
][
nodeName
]
=
network
.
Interface
{
ID
:
&
interfaceID
,
InterfacePropertiesFormat
:
&
network
.
InterfacePropertiesFormat
{
IPConfigurations
:
&
[]
network
.
InterfaceIPConfiguration
{
{
InterfaceIPConfigurationPropertiesFormat
:
&
network
.
InterfaceIPConfigurationPropertiesFormat
{
Primary
:
to
.
BoolPtr
(
true
),
PrivateIPAddress
:
to
.
StringPtr
(
fakePrivateIP
),
PublicIPAddress
:
&
network
.
PublicIPAddress
{
ID
:
to
.
StringPtr
(
publicAddressID
),
},
},
},
},
},
}
// set public IPs.
testPIPs
[
"rg"
][
nodeName
]
=
network
.
PublicIPAddress
{
ID
:
to
.
StringPtr
(
publicAddressID
),
PublicIPAddressPropertiesFormat
:
&
network
.
PublicIPAddressPropertiesFormat
{
IPAddress
:
to
.
StringPtr
(
fakePublicIP
),
},
}
}
virtualMachineScaleSetVMsClient
.
setFakeStore
(
ssVMs
)
interfaceClient
.
setFakeStore
(
testInterfaces
)
publicIPAddressesClient
.
setFakeStore
(
testPIPs
)
ss
.
VirtualMachineScaleSetsClient
=
virtualMachineScaleSetsClient
ss
.
VirtualMachineScaleSetVMsClient
=
virtualMachineScaleSetVMsClient
ss
.
InterfacesClient
=
interfaceClient
ss
.
PublicIPAddressesClient
=
publicIPAddressesClient
}
func
TestGetScaleSetVMInstanceID
(
t
*
testing
.
T
)
{
...
...
@@ -216,3 +267,43 @@ func TestGetZoneByNodeName(t *testing.T) {
assert
.
Equal
(
t
,
test
.
expected
,
real
.
FailureDomain
,
test
.
description
)
}
}
func
TestGetIPByNodeName
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
description
string
scaleSet
string
vmList
[]
string
nodeName
string
expected
[]
string
expectError
bool
}{
{
description
:
"GetIPByNodeName should get node's privateIP and publicIP"
,
scaleSet
:
"ss"
,
vmList
:
[]
string
{
"vmssee6c2000000"
,
"vmssee6c2000001"
},
nodeName
:
"vmssee6c2000000"
,
expected
:
[]
string
{
fakePrivateIP
,
fakePublicIP
},
},
{
description
:
"GetIPByNodeName should return error for non-exist nodes"
,
scaleSet
:
"ss"
,
vmList
:
[]
string
{
"vmssee6c2000000"
,
"vmssee6c2000001"
},
nodeName
:
"agente6c2000005"
,
expectError
:
true
,
},
}
for
_
,
test
:=
range
testCases
{
ss
,
err
:=
newTestScaleSet
(
test
.
scaleSet
,
""
,
0
,
test
.
vmList
)
assert
.
NoError
(
t
,
err
,
test
.
description
)
privateIP
,
publicIP
,
err
:=
ss
.
GetIPByNodeName
(
test
.
nodeName
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
,
test
.
description
)
continue
}
assert
.
NoError
(
t
,
err
,
test
.
description
)
assert
.
Equal
(
t
,
test
.
expected
,
[]
string
{
privateIP
,
publicIP
},
test
.
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