mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Merge pull request #86452 from lelenanam/lbbug
Fix ensureStaticIP if name for existed address was changed
This commit is contained in:
commit
bd239d42e4
@ -1060,6 +1060,18 @@ func ensureStaticIP(s CloudAddressService, name, serviceName, region, existingIP
|
|||||||
existed = true
|
existed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If address exists, get it by IP, because name might be different.
|
||||||
|
// This can specifically happen if the IP was changed from ephemeral to static,
|
||||||
|
// which results in a new name for the IP.
|
||||||
|
if existingIP != "" {
|
||||||
|
addr, err := s.GetRegionAddressByIP(region, existingIP)
|
||||||
|
if err != nil {
|
||||||
|
return "", false, fmt.Errorf("error getting static IP address: %v", err)
|
||||||
|
}
|
||||||
|
return addr.Address, existed, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, get address by name
|
||||||
addr, err := s.GetRegionAddress(name, region)
|
addr, err := s.GetRegionAddress(name, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, fmt.Errorf("error getting static IP address: %v", err)
|
return "", false, fmt.Errorf("error getting static IP address: %v", err)
|
||||||
|
@ -63,6 +63,13 @@ func TestEnsureStaticIP(t *testing.T) {
|
|||||||
if err != nil || !existed || ip != ipPrime {
|
if err != nil || !existed || ip != ipPrime {
|
||||||
t.Fatalf(`ensureStaticIP(%v, %v, %v, %v, %v) = %v, %v, %v; want %v, true, nil`, gce, ipName, serviceName, gce.region, ip, ipPrime, existed, err, ip)
|
t.Fatalf(`ensureStaticIP(%v, %v, %v, %v, %v) = %v, %v, %v; want %v, true, nil`, gce, ipName, serviceName, gce.region, ip, ipPrime, existed, err, ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure call with different name
|
||||||
|
ipName = "another-name-for-static-ip"
|
||||||
|
ipPrime, existed, err = ensureStaticIP(gce, ipName, serviceName, gce.region, ip, cloud.NetworkTierDefault)
|
||||||
|
if err != nil || !existed || ip != ipPrime {
|
||||||
|
t.Fatalf(`ensureStaticIP(%v, %v, %v, %v, %v) = %v, %v, %v; want %v, true, nil`, gce, ipName, serviceName, gce.region, ip, ipPrime, existed, err, ip)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnsureStaticIPWithTier(t *testing.T) {
|
func TestEnsureStaticIPWithTier(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user