mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Get public IP for Azure vmss nodes
This is required for getting public IP when --public-ip-per-vm (publicIpAddressConfiguration) is enabled for vmss.
This commit is contained in:
parent
6b1af84d4a
commit
303af63ec9
@ -291,8 +291,6 @@ func (ss *scaleSet) GetPrimaryVMSetName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetIPByNodeName gets machine private IP and public IP by node name.
|
// 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) {
|
func (ss *scaleSet) GetIPByNodeName(nodeName string) (string, string, error) {
|
||||||
nic, err := ss.GetPrimaryInterface(nodeName)
|
nic, err := ss.GetPrimaryInterface(nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -306,8 +304,30 @@ func (ss *scaleSet) GetIPByNodeName(nodeName string) (string, string, error) {
|
|||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
targetIP := *ipConfig.PrivateIPAddress
|
internalIP := *ipConfig.PrivateIPAddress
|
||||||
return targetIP, "", nil
|
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.
|
// This returns the full identifier of the primary NIC for the given VM.
|
||||||
|
Loading…
Reference in New Issue
Block a user