diff --git a/docs/examples/customization/custom-errors/custom-default-backend.yaml b/docs/examples/customization/custom-errors/custom-default-backend.yaml index c5d145985..cc97c8c1f 100644 --- a/docs/examples/customization/custom-errors/custom-default-backend.yaml +++ b/docs/examples/customization/custom-errors/custom-default-backend.yaml @@ -30,6 +30,11 @@ spec: spec: containers: - name: nginx-error-server - image: quay.io/kubernetes-ingress-controller/custom-error-pages-amd64:0.2 + image: quay.io/kubernetes-ingress-controller/custom-error-pages-amd64:0.3 ports: - containerPort: 8080 + # Setting the environment variable DEBUG we can see the headers sent + # by the ingress controller to the backend in the client response. + # env: + # - name: DEBUG + # value: "true" diff --git a/images/custom-error-pages/Makefile b/images/custom-error-pages/Makefile index 22ebb16ef..0fd5f7328 100644 --- a/images/custom-error-pages/Makefile +++ b/images/custom-error-pages/Makefile @@ -3,7 +3,7 @@ all: all-container BUILDTAGS= # Use the 0.0 tag for testing, it shouldn't clobber any release builds -TAG?=0.2 +TAG?=0.3 REGISTRY?=quay.io/kubernetes-ingress-controller GOOS?=linux DOCKER?=docker @@ -26,11 +26,11 @@ ARCH ?= $(shell go env GOARCH) GOARCH = ${ARCH} DUMB_ARCH = ${ARCH} -BASEIMAGE?=alpine:3.6 +BASEIMAGE?=alpine:3.7 ALL_ARCH = amd64 arm arm64 ppc64le -QEMUVERSION=v2.9.1 +QEMUVERSION=v2.12.0 IMGNAME = custom-error-pages IMAGE = $(REGISTRY)/$(IMGNAME) @@ -74,7 +74,7 @@ ifeq ($(ARCH),amd64) else # When cross-building, only the placeholder "CROSS_BUILD_" should be removed # Register /usr/bin/qemu-ARCH-static as the handler for ARM binaries in the kernel - $(DOCKER) run --rm --privileged multiarch/qemu-user-static:register --reset + # $(DOCKER) run --rm --privileged multiarch/qemu-user-static:register --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)/rootfs $(SED_I) "s/CROSS_BUILD_//g" $(DOCKERFILE) endif @@ -103,3 +103,8 @@ build: clean release: all-container all-push echo "done" + +.PHONY: register-qemu +register-qemu: + # Register /usr/bin/qemu-ARCH-static as the handler for binaries in multiple platforms + $(DOCKER) run --rm --privileged multiarch/qemu-user-static:register --reset diff --git a/images/custom-error-pages/main.go b/images/custom-error-pages/main.go index 2d42eda88..e4f1ccb23 100644 --- a/images/custom-error-pages/main.go +++ b/images/custom-error-pages/main.go @@ -40,6 +40,21 @@ const ( // ContentType name of the header that defines the format of the reply ContentType = "Content-Type" + // OriginalURI name of the header with the original URL from NGINX + OriginalURI = "X-Original-URI" + + // Namespace name of the header that contains information about the Ingress namespace + Namespace = "X-Namespace" + + // IngressName name of the header that contains the matched Ingress + IngressName = "X-Ingress-Name" + + // ServiceName name of the header that contains the matched Service in the Ingress + ServiceName = "X-Service-Name" + + // ServicePort name of the header that contains the matched Service port in the Ingress + ServicePort = "X-Service-Port" + // ErrFilesPathVar is the name of the environment variable indicating // the location on disk of files served by the handler. ErrFilesPathVar = "ERROR_FILES_PATH" @@ -67,6 +82,17 @@ func errorHandler(path string) func(http.ResponseWriter, *http.Request) { start := time.Now() ext := "html" + if os.Getenv("DEBUG") != "" { + w.Header().Set(FormatHeader, r.Header.Get(FormatHeader)) + w.Header().Set(CodeHeader, r.Header.Get(CodeHeader)) + w.Header().Set(ContentType, r.Header.Get(ContentType)) + w.Header().Set(OriginalURI, r.Header.Get(OriginalURI)) + w.Header().Set(Namespace, r.Header.Get(Namespace)) + w.Header().Set(IngressName, r.Header.Get(IngressName)) + w.Header().Set(ServiceName, r.Header.Get(ServiceName)) + w.Header().Set(ServicePort, r.Header.Get(ServicePort)) + } + format := r.Header.Get(FormatHeader) if format == "" { format = "text/html"