Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secret retry #84

Merged
merged 3 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ func (lbc *LoadBalancerController) syncEndp(key string) {
if !isNginxIngress(&ing) {
continue
}
ingEx := lbc.createIngress(&ing)
ingEx, err := lbc.createIngress(&ing)
if err != nil {
lbc.ingQueue.requeueAfter(key, err, 5*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to requeue the Ingress when endpoints change. Better to ignore such an Ingress with an error.

return
}
glog.V(3).Infof("Updating Endpoints for %v/%v", ing.Name, ing.Namespace)
name := ing.Namespace + "-" + ing.Name
lbc.cnf.UpdateEndpoints(name, &ingEx)
Expand Down Expand Up @@ -414,7 +418,11 @@ 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)
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 @@ -454,7 +462,7 @@ func (lbc *LoadBalancerController) getIngressForEndpoints(obj interface{}) []ext
return ings
}

func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) nginx.IngressEx {
func (lbc *LoadBalancerController) createIngress(ing *extensions.Ingress) (nginx.IngressEx, error) {
ingEx := nginx.IngressEx{
Ingress: ing,
}
Expand All @@ -464,8 +472,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 ingEx, fmt.Errorf("Error retrieving secret %v for Ingress %v: %v", secretName, ing.Name, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to return nil instead of ingEx

}
ingEx.Secrets[secretName] = secret
}
Expand Down Expand Up @@ -495,7 +502,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