in pkg/api/server.go [47:105]
func NewServer(cfg *config.Config) (*Server, error) {
httpListener, err := net.Listen("tcp", cfg.HTTPListen)
if err != nil {
return nil, err
}
gin.SetMode(gin.ReleaseMode)
httpServer := gin.New()
httpServer.Use(log.GinRecovery(true), log.GinLogger())
apirouter.Mount(httpServer)
srv := &Server{
HealthState: new(apirouter.HealthState),
httpServer: httpServer,
httpListener: httpListener,
}
apirouter.MountApisixHealthz(httpServer, srv.HealthState)
if cfg.EnableProfiling {
srv.pprofMu = new(http.ServeMux)
srv.pprofMu.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
srv.pprofMu.HandleFunc("/debug/pprof/profile", pprof.Profile)
srv.pprofMu.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
srv.pprofMu.HandleFunc("/debug/pprof/trace", pprof.Trace)
srv.pprofMu.HandleFunc("/debug/pprof/", pprof.Index)
httpServer.GET("/debug/pprof/*profile", gin.WrapF(srv.pprofMu.ServeHTTP))
}
if cfg.Kubernetes.EnableAdmission {
cert, err := tls.LoadX509KeyPair(cfg.CertFilePath, cfg.KeyFilePath)
if err != nil {
log.Warnw("failed to load x509 key pair, will not start admission server",
zap.String("Error", err.Error()),
zap.String("CertFilePath", cfg.CertFilePath),
zap.String("KeyFilePath", cfg.KeyFilePath),
)
} else {
admission := gin.New()
admission.Use(gin.Recovery(), gin.Logger())
apirouter.MountWebhooks(admission, &apisix.ClusterOptions{
AdminAPIVersion: cfg.Kubernetes.APIVersion,
Name: cfg.APISIX.DefaultClusterName,
AdminKey: cfg.APISIX.DefaultClusterAdminKey,
BaseURL: cfg.APISIX.DefaultClusterBaseURL,
MetricsCollector: metrics.NewPrometheusCollector(),
SchemaSynced: true,
})
srv.admissionServer = &http.Server{
Addr: cfg.HTTPSListen,
Handler: admission,
TLSConfig: &tls.Config{
Certificates: []tls.Certificate{cert},
},
}
}
}
return srv, nil
}