diff --git a/pkg/cloudprovider/providers/azure/azure_vmss.go b/pkg/cloudprovider/providers/azure/azure_vmss.go index 539483d35b2..2c5ac451eda 100644 --- a/pkg/cloudprovider/providers/azure/azure_vmss.go +++ b/pkg/cloudprovider/providers/azure/azure_vmss.go @@ -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.