Skip to content
Merged
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
2 changes: 2 additions & 0 deletions config/samples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ leader_election:
metrics_addr: ":8080" # The address the metrics endpoint binds to.
# The default value is ":8080".

server_addr: "127.0.0.1:9092" # Available endpoints: /debug can be used to debug in-memory state of translated adc configs to be synced with data plane.

enable_http2: false # Whether to enable HTTP/2 for the server.
# The default value is false.

Expand Down
2 changes: 2 additions & 0 deletions docs/en/latest/reference/configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ leader_election:
metrics_addr: ":8080" # The address the metrics endpoint binds to.
# The default value is ":8080".

server_addr: "127.0.0.1:9092" # Available endpoints: /debug can be used to debug in-memory state of translated adc configs to be synced with data plane.

enable_http2: false # Whether to enable HTTP/2 for the server.
# The default value is false.

Expand Down
14 changes: 9 additions & 5 deletions internal/adc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ type Client struct {
executor ADCExecutor
BackendMode string

ConfigManager *common.ConfigManager[types.NamespacedNameKind, adctypes.Config]
ConfigManager *common.ConfigManager[types.NamespacedNameKind, adctypes.Config]
ADCDebugProvider *common.ADCDebugProvider
}

func New(mode string, timeout time.Duration) (*Client, error) {
Expand All @@ -55,12 +56,15 @@ func New(mode string, timeout time.Duration) (*Client, error) {
serverURL = defaultHTTPADCExecutorAddr
}

store := cache.NewStore()
configManager := common.NewConfigManager[types.NamespacedNameKind, adctypes.Config]()
log.Infow("using HTTP ADC Executor", zap.String("server_url", serverURL))
return &Client{
Store: cache.NewStore(),
executor: NewHTTPADCExecutor(serverURL, timeout),
BackendMode: mode,
ConfigManager: common.NewConfigManager[types.NamespacedNameKind, adctypes.Config](),
Store: store,
executor: NewHTTPADCExecutor(serverURL, timeout),
BackendMode: mode,
ConfigManager: configManager,
ADCDebugProvider: common.NewADCDebugProvider(store, configManager),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func NewDefaultConfig() *Config {
LeaderElectionID: DefaultLeaderElectionID,
ProbeAddr: DefaultProbeAddr,
MetricsAddr: DefaultMetricsAddr,
ServerAddr: DefaultServerAddr,
LeaderElection: NewLeaderElection(),
ExecADCTimeout: types.TimeDuration{Duration: 15 * time.Second},
ProviderConfig: ProviderConfig{
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Config struct {
ControllerName string `json:"controller_name" yaml:"controller_name"`
LeaderElectionID string `json:"leader_election_id" yaml:"leader_election_id"`
MetricsAddr string `json:"metrics_addr" yaml:"metrics_addr"`
ServerAddr string `json:"server_addr" yaml:"server_addr"`
EnableServer bool `json:"enable_server" yaml:"enable_server"`
EnableHTTP2 bool `json:"enable_http2" yaml:"enable_http2"`
ProbeAddr string `json:"probe_addr" yaml:"probe_addr"`
SecureMetrics bool `json:"secure_metrics" yaml:"secure_metrics"`
Expand Down
9 changes: 9 additions & 0 deletions internal/manager/run.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/controller/config"
"github.com/apache/apisix-ingress-controller/internal/controller/status"
"github.com/apache/apisix-ingress-controller/internal/manager/readiness"
"github.com/apache/apisix-ingress-controller/internal/manager/server"
"github.com/apache/apisix-ingress-controller/internal/provider"
_ "github.com/apache/apisix-ingress-controller/internal/provider/init"
_ "github.com/apache/apisix-ingress-controller/pkg/metrics"
Expand Down Expand Up @@ -189,6 +190,14 @@ func Run(ctx context.Context, logger logr.Logger) error {
return err
}

if cfg.EnableServer {
srv := server.NewServer(config.ControllerConfig.ServerAddr)
srv.Register("/debug", provider)
if err := mgr.Add(srv); err != nil {
setupLog.Error(err, "unable to add debug server to manager")
return err
}
}
if err := mgr.Add(provider); err != nil {
setupLog.Error(err, "unable to add provider to manager")
return err
Expand Down
69 changes: 69 additions & 0 deletions internal/manager/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package server

import (
"context"
"net/http"
"time"

"github.com/apache/apisix-ingress-controller/internal/provider"
)

type Server struct {
server *http.Server
mux *http.ServeMux
}

func (s *Server) Start(ctx context.Context) error {
stop := make(chan error, 1)
go func() {
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
stop <- err
}
close(stop)
}()
select {
case <-ctx.Done():
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
return s.server.Shutdown(shutdownCtx)
case err := <-stop:
return err
}
}

func (s *Server) Register(pathPrefix string, registrant provider.RegisterHandler) {
subMux := http.NewServeMux()
registrant.Register(pathPrefix, subMux)
s.mux.Handle(pathPrefix+"/", http.StripPrefix(pathPrefix, subMux))
s.mux.HandleFunc(pathPrefix, func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, pathPrefix+"/", http.StatusPermanentRedirect)
})
}

func NewServer(addr string) *Server {
mux := http.NewServeMux()
return &Server{
server: &http.Server{
Addr: addr,
Handler: mux,
},
mux: mux,
}
}
5 changes: 5 additions & 0 deletions internal/provider/api7ee/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package api7ee

import (
"context"
"net/http"
"sync/atomic"
"time"

Expand Down Expand Up @@ -84,6 +85,10 @@ func New(updater status.Updater, readier readiness.ReadinessManager, opts ...pro
}, nil
}

func (d *api7eeProvider) Register(pathPrefix string, mux *http.ServeMux) {
d.client.ADCDebugProvider.SetupHandler(pathPrefix, mux)
}

func (d *api7eeProvider) Update(ctx context.Context, tctx *provider.TranslateContext, obj client.Object) error {
log.Debugw("updating object", zap.Any("object", obj))
var (
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/apisix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package apisix

import (
"context"
"net/http"
"sync"
"time"

Expand Down Expand Up @@ -91,6 +92,10 @@ func New(updater status.Updater, readier readiness.ReadinessManager, opts ...pro
}, nil
}

func (d *apisixProvider) Register(pathPrefix string, mux *http.ServeMux) {
d.client.ADCDebugProvider.SetupHandler(pathPrefix, mux)
}

func (d *apisixProvider) Update(ctx context.Context, tctx *provider.TranslateContext, obj client.Object) error {
log.Debugw("updating object", zap.Any("object", obj))
var (
Expand Down
Loading
Loading