Skip to content

Commit 21ec900

Browse files
committed
MINOR: add master socket
1 parent d60c02e commit 21ec900

File tree

7 files changed

+83
-7
lines changed

7 files changed

+83
-7
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
PROJECT_PATH=${PWD}
22
TARGETPLATFORM?=linux/amd64
3+
GOOS?=linux
4+
GOARCH?=amd64
35
GOLANGCI_LINT_VERSION=1.54.1
46

57
.PHONY: test
@@ -33,6 +35,15 @@ yaml-lint:
3335
example:
3436
deploy/tests/create.sh
3537

38+
.PHONY: example-pebble
39+
example-pebble:
40+
CUSTOMDOCKERFILE=build/Dockerfile.pebble deploy/tests/create.sh
41+
42+
## Install the `example` with an image built from a local build.
43+
.PHONY: example-dev
44+
example-dev: build-dev
45+
CUSTOMDOCKERFILE=build/Dockerfile.dev deploy/tests/create.sh
46+
3647
.PHONY: example-experimental-gwapi
3748
example-experimental-gwapi:
3849
EXPERIMENTAL_GWAPI=1 deploy/tests/create.sh
@@ -53,6 +64,13 @@ build:
5364
build-pebble:
5465
docker build -t haproxytech/kubernetes-ingress --build-arg TARGETPLATFORM=$(TARGETPLATFORM) -f build/Dockerfile.pebble .
5566

67+
### build-dev builds locally an ingress-controller binary and copies it into the docker image.
68+
### Can be used for example to use `go replace` and build with a local library,
69+
.PHONY: build-dev
70+
build-dev:
71+
GOOS=$(GOSS) GOARCH=$(GOARCH) go build .
72+
docker build -t haproxytech/kubernetes-ingress --build-arg TARGETPLATFORM=$(TARGETPLATFORM) -f build/Dockerfile.dev .
73+
5674
.PHONY: publish
5775
publish:
5876
goreleaser release --rm-dist

build/Dockerfile.dev

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2019 HAProxy Technologies LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM haproxytech/haproxy-alpine:2.7
16+
17+
ARG TARGETPLATFORM
18+
19+
ARG S6_OVERLAY_VERSION=2.2.0.3
20+
ENV S6_OVERLAY_VERSION $S6_OVERLAY_VERSION
21+
ENV S6_READ_ONLY_ROOT=1
22+
23+
COPY /fs /
24+
25+
RUN apk --no-cache add socat openssl util-linux htop tzdata curl libcap && \
26+
rm -f /usr/local/bin/dataplaneapi /usr/bin/dataplaneapi && \
27+
chgrp -R haproxy /usr/local/etc/haproxy /run /var && \
28+
chmod -R ug+rwx /usr/local/etc/haproxy /run /var && \
29+
setcap 'cap_net_bind_service=+ep' /usr/local/sbin/haproxy && \
30+
case "${TARGETPLATFORM}" in \
31+
"linux/arm64") S6_ARCH=aarch64 ;; \
32+
"linux/amd64") S6_ARCH=amd64 ;; \
33+
"linux/arm/v6") S6_ARCH=arm ;; \
34+
"linux/arm/v7") S6_ARCH=armhf ;; \
35+
"linux/ppc64le") S6_ARCH=ppc64le ;; \
36+
"linux/386") S6_ARCH=x86 ;; \
37+
*) echo "ARG TARGETPLATFORM undeclared" >&2 && exit 1 ;; \
38+
esac && \
39+
curl -sS -L -o /tmp/s6-overlay-installer "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}-installer" && \
40+
chmod +x /tmp/s6-overlay-installer && \
41+
/tmp/s6-overlay-installer / && \
42+
rm -f /tmp/s6-overlay-installer && \
43+
mkdir /var/run/s6 && \
44+
chown haproxy:haproxy /var/run/s6 && \
45+
chmod ug+rwx /var/run/s6 && \
46+
sed -i 's/ root / haproxy /g' /etc/s6/init/init-stage2-fixattrs.txt && \
47+
chmod ugo+x /etc/services.d/*/run /etc/cont-init.d/* && \
48+
rm -rf /var/lib/pebble
49+
50+
COPY kubernetes-ingress ./haproxy-ingress-controller
51+
52+
ENTRYPOINT ["/start.sh"]

deploy/tests/create.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22
set -e
33
clustername=${1:-dev}
4+
dockerfile=${CUSTOMDOCKERFILE:-build/Dockerfile}
45
command -v kind >/dev/null 2>&1 || { echo >&2 "Kind not installed. Aborting."; exit 1; }
56
command -v kubectl >/dev/null 2>&1 || { echo >&2 "Kubectl not installed. Aborting."; exit 1; }
67
DIR=$(dirname "$0")
@@ -31,7 +32,7 @@ else
3132
kind create cluster --name $clustername --config $DIR/kind-config.yaml
3233

3334
echo "building image for ingress controller"
34-
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/kubernetes-ingress -f build/Dockerfile .
35+
docker build --build-arg TARGETPLATFORM="linux/amd64" -t haproxytech/kubernetes-ingress -f "${dockerfile}" .
3536

3637
echo "loading image of ingress controller in kind"
3738
kind load docker-image haproxytech/kubernetes-ingress:latest --name=$clustername

fs/etc/services.d/haproxy/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ fi
1919

2020
echo "Memory limit for HAProxy: ${MEMLIMIT}MiB"
2121

22-
exec /usr/local/sbin/haproxy -W -db -m "${MEMLIMIT}" -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy-aux.cfg
22+
exec /usr/local/sbin/haproxy -W -db -m "${MEMLIMIT}" -S /var/run/haproxy-master.sock,level,admin -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy-aux.cfg

fs/var/lib/pebble/default/run-haproxy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ fi
1919

2020
echo "Memory limit for HAProxy: ${MEMLIMIT}MiB"
2121

22-
exec /usr/local/sbin/haproxy -W -db -m "${MEMLIMIT}" -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy-aux.cfg
22+
exec /usr/local/sbin/haproxy -W -db -m "${MEMLIMIT}" -S /var/run/haproxy-master.sock,level,admin -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/haproxy-aux.cfg

pkg/haproxy/env/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Env struct {
3131
Proxies
3232
CfgDir string
3333
RuntimeSocket string
34+
MasterSocket string
3435
PIDFile string
3536
AuxCFGFile string
3637
RuntimeDir string
@@ -67,9 +68,11 @@ func (env *Env) Init(osArgs utils.OSArgs) (err error) {
6768
env.AuxCFGFile = filepath.Join(env.CfgDir, "haproxy-aux.cfg")
6869
env.PIDFile = filepath.Join(env.RuntimeDir, "haproxy.pid")
6970
env.RuntimeSocket = filepath.Join(env.RuntimeDir, "haproxy-runtime-api.sock")
71+
env.MasterSocket = filepath.Join(env.RuntimeDir, "haproxy-master.sock")
7072
if osArgs.Test {
7173
env.Binary = "echo"
7274
env.RuntimeSocket = ""
75+
env.MasterSocket = ""
7376
} else if _, err = os.Stat(env.Binary); err != nil {
7477
return err
7578
}

pkg/haproxy/process/direct-control.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ func (d *directControl) Service(action string) (err error) {
2929
// hold information about a running Master HAproxy process
3030
process, processErr := haproxyProcess(d.Env.PIDFile)
3131

32+
masterSocketArg := fmt.Sprintf("%s,level,admin", d.Env.MasterSocket)
33+
3234
//nolint:gosec //checks on HAProxyBinary should be done in configuration module.
3335
switch action {
3436
case "start":
3537
if processErr == nil {
3638
logger.Error("haproxy is already running")
3739
return nil
3840
}
39-
cmd = exec.Command(d.Env.Binary, "-f", d.Env.MainCFGFile)
41+
cmd = exec.Command(d.Env.Binary, "-S", masterSocketArg, "-f", d.Env.MainCFGFile)
4042
if d.useAuxFile {
41-
cmd = exec.Command(d.Env.Binary, "-f", d.Env.MainCFGFile, "-f", d.Env.AuxCFGFile)
43+
cmd = exec.Command(d.Env.Binary, "-S", masterSocketArg, "-f", d.Env.MainCFGFile, "-f", d.Env.AuxCFGFile)
4244
}
4345
cmd.Stdout = os.Stdout
4446
cmd.Stderr = os.Stderr
@@ -65,9 +67,9 @@ func (d *directControl) Service(action string) (err error) {
6567
return d.Service("start")
6668
}
6769
pid := strconv.Itoa(process.Pid)
68-
cmd = exec.Command(d.Env.Binary, "-f", d.Env.MainCFGFile, "-sf", pid)
70+
cmd = exec.Command(d.Env.Binary, "-S", masterSocketArg, "-f", d.Env.MainCFGFile, "-sf", pid)
6971
if d.useAuxFile {
70-
cmd = exec.Command(d.Env.Binary, "-f", d.Env.MainCFGFile, "-f", d.Env.AuxCFGFile, "-sf", pid)
72+
cmd = exec.Command(d.Env.Binary, "-S", masterSocketArg, "-f", d.Env.MainCFGFile, "-f", d.Env.AuxCFGFile, "-sf", pid)
7173
}
7274
cmd.Stdout = os.Stdout
7375
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)