Skip to content

Commit

Permalink
Merge pull request #41 from takutakahashi/add_aws_backend
Browse files Browse the repository at this point in the history
add async to verify
  • Loading branch information
takutakahashi authored May 22, 2020
2 parents 86dc29e + d03bdf6 commit dad462a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 8 additions & 10 deletions api/v1beta1/awsbackend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -141,13 +140,13 @@ func (a AWSBackend) ReachableAll() (bool, error) {
}
reachedList := []BackendListener{}
for _, listener := range a.Status.Listeners {
for i := 0; i < 300; i++ {
reached, _ := a.reachable(listener)
if reached {
reachedList = append(reachedList, listener)
break
}
time.Sleep(1 * time.Second)
reached, err := a.reachable(listener)
if err != nil {
return false, err
}
if reached {
reachedList = append(reachedList, listener)
break
}
}
if len(reachedList) != len(a.Status.Listeners) {
Expand All @@ -161,9 +160,8 @@ func (a AWSBackend) reachable(listener BackendListener) (bool, error) {
if e == "" {
e = a.Status.Endpoint.IP
}
conn, err := net.Dial(strings.ToLower(listener.Protocol.String()), fmt.Sprintf("%s:%d", e, listener.Port))
conn, err := net.DialTimeout(strings.ToLower(listener.Protocol.String()), fmt.Sprintf("%s:%d", e, listener.Port), 2*time.Second)
if err != nil {
logrus.Debug(err)
return false, err
}
defer conn.Close()
Expand Down
18 changes: 14 additions & 4 deletions controllers/awsbackend_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"context"
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -95,8 +96,15 @@ func (r *AWSBackendReconciler) ReconcileVerify(ctx context.Context, backend load
backend.Status = status
if backend.Status.Internal != true {
reached, err := backend.ReachableAll()
if err != nil || !reached {
return ctrl.Result{Requeue: true}, err
if err != nil {
r.Log.Info(err.Error())
r.Log.Info("task was requeued")
return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, nil
}
if !reached {
r.Log.Info("this endpoint is not reachable")
r.Log.Info("task was requeued")
return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, nil
}
}
backend.Status.Phase = loadbalancerv1beta1.BackendPhaseReady
Expand All @@ -111,7 +119,8 @@ func (r *AWSBackendReconciler) ReconcileApply(ctx context.Context, backend loadb
}
err = tc.Apply()
if err != nil {
return ctrl.Result{Requeue: true}, err
r.Log.Info(err.Error())
return ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second}, nil
}
backend.Status.Phase = loadbalancerv1beta1.BackendPhaseProvisioned
return ctrl.Result{}, r.Update(ctx, &backend)
Expand All @@ -125,7 +134,8 @@ func (r *AWSBackendReconciler) ReconcileDelete(ctx context.Context, backend load
}
err = tc.Destroy()
if err != nil {
return ctrl.Result{}, err
r.Log.Info(err.Error())
return ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second}, nil
}
backend.Finalizers = []string{}
backend.Status.Phase = loadbalancerv1beta1.BackendPhaseDeleted
Expand Down

0 comments on commit dad462a

Please sign in to comment.