Skip to content

Commit

Permalink
fix: catch route failure and trigger retry (#149)
Browse files Browse the repository at this point in the history
Fix #148
  • Loading branch information
gxthrj authored Jan 6, 2021
1 parent 8b65c9d commit 2a8e8a7
Show file tree
Hide file tree
Showing 20 changed files with 552 additions and 277 deletions.
5 changes: 3 additions & 2 deletions pkg/ingress/apisix/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"

"github.com/api7/ingress-controller/pkg/seven/utils"
apisix "github.com/api7/ingress-controller/pkg/types/apisix/v1"
)

Expand Down Expand Up @@ -154,5 +155,5 @@ func (sc *SecretClientMock) FindByName(namespace, name string) (*v1.Secret, erro
type SecretClientErrorMock struct{}

func (sc *SecretClientErrorMock) FindByName(namespace, name string) (*v1.Secret, error) {
return nil, fmt.Errorf("NOT FOUND")
return nil, utils.ErrNotFound
}
20 changes: 3 additions & 17 deletions pkg/ingress/controller/apisix_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
clientSet "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned"
api6Scheme "github.com/gxthrj/apisix-ingress-types/pkg/client/clientset/versioned/scheme"
api6Informers "github.com/gxthrj/apisix-ingress-types/pkg/client/informers/externalversions/config/v1"
v1 "github.com/gxthrj/apisix-ingress-types/pkg/client/listers/config/v1"
"github.com/gxthrj/apisix-ingress-types/pkg/client/listers/config/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
Expand All @@ -34,7 +34,6 @@ import (
"github.com/api7/ingress-controller/pkg/ingress/apisix"
"github.com/api7/ingress-controller/pkg/log"
"github.com/api7/ingress-controller/pkg/seven/state"
apisixV1 "github.com/api7/ingress-controller/pkg/types/apisix/v1"
)

type ApisixRouteController struct {
Expand Down Expand Up @@ -210,21 +209,8 @@ func (c *ApisixRouteController) add(key string) error {
apisixRoute := apisix.ApisixRoute(*apisixIngressRoute)
routes, services, upstreams, _ := apisixRoute.Convert()
comb := state.ApisixCombination{Routes: routes, Services: services, Upstreams: upstreams}
// protect: will retry when any upstream nodes is empty
retry := false
upstreamWithEmptyNodes := &apisixV1.Upstream{}
for _, upstream := range upstreams {
if len(upstream.Nodes) < 1 {
upstreamWithEmptyNodes = upstream
break
}
}
if !retry {
_, err = comb.Solver()
return err
} else {
return fmt.Errorf("upstream %s which nodes is empty", *upstreamWithEmptyNodes.Name)
}
_, err = comb.Solver()
return err

}

Expand Down
2 changes: 1 addition & 1 deletion pkg/seven/apisix/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func FindCurrentRoute(route *v1.Route) (*v1.Route, error) {
}

}
return nil, fmt.Errorf("NOT FOUND")
return nil, utils.ErrNotFound
}

// ListRoute list route from etcd , convert to v1.Route
Expand Down
7 changes: 3 additions & 4 deletions pkg/seven/db/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
package db

import (
"fmt"

"github.com/hashicorp/go-memdb"

v1 "github.com/api7/ingress-controller/pkg/types/apisix/v1"
"github.com/api7/ingress-controller/pkg/seven/utils"
"github.com/api7/ingress-controller/pkg/types/apisix/v1"
)

const (
Expand All @@ -42,7 +41,7 @@ func (rr *RouteRequest) FindByName() (*v1.Route, error) {
currentRoute := raw.(*v1.Route)
return currentRoute, nil
}
return nil, fmt.Errorf("NOT FOUND")
return nil, utils.ErrNotFound
}
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/seven/db/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
package db

import (
"fmt"

"github.com/hashicorp/go-memdb"

v1 "github.com/api7/ingress-controller/pkg/types/apisix/v1"
"github.com/api7/ingress-controller/pkg/seven/utils"
"github.com/api7/ingress-controller/pkg/types/apisix/v1"
)

const (
Expand All @@ -42,7 +41,7 @@ func (sr *ServiceRequest) FindByName() (*v1.Service, error) {
currentService := raw.(*v1.Service)
return currentService, nil
}
return nil, fmt.Errorf("NOT FOUND")
return nil, utils.ErrNotFound
}
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/seven/db/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
package db

import (
"fmt"

"github.com/hashicorp/go-memdb"

v1 "github.com/api7/ingress-controller/pkg/types/apisix/v1"
"github.com/api7/ingress-controller/pkg/seven/utils"
"github.com/api7/ingress-controller/pkg/types/apisix/v1"
)

const (
Expand All @@ -46,7 +45,7 @@ func (ur *UpstreamRequest) FindByName() (*v1.Upstream, error) {
currentUpstream := raw.(*v1.Upstream)
return currentUpstream, nil
}
return nil, fmt.Errorf("NOT FOUND")
return nil, utils.ErrNotFound
}
}

Expand Down
Loading

0 comments on commit 2a8e8a7

Please sign in to comment.