Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
64 changes: 64 additions & 0 deletions .github/workflows/apisix-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,67 @@ jobs:
else
make ginkgo-e2e-test
fi

disable-gateway-api:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Go Env
uses: actions/setup-go@v4
with:
go-version: "1.24"

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "*"

- name: Install kind
run: |
go install sigs.k8s.io/kind@v0.23.0

- name: Install ginkgo
run: |
make install-ginkgo

- name: Build images
env:
TAG: dev
ARCH: amd64
ENABLE_PROXY: "false"
BASE_IMAGE_TAG: "debug"
run: |
echo "building images..."
make build-image

- name: Launch Kind Cluster
run: |
make kind-up

- name: Loading Docker Image to Kind Cluster
run: |
make kind-load-images

- name: Extract adc binary
if: ${{ env.ADC_VERSION == 'dev' }}
run: |
docker create --name adc-temp ghcr.io/api7/adc:dev
docker cp adc-temp:main.js adc.js
docker rm adc-temp
node $(pwd)/adc.js -v
echo "ADC_BIN=node $(pwd)/adc.js" >> $GITHUB_ENV

- name: Install CRDs
run: make install-crds

- name: Run E2E test suite
shell: bash
env:
TEST_DIR: "./test/e2e/apisix/"
TEST_ENV: CI
TEST_FOCUS: "Test ApisixRoute Basic tests"
run: make e2e-test
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ uninstall-gateway-api: ## Uninstall Gateway API CRDs from the K8s cluster specif
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/$(GATEAY_API_VERSION)/experimental-install.yaml

.PHONY: install
install: manifests kustomize install-gateway-api ## Install CRDs into the K8s cluster specified in ~/.kube/config.
install: manifests kustomize install-gateway-api install-crds ## Install CRDs and Gateway API into the K8s cluster specified in ~/.kube/config.

.PHONY: install-crds
install-crds: manifests kustomize ## Install CRDs into the K8s cluster specified
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -

.PHONY: install-crds-nocel
Expand Down
2 changes: 2 additions & 0 deletions config/samples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ secure_metrics: false # The secure metrics configuration.

exec_adc_timeout: 15s # The timeout for the ADC to execute.
# The default value is 15 seconds.
disable_gateway_api: false # Whether to disable the Gateway API support.
# The default value is false.

disable_gateway_api: false # Whether to disable the Gateway API support.
# The default value is false.
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/consumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
"github.com/apache/apisix-ingress-controller/internal/utils"
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
)

// ConsumerReconciler reconciles a Gateway object.
Expand All @@ -60,6 +61,10 @@ type ConsumerReconciler struct { //nolint:revive

// SetupWithManager sets up the controller with the Manager.
func (r *ConsumerReconciler) SetupWithManager(mgr ctrl.Manager) error {
if config.ControllerConfig.DisableGatewayAPI || !pkgutils.HasAPIResource(mgr, &gatewayv1.Gateway{}) {
r.Log.Info("skipping Consumer controller setup as Gateway API is not available")
return nil
}
return ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.Consumer{},
builder.WithPredicates(
Expand Down
27 changes: 27 additions & 0 deletions internal/controller/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
"github.com/apache/apisix-ingress-controller/internal/utils"
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
)

// GatewayReconciler reconciles a Gateway object.
Expand Down Expand Up @@ -80,7 +81,15 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
).
Watches(
&gatewayv1.HTTPRoute{},
<<<<<<< HEAD
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForHTTPRoute),
=======
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
).
Watches(
&gatewayv1.GRPCRoute{},
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
).
Watches(
&v1alpha1.GatewayProxy{},
Expand All @@ -97,6 +106,24 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
builder.WithPredicates(referenceGrantPredicates(KindGateway)),
)
}
if pkgutils.HasAPIResource(mgr, &gatewayv1alpha2.TCPRoute{}) {
bdr.Watches(
&gatewayv1alpha2.TCPRoute{},
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
)
}
if pkgutils.HasAPIResource(mgr, &gatewayv1alpha2.TLSRoute{}) {
bdr.Watches(
&gatewayv1alpha2.TLSRoute{},
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
)
}
if pkgutils.HasAPIResource(mgr, &gatewayv1alpha2.UDPRoute{}) {
bdr.Watches(
&gatewayv1alpha2.UDPRoute{},
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForStatusParentRefs),
)
}

return bdr.Complete(r)
}
Expand Down
52 changes: 52 additions & 0 deletions internal/controller/gatewayproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type GatewayProxyController struct {
Log logr.Logger
Provider provider.Provider

<<<<<<< HEAD
ICGV schema.GroupVersion
// supportsEndpointSlice indicates whether the cluster supports EndpointSlice API
supportsEndpointSlice bool
Expand Down Expand Up @@ -81,6 +82,16 @@ func (r *GatewayProxyController) SetupWithManager(mrg ctrl.Manager) error {
}

bdr := ctrl.NewControllerManagedBy(mrg).
=======
disableGatewayAPI bool
}

func (r *GatewayProxyController) SetupWithManager(mrg ctrl.Manager) error {
if config.ControllerConfig.DisableGatewayAPI || !pkgutils.HasAPIResource(mrg, &gatewayv1.Gateway{}) {
r.disableGatewayAPI = true
}
builder := ctrl.NewControllerManagedBy(mrg).
>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
For(&v1alpha1.GatewayProxy{}).
WithEventFilter(predicate.Or(eventFilters...)).
Watches(&corev1.Service{},
Expand Down Expand Up @@ -110,7 +121,19 @@ func (r *GatewayProxyController) SetupWithManager(mrg ctrl.Manager) error {
Watches(&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.listGatewayProxiesForSecret),
).
<<<<<<< HEAD
Complete(r)
=======
Watches(&networkingv1.IngressClass{},
handler.EnqueueRequestsFromMapFunc(r.listGatewayProxiesForIngressClass),
)
if !r.disableGatewayAPI {
builder.Watches(&gatewayv1.Gateway{},
handler.EnqueueRequestsFromMapFunc(r.listGatewayProxiesByGateway),
)
}
return builder.Complete(r)
>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
}

func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request) (reconcile.Result, error) {
Expand Down Expand Up @@ -170,8 +193,18 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
indexKey := indexer.GenIndexKey(gp.GetNamespace(), gp.GetName())

// list Gateways that reference the GatewayProxy
<<<<<<< HEAD
if r.supportsGateway {
var gatewayList gatewayv1.GatewayList
=======
var (
gatewayList gatewayv1.GatewayList
ingressClassList networkingv1.IngressClassList
indexKey = indexer.GenIndexKey(gp.GetNamespace(), gp.GetName())
)

if !r.disableGatewayAPI {
>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
if err := r.List(ctx, &gatewayList, client.MatchingFields{indexer.ParametersRef: indexKey}); err != nil {
r.Log.Error(err, "failed to list GatewayList")
return ctrl.Result{}, nil
Expand All @@ -195,6 +228,7 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
tctx.GatewayProxyReferrers[req.NamespacedName] = append(tctx.GatewayProxyReferrers[req.NamespacedName], utils.NamespacedNameKind(&item))
}
}
<<<<<<< HEAD
}

switch r.ICGV.String() {
Expand Down Expand Up @@ -227,6 +261,24 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
tctx.GatewayProxyReferrers[req.NamespacedName] = append(tctx.GatewayProxyReferrers[req.NamespacedName], utils.NamespacedNameKind(&item))
}
}
=======
r.Log.V(1).Info("found Gateways for GatewayProxy", "gatewayproxy", req.String(), "gateways", len(gatewayList.Items), "gatewayclasses", len(gatewayclassList.Items), "ingressclasses", len(ingressClassList.Items))
}

// list IngressClasses that reference the GatewayProxy
if err := r.List(ctx, &ingressClassList, client.MatchingFields{indexer.IngressClassParametersRef: indexKey}); err != nil {
r.Log.Error(err, "failed to list IngressClassList")
return reconcile.Result{}, err
}

for _, item := range ingressClassList.Items {
if item.Spec.Controller != config.GetControllerName() {
continue
}
tctx.GatewayProxyReferrers[req.NamespacedName] = append(tctx.GatewayProxyReferrers[req.NamespacedName], utils.NamespacedNameKind(&item))
}

>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
if len(tctx.GatewayProxyReferrers[req.NamespacedName]) == 0 {
return ctrl.Result{}, nil
}
Expand Down
74 changes: 72 additions & 2 deletions internal/controller/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ import (
"github.com/apache/apisix-ingress-controller/internal/adc/translator/annotations"
"github.com/apache/apisix-ingress-controller/internal/controller/config"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
<<<<<<< HEAD
k8sutils "github.com/apache/apisix-ingress-controller/internal/utils"
=======
>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
"github.com/apache/apisix-ingress-controller/pkg/utils"
)

Expand All @@ -58,6 +61,7 @@ const (
ControllerName = "controllerName"
)

<<<<<<< HEAD
func SetupIndexer(mgr ctrl.Manager) error {
setupLog := ctrl.LoggerFrom(context.Background()).WithName("indexer-setup")

Expand Down Expand Up @@ -106,9 +110,66 @@ func SetupIndexer(mgr ctrl.Manager) error {
setupApisixTlsIndexer,
setupApisixConsumerIndexer,
setupApisixGlobalRuleIndexer,
=======
func SetupAPIv1alpha1Indexer(mgr ctrl.Manager) error {
setupLog := ctrl.LoggerFrom(context.Background()).WithName("indexer").WithName("apiv1alpha1")
for resource, setup := range map[client.Object]func(ctrl.Manager) error{
&v1alpha1.BackendTrafficPolicy{}: setupBackendTrafficPolicyIndexer,
&v1alpha1.Consumer{}: setupConsumerIndexer,
&v1alpha1.GatewayProxy{}: setupGatewayProxyIndexer,
>>>>>>> 4f9cd000 (feat: support disable gateway-api (#2672))
} {
if err := setup(mgr); err != nil {
return err
if utils.HasAPIResource(mgr, resource) {
if err := setup(mgr); err != nil {
return err
}
} else {
setupLog.Info("Skipping indexer setup, API not found in cluster", "api", utils.FormatGVK(resource))
}
}
return nil
}
func SetupAPIv2Indexer(mgr ctrl.Manager) error {
setupLog := ctrl.LoggerFrom(context.Background()).WithName("indexer").WithName("apiv2")

for resource, setup := range map[client.Object]func(ctrl.Manager) error{
&networkingv1.IngressClass{}: setupIngressClassIndexer,
&networkingv1.Ingress{}: setupIngressIndexer,
&apiv2.ApisixConsumer{}: setupApisixConsumerIndexer,
&apiv2.ApisixRoute{}: setupApisixRouteIndexer,
&apiv2.ApisixPluginConfig{}: setupApisixPluginConfigIndexer,
&apiv2.ApisixTls{}: setupApisixTlsIndexer,
&apiv2.ApisixGlobalRule{}: setupApisixGlobalRuleIndexer,
} {
if utils.HasAPIResource(mgr, resource) {
if err := setup(mgr); err != nil {
return err
}
} else {
setupLog.Info("Skipping indexer setup, API not found in cluster", "api", utils.FormatGVK(resource))
}
}
return nil
}

func SetupGatewayAPIIndexer(mgr ctrl.Manager) error {
setupLog := ctrl.LoggerFrom(context.Background()).WithName("indexer").WithName("gatewayapi")

for resource, setup := range map[client.Object]func(ctrl.Manager) error{
&gatewayv1.Gateway{}: setupGatewayIndexer,
&gatewayv1.HTTPRoute{}: setupHTTPRouteIndexer,
&gatewayv1.GRPCRoute{}: setupGRPCRouteIndexer,
&gatewayv1alpha2.TCPRoute{}: setupTCPRouteIndexer,
&gatewayv1alpha2.UDPRoute{}: setupUDPRouteIndexer,
&gatewayv1alpha2.TLSRoute{}: setupTLSRouteIndexer,
&gatewayv1.GatewayClass{}: setupGatewayClassIndexer,
} {
if utils.HasAPIResource(mgr, resource) {
if err := setup(mgr); err != nil {
return err
}
} else {
setupLog.Info("Skipping indexer setup, API not found in cluster", "api", utils.FormatGVK(resource))
}
}
return nil
Expand Down Expand Up @@ -153,6 +214,15 @@ func setupGatewayIndexer(mgr ctrl.Manager) error {
return err
}

if err := mgr.GetFieldIndexer().IndexField(
context.Background(),
&gatewayv1.Gateway{},
SecretIndexRef,
GatewaySecretIndexFunc,
); err != nil {
return err
}

return nil
}

Expand Down
Loading