Skip to content

Commit

Permalink
Merge pull request #84 from thetechnick/secret-retry
Browse files Browse the repository at this point in the history
Secret retry
  • Loading branch information
pleshakov authored Dec 2, 2016
2 parents 0199908 + 46eff6c commit 3b59ab2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
25 changes: 16 additions & 9 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ func (lbc *LoadBalancerController) syncEndp(key string) {
if !isNginxIngress(&ing) {
continue
}
ingEx := lbc.createIngress(&ing)
ingEx, err := lbc.createIngress(&ing)
if err != nil {
glog.Warningf("Error updating endpoints for %v/%v: %v, skipping", ing.Namespace, ing.Name, err)
continue
}
glog.V(3).Infof("Updating Endpoints for %v/%v", ing.Name, ing.Namespace)
name := ing.Namespace + "-" + ing.Name
lbc.cnf.UpdateEndpoints(name, &ingEx)
lbc.cnf.UpdateEndpoints(name, ingEx)
}
}

Expand Down Expand Up @@ -479,8 +483,12 @@ func (lbc *LoadBalancerController) syncIng(key string) {
glog.V(2).Infof("Adding or Updating Ingress: %v\n", key)

ing := obj.(*extensions.Ingress)
ingEx := lbc.createIngress(ing)
lbc.cnf.AddOrUpdateIngress(name, &ingEx)
ingEx, err := lbc.createIngress(ing)
if err != nil {
lbc.ingQueue.requeueAfter(key, err, 5*time.Second)
return
}
lbc.cnf.AddOrUpdateIngress(name, ingEx)
}
}

Expand Down Expand Up @@ -519,8 +527,8 @@ func (lbc *LoadBalancerController) getIngressForEndpoints(obj interface{}) []ext
return ings
}

func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) nginx.IngressEx {
ingEx := nginx.IngressEx{
func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) (*nginx.IngressEx, error) {
ingEx := &nginx.IngressEx{
Ingress: ing,
}

Expand All @@ -529,8 +537,7 @@ func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) nginx.
secretName := tls.SecretName
secret, err := lbc.client.Secrets(ing.Namespace).Get(secretName)
if err != nil {
glog.Warningf("Error retrieving secret %v for Ingress %v: %v", secretName, ing.Name, err)
continue
return nil, fmt.Errorf("Error retrieving secret %v for Ingress %v: %v", secretName, ing.Name, err)
}
ingEx.Secrets[secretName] = secret
}
Expand Down Expand Up @@ -560,7 +567,7 @@ func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) nginx.
}
}

return ingEx
return ingEx, nil
}

func (lbc *LoadBalancerController) getEndpointsForIngressBackend(backend *extensions.IngressBackend, namespace string) ([]string, error) {
Expand Down
8 changes: 8 additions & 0 deletions nginx-controller/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func (t *taskQueue) requeue(key string, err error) {
t.queue.Add(key)
}

func (t *taskQueue) requeueAfter(key string, err error, after time.Duration) {
glog.Errorf("Requeuing %v after %s, err %v", key, after.String(), err)
go func(key string, after time.Duration) {
time.Sleep(after)
t.queue.Add(key)
}(key, after)
}

// worker processes work in the queue through sync.
func (t *taskQueue) worker() {
for {
Expand Down

0 comments on commit 3b59ab2

Please sign in to comment.