mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Fix ensureStaticIP if name for existed address was changed
It might happend when we change external IP address from ephemeral to static and give it a custom name. In this case GetRegionAddress with given name will return Not Found
This commit is contained in:
parent
0387ee4244
commit
0995ef573f
@ -1060,6 +1060,18 @@ func ensureStaticIP(s CloudAddressService, name, serviceName, region, existingIP
|
||||
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)
|
||||
if err != nil {
|
||||
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 {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user