Skip to content

Commit 997b67e

Browse files
AkarshESl-technicore
authored andcommitted
Wait for LB to reach ACTIVE state before updating it
1 parent a1065f9 commit 997b67e

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
9898
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
9999
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
100100
github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU=
101+
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
101102
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
102103
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
103104
github.com/blang/semver v3.1.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
@@ -635,6 +636,7 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.m
635636
github.com/opencontainers/selinux v1.5.1/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g=
636637
github.com/opencontainers/selinux v1.5.2/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g=
637638
github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3ogry1nUQF8Evvo=
639+
github.com/opencontainers/selinux v1.8.2 h1:c4ca10UMgRcvZ6h0K4HtS15UaVSBEaE+iln2LVpAuGc=
638640
github.com/opencontainers/selinux v1.8.2/go.mod h1:MUIHuUEvKB1wtJjQdOyYRgOnLD2xAPP8dBsCoU0KuF8=
639641
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
640642
github.com/oracle/oci-go-sdk/v31 v31.0.0 h1:LEstCAlSNcuuPIRUMLuX3UF+V3ID2B1LN4k9Dvbd5tM=
@@ -1322,6 +1324,7 @@ k8s.io/legacy-cloud-providers v0.19.12/go.mod h1:8ZhENHyKoTmK3ZfgXYWRc36HlFdIKKq
13221324
k8s.io/legacy-cloud-providers v0.22.5/go.mod h1:a+nO87Q1eJjGpBcfmv1llCMufHF6sRpKSoXFMp1tj+s=
13231325
k8s.io/metrics v0.19.12/go.mod h1:l7v54/zYNUiDNjgCbEG3kF0r85DdLxbQNtYLuhgyO8s=
13241326
k8s.io/metrics v0.22.5/go.mod h1:dCqOkoZQWLSfBhUtPFMiDrzJaPtXJlVePVuJbEx0hW8=
1327+
k8s.io/mount-utils v0.22.5 h1:Tj1mcA/azQaWlIXGL9g5+505ig/+r4AYfPMtwaaNSis=
13251328
k8s.io/mount-utils v0.22.5/go.mod h1:dHl6c2P60T5LHUnZxVslyly9EDCMzvhtISO5aY+Z4sk=
13261329
k8s.io/pod-security-admission v0.22.5/go.mod h1:2a1JSU7b+CHFoSGIr8FwZBBeAJFau41srx08/qEy+NI=
13271330
k8s.io/sample-apiserver v0.19.12/go.mod h1:+bwpXMUrAFSGjLjpxfqNkrNn4mQrJH0czEavWrVcEJc=

pkg/cloudprovider/providers/oci/load_balancer.go

+9
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

+2-1
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

+14
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

@@ -101,3 +103,15 @@ func NewRateLimiter(logger *zap.SugaredLogger, config *providercfg.RateLimiterCo
101103

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

vendor/modules.txt

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ github.com/PuerkitoBio/purell
99
github.com/PuerkitoBio/urlesc
1010
# github.com/beorn7/perks v1.0.1
1111
github.com/beorn7/perks/quantile
12+
# github.com/bits-and-blooms/bitset v1.2.0
13+
github.com/bits-and-blooms/bitset
1214
# github.com/blang/semver v3.5.1+incompatible
1315
github.com/blang/semver
1416
# github.com/cespare/xxhash/v2 v2.1.1
@@ -180,6 +182,9 @@ github.com/opencontainers/go-digest
180182
# github.com/opencontainers/runc v1.0.2
181183
github.com/opencontainers/runc/libcontainer/apparmor
182184
github.com/opencontainers/runc/libcontainer/utils
185+
# github.com/opencontainers/selinux v1.8.2
186+
github.com/opencontainers/selinux/go-selinux
187+
github.com/opencontainers/selinux/pkg/pwalk
183188
# github.com/oracle/oci-go-sdk/v50 v50.1.0
184189
## explicit
185190
github.com/oracle/oci-go-sdk/v50/common
@@ -1091,6 +1096,7 @@ k8s.io/kubernetes/pkg/features
10911096
k8s.io/kubernetes/pkg/fieldpath
10921097
k8s.io/kubernetes/pkg/kubelet/types
10931098
k8s.io/kubernetes/pkg/kubelet/util/format
1099+
k8s.io/kubernetes/pkg/proxy/util
10941100
k8s.io/kubernetes/pkg/scheduler/apis/config
10951101
k8s.io/kubernetes/pkg/scheduler/framework
10961102
k8s.io/kubernetes/pkg/scheduler/internal/parallelize
@@ -1100,18 +1106,33 @@ k8s.io/kubernetes/pkg/util/hash
11001106
k8s.io/kubernetes/pkg/util/labels
11011107
k8s.io/kubernetes/pkg/util/node
11021108
k8s.io/kubernetes/pkg/util/parsers
1109+
k8s.io/kubernetes/pkg/util/selinux
1110+
k8s.io/kubernetes/pkg/util/sysctl
11031111
k8s.io/kubernetes/pkg/util/taints
1112+
k8s.io/kubernetes/pkg/volume
1113+
k8s.io/kubernetes/pkg/volume/util/fs
1114+
k8s.io/kubernetes/pkg/volume/util/fsquota
1115+
k8s.io/kubernetes/pkg/volume/util/fsquota/common
1116+
k8s.io/kubernetes/pkg/volume/util/hostutil
1117+
k8s.io/kubernetes/pkg/volume/util/recyclerclient
1118+
k8s.io/kubernetes/pkg/volume/util/subpath
1119+
k8s.io/kubernetes/pkg/volume/util/types
11041120
k8s.io/kubernetes/test/utils
11051121
k8s.io/kubernetes/test/utils/image
1122+
# k8s.io/mount-utils v0.22.5 => k8s.io/mount-utils v0.22.5
1123+
k8s.io/mount-utils
11061124
# k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a
11071125
## explicit
11081126
k8s.io/utils/buffer
11091127
k8s.io/utils/exec
11101128
k8s.io/utils/integer
11111129
k8s.io/utils/internal/third_party/forked/golang/golang-lru
11121130
k8s.io/utils/internal/third_party/forked/golang/net
1131+
k8s.io/utils/io
1132+
k8s.io/utils/keymutex
11131133
k8s.io/utils/lru
11141134
k8s.io/utils/net
1135+
k8s.io/utils/nsenter
11151136
k8s.io/utils/path
11161137
k8s.io/utils/pointer
11171138
k8s.io/utils/trace

0 commit comments

Comments
 (0)