Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bug-836
Browse files Browse the repository at this point in the history
  • Loading branch information
neverCase committed Feb 24, 2022
2 parents 4b6cce0 + d30bef5 commit 4547a1a
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 98 deletions.
28 changes: 18 additions & 10 deletions docs/en/latest/practices/the-hard-way.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ spec:
volumeMounts:
- name: data
mountPath: /etcd
# If you don't have a storage provisioner or don't want to use persistence volume, you could use an `emptyDir` as follow.
# volumes:
# - name: data
# emptyDir: {}
volumeClaimTemplates:
- metadata:
name: data
Expand Down Expand Up @@ -443,11 +447,13 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: apisix-ingress-controller
namespace: apisix
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: apisix-clusterrole
namespace: apisix
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -589,6 +595,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: apisix-clusterrolebinding
namespace: apisix
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down Expand Up @@ -694,7 +701,7 @@ spec:
initContainers:
- name: wait-apisix-admin
image: busybox:1.28
command: ['sh', '-c', "until nc -z apisix-service.apisix.svc.cluster.local 9180 ; do echo waiting for apisix-admin; sleep 2; done;"]
command: ['sh', '-c', "until nc -z apisix-admin.apisix.svc.cluster.local 9180 ; do echo waiting for apisix-admin; sleep 2; done;"]
containers:
- name: ingress-controller
command:
Expand Down Expand Up @@ -730,20 +737,21 @@ After the ingress controller status is converted to `Running`, we could create a
Here is an example ApisixRoute:

```yaml
apiVersion: apisix.apache.org/v2beta1
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
name: httpserver-route
namespace: demo
spec:
http:
- name: httpbin
match:
hosts:
- local.httpbin.org
paths:
- "/*"
backend:
serviceName: httpbin
- name: httpbin
match:
hosts:
- local.httpbin.org
paths:
- /*
backends:
- serviceName: httpbin
servicePort: 80
```

Expand Down
6 changes: 3 additions & 3 deletions pkg/ingress/apisix_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *apisixConsumerController) onAdd(obj interface{}) {
log.Errorf("found ApisixConsumer resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixConsumer add event arrived",
Expand All @@ -184,7 +184,7 @@ func (c *apisixConsumerController) onUpdate(oldObj, newObj interface{}) {
log.Errorf("found ApisixConsumer resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixConsumer update event arrived",
Expand Down Expand Up @@ -215,7 +215,7 @@ func (c *apisixConsumerController) onDelete(obj interface{}) {
log.Errorf("found ApisixConsumer resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixConsumer delete event arrived",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ingress/apisix_pluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (c *apisixPluginConfigController) onAdd(obj interface{}) {
log.Errorf("found ApisixPluginConfig resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixPluginConfig add event arrived",
Expand Down Expand Up @@ -277,7 +277,7 @@ func (c *apisixPluginConfigController) onUpdate(oldObj, newObj interface{}) {
log.Errorf("found ApisixPluginConfig resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixPluginConfig update event arrived",
Expand Down Expand Up @@ -310,7 +310,7 @@ func (c *apisixPluginConfigController) onDelete(obj interface{}) {
log.Errorf("found ApisixPluginConfig resource with bad meta namesapce key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixPluginConfig delete event arrived",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ingress/apisix_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (c *apisixRouteController) onAdd(obj interface{}) {
log.Errorf("found ApisixRoute resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixRoute add event arrived",
Expand Down Expand Up @@ -364,7 +364,7 @@ func (c *apisixRouteController) onUpdate(oldObj, newObj interface{}) {
log.Errorf("found ApisixRoute resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixRoute update event arrived",
Expand Down Expand Up @@ -397,7 +397,7 @@ func (c *apisixRouteController) onDelete(obj interface{}) {
log.Errorf("found ApisixRoute resource with bad meta namesapce key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixRoute delete event arrived",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ingress/apisix_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *apisixTlsController) onAdd(obj interface{}) {
log.Errorf("found ApisixTls object with bad namespace/name: %s, ignore it", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixTls add event arrived",
Expand All @@ -214,7 +214,7 @@ func (c *apisixTlsController) onUpdate(prev, curr interface{}) {
log.Errorf("found ApisixTls object with bad namespace/name: %s, ignore it", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixTls update event arrived",
Expand Down Expand Up @@ -246,7 +246,7 @@ func (c *apisixTlsController) onDelete(obj interface{}) {
log.Errorf("found ApisixTls resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixTls delete event arrived",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ingress/apisix_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (c *apisixUpstreamController) onAdd(obj interface{}) {
log.Errorf("found ApisixUpstream resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixUpstream add event arrived",
Expand All @@ -246,7 +246,7 @@ func (c *apisixUpstreamController) onUpdate(oldObj, newObj interface{}) {
log.Errorf("found ApisixUpstream resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixUpstream update event arrived",
Expand Down Expand Up @@ -277,7 +277,7 @@ func (c *apisixUpstreamController) onDelete(obj interface{}) {
log.Errorf("found ApisixUpstream resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("ApisixUpstream delete event arrived",
Expand Down
8 changes: 4 additions & 4 deletions pkg/ingress/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (c *Controller) CompareResources(ctx context.Context) error {
consumerMapA6 = make(map[string]string)
pluginConfigMapA6 = make(map[string]string)
)
// watchingNamespace == nil means to monitor all namespaces
if !validation.HasValueInSyncMap(c.watchingNamespace) {
// watchingNamespaces == nil means to monitor all namespaces
if !validation.HasValueInSyncMap(c.watchingNamespaces) {
opts := v1.ListOptions{}
// list all namespaces
nsList, err := c.kubeClient.Client.CoreV1().Namespaces().List(ctx, opts)
Expand All @@ -59,11 +59,11 @@ func (c *Controller) CompareResources(ctx context.Context) error {
for _, v := range nsList.Items {
wns.Store(v.Name, struct{}{})
}
c.watchingNamespace = wns
c.watchingNamespaces = wns
}
}

c.watchingNamespace.Range(func(key, value interface{}) bool {
c.watchingNamespaces.Range(func(key, value interface{}) bool {
wg.Add(1)
go func(ns string) {
defer wg.Done()
Expand Down
58 changes: 29 additions & 29 deletions pkg/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ const (

// Controller is the ingress apisix controller object.
type Controller struct {
name string
namespace string
cfg *config.Config
wg sync.WaitGroup
watchingNamespace *sync.Map
watchingLabels types.Labels
apisix apisix.APISIX
podCache types.PodCache
translator translation.Translator
apiServer *api.Server
MetricsCollector metrics.Collector
kubeClient *kube.KubeClient
name string
namespace string
cfg *config.Config
wg sync.WaitGroup
watchingNamespaces *sync.Map
watchingLabels types.Labels
apisix apisix.APISIX
podCache types.PodCache
translator translation.Translator
apiServer *api.Server
MetricsCollector metrics.Collector
kubeClient *kube.KubeClient
// recorder event
recorder record.EventRecorder
// this map enrolls which ApisixTls objects refer to a Kubernetes
Expand Down Expand Up @@ -181,17 +181,17 @@ func NewController(cfg *config.Config) (*Controller, error) {
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeClient.Client.CoreV1().Events("")})

c := &Controller{
name: podName,
namespace: podNamespace,
cfg: cfg,
apiServer: apiSrv,
apisix: client,
MetricsCollector: metrics.NewPrometheusCollector(),
kubeClient: kubeClient,
watchingNamespace: watchingNamespace,
watchingLabels: watchingLabels,
secretSSLMap: new(sync.Map),
recorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: _component}),
name: podName,
namespace: podNamespace,
cfg: cfg,
apiServer: apiSrv,
apisix: client,
MetricsCollector: metrics.NewPrometheusCollector(),
kubeClient: kubeClient,
watchingNamespaces: watchingNamespace,
watchingLabels: watchingLabels,
secretSSLMap: new(sync.Map),
recorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: _component}),

podCache: types.NewPodCache(),
}
Expand Down Expand Up @@ -442,8 +442,8 @@ func (c *Controller) run(ctx context.Context) {

c.initWhenStartLeading()

// list namesapce and init watchingNamespace
if err := c.initWatchingNamespaceByLabels(ctx); err != nil {
// list namespaces and init watchingNamespaces
if err := c.initWatchingNamespacesByLabels(ctx); err != nil {
ctx.Done()
return
}
Expand Down Expand Up @@ -552,10 +552,10 @@ func (c *Controller) run(ctx context.Context) {
c.wg.Wait()
}

// namespaceWatching accepts a resource key, getting the namespace part
// isWatchingNamespace accepts a resource key, getting the namespace part
// and checking whether the namespace is being watched.
func (c *Controller) namespaceWatching(key string) (ok bool) {
if !validation.HasValueInSyncMap(c.watchingNamespace) {
func (c *Controller) isWatchingNamespace(key string) (ok bool) {
if !validation.HasValueInSyncMap(c.watchingNamespaces) {
ok = true
return
}
Expand All @@ -566,7 +566,7 @@ func (c *Controller) namespaceWatching(key string) (ok bool) {
log.Warnf("resource %s was ignored since: %s", key, err)
return
}
_, ok = c.watchingNamespace.Load(ns)
_, ok = c.watchingNamespaces.Load(ns)
return
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/ingress/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *endpointsController) onAdd(obj interface{}) {
log.Errorf("found endpoints object with bad namespace/name: %s, ignore it", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("endpoints add event arrived",
Expand All @@ -133,7 +133,7 @@ func (c *endpointsController) onUpdate(prev, curr interface{}) {
log.Errorf("found endpoints object with bad namespace/name: %s, ignore it", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("endpoints update event arrived",
Expand All @@ -160,10 +160,10 @@ func (c *endpointsController) onDelete(obj interface{}) {
ep = tombstone.Obj.(*corev1.Endpoints)
}

// FIXME Refactor Controller.namespaceWatching to just use
// FIXME Refactor Controller.isWatchingNamespace to just use
// namespace after all controllers use the same way to fetch
// the object.
if !c.controller.namespaceWatching(ep.Namespace + "/" + ep.Name) {
if !c.controller.isWatchingNamespace(ep.Namespace + "/" + ep.Name) {
return
}
log.Debugw("endpoints delete event arrived",
Expand Down
6 changes: 3 additions & 3 deletions pkg/ingress/endpointslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *endpointSliceController) onAdd(obj interface{}) {
if err != nil {
log.Errorf("found endpointSlice object with bad namespace")
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
ep := obj.(*discoveryv1.EndpointSlice)
Expand Down Expand Up @@ -165,7 +165,7 @@ func (c *endpointSliceController) onUpdate(prev, curr interface{}) {
log.Errorf("found endpointSlice object with bad namespace/name: %s, ignore it", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
if currEp.Labels[discoveryv1.LabelManagedBy] != _endpointSlicesManagedBy {
Expand Down Expand Up @@ -209,7 +209,7 @@ func (c *endpointSliceController) onDelete(obj interface{}) {
log.Errorf("found endpointSlice object with bad namespace/name: %s, ignore it", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
if ep.Labels[discoveryv1.LabelManagedBy] != _endpointSlicesManagedBy {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingress/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (c *gatewayController) onAdd(obj interface{}) {
log.Errorf("found gateway resource with bad meta namespace key: %s", err)
return
}
if !c.controller.namespaceWatching(key) {
if !c.controller.isWatchingNamespace(key) {
return
}
log.Debugw("gateway add event arrived",
Expand Down
Loading

0 comments on commit 4547a1a

Please sign in to comment.