Skip to content

Commit

Permalink
feat: support GatewayClass, refactor gateway modules (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingsamuel authored Jun 16, 2022
1 parent a0b88d1 commit c48a62a
Show file tree
Hide file tree
Showing 30 changed files with 1,331 additions and 608 deletions.
17 changes: 9 additions & 8 deletions pkg/ingress/apisix_pluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/apache/apisix-ingress-controller/pkg/config"
"github.com/apache/apisix-ingress-controller/pkg/ingress/utils"
"github.com/apache/apisix-ingress-controller/pkg/kube"
"github.com/apache/apisix-ingress-controller/pkg/kube/translation"
"github.com/apache/apisix-ingress-controller/pkg/log"
Expand Down Expand Up @@ -167,14 +168,14 @@ func (c *apisixPluginConfigController) sync(ctx context.Context, ev *types.Event
zap.Any("pluginConfigs", tctx.PluginConfigs),
)

m := &manifest{
pluginConfigs: tctx.PluginConfigs,
m := &utils.Manifest{
PluginConfigs: tctx.PluginConfigs,
}

var (
added *manifest
updated *manifest
deleted *manifest
added *utils.Manifest
updated *utils.Manifest
deleted *utils.Manifest
)

if ev.Type == types.EventDelete {
Expand All @@ -199,10 +200,10 @@ func (c *apisixPluginConfigController) sync(ctx context.Context, ev *types.Event
return err
}

om := &manifest{
pluginConfigs: oldCtx.PluginConfigs,
om := &utils.Manifest{
PluginConfigs: oldCtx.PluginConfigs,
}
added, updated, deleted = m.diff(om)
added, updated, deleted = m.Diff(om)
}

return c.controller.syncManifests(ctx, added, updated, deleted)
Expand Down
29 changes: 15 additions & 14 deletions pkg/ingress/apisix_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/client-go/util/workqueue"

apisixcache "github.com/apache/apisix-ingress-controller/pkg/apisix/cache"
"github.com/apache/apisix-ingress-controller/pkg/ingress/utils"
"github.com/apache/apisix-ingress-controller/pkg/kube"
v2 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
Expand Down Expand Up @@ -189,17 +190,17 @@ func (c *apisixRouteController) sync(ctx context.Context, ev *types.Event) error
zap.Any("pluginConfigs", tctx.PluginConfigs),
)

m := &manifest{
routes: tctx.Routes,
upstreams: tctx.Upstreams,
streamRoutes: tctx.StreamRoutes,
pluginConfigs: tctx.PluginConfigs,
m := &utils.Manifest{
Routes: tctx.Routes,
Upstreams: tctx.Upstreams,
StreamRoutes: tctx.StreamRoutes,
PluginConfigs: tctx.PluginConfigs,
}

var (
added *manifest
updated *manifest
deleted *manifest
added *utils.Manifest
updated *utils.Manifest
deleted *utils.Manifest
)

if ev.Type == types.EventDelete {
Expand All @@ -226,13 +227,13 @@ func (c *apisixRouteController) sync(ctx context.Context, ev *types.Event) error
return err
}

om := &manifest{
routes: oldCtx.Routes,
upstreams: oldCtx.Upstreams,
streamRoutes: oldCtx.StreamRoutes,
pluginConfigs: oldCtx.PluginConfigs,
om := &utils.Manifest{
Routes: oldCtx.Routes,
Upstreams: oldCtx.Upstreams,
StreamRoutes: oldCtx.StreamRoutes,
PluginConfigs: oldCtx.PluginConfigs,
}
added, updated, deleted = m.diff(om)
added, updated, deleted = m.Diff(om)
}

return c.controller.syncManifests(ctx, added, updated, deleted)
Expand Down
25 changes: 4 additions & 21 deletions pkg/ingress/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/apisix-ingress-controller/pkg/api/validation"
"github.com/apache/apisix-ingress-controller/pkg/log"
)

Expand All @@ -46,24 +45,9 @@ func (c *Controller) CompareResources(ctx context.Context) error {
consumerMapA6 = make(map[string]string)
pluginConfigMapA6 = make(map[string]string)
)
// watchingNamespaces and watchingLabels are empty means to monitor all namespaces.
if !validation.HasValueInSyncMap(c.watchingNamespaces) && len(c.watchingLabels) == 0 {
opts := v1.ListOptions{}
// list all namespaces
nsList, err := c.kubeClient.Client.CoreV1().Namespaces().List(ctx, opts)
if err != nil {
log.Error(err.Error())
ctx.Done()
} else {
wns := new(sync.Map)
for _, v := range nsList.Items {
wns.Store(v.Name, struct{}{})
}
c.watchingNamespaces = wns
}
}

c.watchingNamespaces.Range(func(key, value interface{}) bool {
namespaces := c.namespaceProvider.WatchingNamespaces()
for _, key := range namespaces {
log.Debugf("start to watch namespace: %s", key)
wg.Add(1)
go func(ns string) {
Expand Down Expand Up @@ -139,9 +123,8 @@ func (c *Controller) CompareResources(ctx context.Context) error {
}
}
}
}(key.(string))
return true
})
}(key)
}
wg.Wait()

// 2.get all cache routes
Expand Down
Loading

0 comments on commit c48a62a

Please sign in to comment.