Skip to content

Commit

Permalink
fix: race condition for ingress resource status
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt committed Oct 19, 2021
1 parent 119e926 commit 96d7e90
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
- Debug logging for resource status updates have been fixed to ensure that
debug output isn't silently lost and to fix some formatting issues.
[#1930](https://github.com/Kong/kubernetes-ingress-controller/pull/1930)
- Fixed a bug where Ingress resources would not be able to receive status
updates containing relevant addresses in environments where LoadBalancer
type services provision slowly.
[#1931](https://github.com/Kong/kubernetes-ingress-controller/pull/1931)

## [2.0.2] - 2021/10/14

Expand Down
29 changes: 25 additions & 4 deletions internal/ctrlutils/ingress-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,25 @@ func PullConfigUpdate(
publishService string,
publishAddresses []string,
) {
ips, hostname, err := RunningAddresses(ctx, kubeConfig, publishService, publishAddresses)
if err != nil {
log.Error(err, "failed to determine kong proxy external ips/hostnames.")
return
var hostname string
var ips []string
for {
var err error
ips, hostname, err = RunningAddresses(ctx, kubeConfig, publishService, publishAddresses)
if err != nil {
// in the case that a LoadBalancer type service is being used for the Kong Proxy
// we must wait until the IP address if fully provisioned before we will be able
// to use the reference IPs/Hosts from that LoadBalancer to update resource status addresses.
if err.Error() == proxyLBNotReadyMessage {
log.V(util.InfoLevel).Info("LoadBalancer type Service for the Kong proxy is not yet provisioned, waiting...", "service", publishService)
time.Sleep(time.Second)
continue
}

log.Error(err, "failed to determine kong proxy external ips/hostnames.")
return
}
break
}

cli, err := clientset.NewForConfig(kubeConfig)
Expand Down Expand Up @@ -489,6 +504,8 @@ func UpdateKnativeIngress(ctx context.Context, log logr.Logger, svc file.FServic
return nil
}

const proxyLBNotReadyMessage = "LoadBalancer service for proxy is not yet ready"

// RunningAddresses retrieve cluster loader balance IP or hostaddress using networking
func RunningAddresses(ctx context.Context, kubeCfg *rest.Config, publishService string,
publishAddresses []string) ([]string, string, error) {
Expand All @@ -514,6 +531,10 @@ func RunningAddresses(ctx context.Context, kubeCfg *rest.Config, publishService
//nolint:exhaustive
switch svc.Spec.Type {
case apiv1.ServiceTypeLoadBalancer:
if len(svc.Status.LoadBalancer.Ingress) < 1 {
return addrs, hostname, fmt.Errorf(proxyLBNotReadyMessage)
}

for _, ip := range svc.Status.LoadBalancer.Ingress {
if ip.IP == "" {
addrs = append(addrs, ip.Hostname)
Expand Down

0 comments on commit 96d7e90

Please sign in to comment.