Skip to content

Commit

Permalink
MINOR: 6060 as default controller port, fix pprof missing in maps, ad…
Browse files Browse the repository at this point in the history
…d e2e tests

This MR fixes several issues around the controller port:
- set 6060 as default port, so techdump endpoint is working without adding --controller-port parameter
- fix pprof backend, entries were missing in maps
- have server for prometheus, pprof and techdump starts on ControllerPort and not hard-coded to 6060

This MR also adds e2e tests for techdump and pprof endpoints. Not testing the bahavior, but at least that:
- pprof can be triggered
  • Loading branch information
hdurand0710 committed Dec 21, 2023
1 parent 37e3276 commit 8894726
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode/*
.idea/*
.test/*
kubernetes-ingress
dist/
.code-generator/
Expand Down
2 changes: 2 additions & 0 deletions deploy/tests/config/3.ingress-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
- --configmap-patternfiles=$(POD_NAMESPACE)/patternfiles
- --ingress.class=haproxy
- --sync-period=1s
- --pprof
- --prometheus
securityContext:
runAsUser: 1000
runAsGroup: 1000
Expand Down
50 changes: 50 additions & 0 deletions deploy/tests/e2e/admin-port/pprof_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2019 HAProxy Technologies LLC
//
// Licensed 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.

//go:build e2e_parallel

package adminport

import (
"net/http"

"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
)

func (suite *AdminPortSuite) Test_Pprof() {
suite.Run("OK", func() {
suite.Eventually(func() bool {
suite.client.Path = "/debug/pprof/cmdline"
res, cls, err := suite.client.Do()
if err != nil {
suite.T().Logf("Connection ERROR: %s", err.Error())
return false
}
defer cls()
return res.StatusCode == http.StatusOK
}, e2e.WaitDuration, e2e.TickDuration)
})
suite.Run("OK", func() {
suite.Eventually(func() bool {
suite.client.Path = "/debug/pprof/symbol"
res, cls, err := suite.client.Do()
if err != nil {
suite.T().Logf("Connection ERROR: %s", err.Error())
return false
}
defer cls()
return res.StatusCode == http.StatusOK
}, e2e.WaitDuration, e2e.TickDuration)
})
}
56 changes: 56 additions & 0 deletions deploy/tests/e2e/admin-port/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2019 HAProxy Technologies LLC
//
// Licensed 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.

//go:build e2e_parallel

package adminport

import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
)

type AdminPortSuite struct {
suite.Suite
test e2e.Test
client *e2e.Client
tmplData tmplData
}

type tmplData struct {
Host string
}

func (suite *AdminPortSuite) SetupSuite() {
var err error
suite.test, err = e2e.NewTest()
suite.NoError(err)
suite.tmplData = tmplData{Host: suite.test.GetNS() + ".test"}
suite.client, err = e2e.NewHTTPClient(suite.tmplData.Host)
suite.NoError(err)
}

func (suite *AdminPortSuite) TearDownSuite() {
err := suite.test.TearDown()
if err != nil {
suite.T().Error(err)
}
}

func TestAdminPortSuite(t *testing.T) {
suite.Run(t, new(AdminPortSuite))
}
4 changes: 2 additions & 2 deletions deploy/tests/e2e/map-updates/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (suite *MapUpdateSuite) Test_Update() {
suite.NoError(err)
count, err := e2e.GetHAProxyMapCount("path-prefix")
suite.NoError(err)
suite.T().Log(count)
return oldInfo.Pid == newInfo.Pid && count == 700
suite.T().Logf("oldInfo.Pid(%s) == newInfo.Pid(%s) && count(%d) == 701", oldInfo.Pid, newInfo.Pid, count)
return oldInfo.Pid == newInfo.Pid && count == 701 // 700 + pprof
}, e2e.WaitDuration, e2e.TickDuration)
})
}
8 changes: 8 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type HAProxyController struct {
podPrefix string
chShutdown chan struct{}
updatePublishServiceFunc func(ingresses []*ingress.Ingress, publishServiceAddresses []string)
beforeUpdateHandlers []UpdateHandler
}

// Wrapping a Native-Client transaction and commit it.
Expand Down Expand Up @@ -111,6 +112,13 @@ func (c *HAProxyController) updateHAProxy() {
}

ingresses := []*ingress.Ingress{}

for _, handler := range c.beforeUpdateHandlers {
reload, err = handler.Update(c.store, c.haproxy, c.annotations)
logger.Error(err)
c.reload = c.reload || reload
}

for _, namespace := range c.store.Namespaces {
if !namespace.Relevant {
continue
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func (c *HAProxyController) initHandlers() {
}

c.updateHandlers = append(c.updateHandlers, handler.Refresh{})

c.beforeUpdateHandlers = []UpdateHandler{}
// Need to be before Refresh. If after, maps are refreshed without pprof content
if c.osArgs.PprofEnabled {
c.beforeUpdateHandlers = append(c.beforeUpdateHandlers, handler.Pprof{})
}
}

func (c *HAProxyController) startupHandlers() error {
Expand All @@ -70,9 +76,7 @@ func (c *HAProxyController) startupHandlers() error {
IPv6Addr: c.osArgs.IPV6BindAddr,
},
}
if c.osArgs.PprofEnabled {
handlers = append(handlers, handler.Pprof{})
}

for _, handler := range handlers {
_, err := handler.Update(c.store, c.haproxy, c.annotations)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/handler/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package handler

import (
"fmt"

"github.com/haproxytech/client-native/v3/models"

"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
Expand All @@ -38,8 +40,8 @@ func (handler Pprof) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annota
return
}
err = h.BackendServerCreate(pprofBackend, models.Server{
Name: "pprof",
Address: "127.0.0.1:6060",
Name: pprofBackend,
Address: fmt.Sprintf("127.0.0.1:%d", h.Env.ControllerPort),
})
if err != nil {
return
Expand All @@ -56,6 +58,6 @@ func (handler Pprof) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annota
if err != nil {
return
}
reload = true
// instance.Reload("pprof backend created")
return
}
3 changes: 2 additions & 1 deletion pkg/haproxy/env/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Env struct {
MapsDir string
Certs certs.Env
Proxies
ControllerPort int
}

// Proxies contains names of the main proxies of haproxy config
Expand Down Expand Up @@ -85,7 +86,7 @@ func (env *Env) Init(osArgs utils.OSArgs) (err error) {
env.MapsDir = filepath.Join(env.CfgDir, "maps")
env.PatternDir = filepath.Join(env.CfgDir, "patterns")
env.ErrFileDir = filepath.Join(env.CfgDir, "errorfiles")

env.ControllerPort = osArgs.ControllerPort
for _, d := range []string{
env.Certs.MainDir,
env.Certs.FrontendDir,
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type OSArgs struct { //nolint:maligned
RuntimeDir string `long:"runtime-dir" description:"path to HAProxy runtime directory. NOTE: works only in External mode"`
DisableServiceExternalName bool `long:"disable-service-external-name" description:"disable forwarding to ExternalName Services due to CVE-2021-25740"`
UseWiths6Overlay bool `long:"with-s6-overlay" description:"use s6 overlay to start/stpop/reload HAProxy"`
ControllerPort int `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof"`
ControllerPort int `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof" default:"6060"`
PprofEnabled bool `long:"pprof" short:"p" description:"enable pprof"`
PrometheusEnabled bool `long:"prometheus" description:"enable prometheus of IC data"`
ChannelSize int64 `long:"channel-size" description:"sets the size of controller buffers used to receive and send k8s events.NOTE: increase the value to accommodate large number of resources "`
Expand Down

0 comments on commit 8894726

Please sign in to comment.