Skip to content

Commit

Permalink
Get public IP for Azure vmss nodes
Browse files Browse the repository at this point in the history
This is required for getting public IP when --public-ip-per-vm
(publicIpAddressConfiguration) is enabled for vmss.
  • Loading branch information
feiskyer committed Sep 25, 2018
1 parent 6b1af84 commit 303af63
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/cloudprovider/providers/azure/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit 303af63

Please sign in to comment.