Skip to content

Commit 94dc7a6

Browse files
committed
Merge pull request oracle#315 in OKE/oci-cloud-controller-manager from task/OKE-21403-1.23 to release-1.23
* commit 'c63638e66acd90bb33c448b9c62703a241406853': Wait for LB to reach ACTIVE state before updating it
2 parents 023da46 + c63638e commit 94dc7a6

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pkg/cloudprovider/providers/oci/load_balancer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const (
6767
lbConnectionIdleTimeoutTCP = 300
6868
lbConnectionIdleTimeoutHTTP = 60
6969
flexible = "flexible"
70+
lbLifecycleStateActive = "ACTIVE"
7071
lbMaximumNetworkSecurityGroupIds = 5
7172
excludeBackendFromLBLabel = "node.kubernetes.io/exclude-from-external-load-balancers"
7273
)
@@ -492,6 +493,11 @@ func (cp *CloudProvider) EnsureLoadBalancer(ctx context.Context, clusterName str
492493
return lbStatus, err
493494
}
494495

496+
if lb.LifecycleState == nil || *lb.LifecycleState != lbLifecycleStateActive {
497+
logger.With("lifecycleState", lb.LifecycleState).Infof("LB is not in %s state, will retry EnsureLoadBalancer", lbLifecycleStateActive)
498+
return nil, errors.Errorf("rejecting request to update LB which is not in %s state", lbLifecycleStateActive)
499+
}
500+
495501
// Existing load balancers cannot change subnets. This ensures that the spec matches
496502
// what the actual load balancer has listed as the subnet ids. If the load balancer
497503
// was just created then these values would be equal; however, if the load balancer
@@ -1075,6 +1081,9 @@ func loadBalancerToStatus(lb *client.GenericLoadBalancer) (*v1.LoadBalancerStatu
10751081
}
10761082
ingress = append(ingress, v1.LoadBalancerIngress{IP: *ip.IpAddress})
10771083
}
1084+
if len(ingress) == 0 {
1085+
return nil, errors.Errorf("ip addresses are not assigned for load balancer %q", *lb.DisplayName)
1086+
}
10781087
return &v1.LoadBalancerStatus{Ingress: ingress}, nil
10791088
}
10801089

pkg/oci/client/load_balancer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,14 @@ func (c *loadbalancerClientStruct) AwaitWorkRequest(ctx context.Context, id stri
388388
var wr *loadbalancer.WorkRequest
389389
contextWithTimeout, cancel := context.WithTimeout(ctx, defaultSynchronousAPIContextTimeout)
390390
defer cancel()
391+
requestId, _ := generateRandUUID()
391392
err := wait.PollUntil(workRequestPollInterval, func() (done bool, err error) {
392393
twr, err := c.GetWorkRequest(contextWithTimeout, id)
393394
if err != nil {
394395
if IsRetryable(err) {
395396
return false, nil
396397
}
397-
return true, errors.WithStack(err)
398+
return true, errors.Wrapf(errors.WithStack(err), "failed to get workrequest. opc-request-id: %s", requestId)
398399
}
399400
switch twr.LifecycleState {
400401
case loadbalancer.WorkRequestLifecycleStateSucceeded:

pkg/oci/client/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package client
1616

1717
import (
18+
"crypto/rand"
19+
"fmt"
1820
"net/http"
1921
"strings"
2022

@@ -102,3 +104,15 @@ func NewRateLimiter(logger *zap.SugaredLogger, config *providercfg.RateLimiterCo
102104

103105
return rateLimiter
104106
}
107+
108+
// source: oci-go-sdk common/http.go
109+
func generateRandUUID() (string, error) {
110+
b := make([]byte, 16)
111+
_, err := rand.Read(b)
112+
if err != nil {
113+
return "", err
114+
}
115+
uuid := fmt.Sprintf("%x%x%x%x%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
116+
117+
return uuid, nil
118+
}

0 commit comments

Comments
 (0)