Skip to content

Commit

Permalink
Merge pull request kubernetes#32 from ryansann/nginx-0.32.x-fix
Browse files Browse the repository at this point in the history
Nginx 0.32.x fix
  • Loading branch information
ryansann authored May 12, 2020
2 parents 4468451 + d359bb1 commit 29dd976
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
kind: pipeline
name: ci

platform:
os: linux
arch: amd64

steps:
- name: build
image: rancher/dapper:v0.4.1
commands:
- dapper ci
environment:
GIT_IN_DAPPER: true
volumes:
- name: docker
path: /var/run/docker.sock

- name: publish
image: docker
commands:
- docker login -u $USERNAME -p $PASSWORD
- "docker tag rancher/nginx-ingress-controller-amd64:${DRONE_TAG} rancher/nginx-ingress-controller:${DRONE_TAG}-amd64"
- "docker push rancher/nginx-ingress-controller:${DRONE_TAG}-amd64"
- "docker tag rancher/nginx-ingress-controller-arm64:${DRONE_TAG} rancher/nginx-ingress-controller:${DRONE_TAG}-arm64"
- "docker push rancher/nginx-ingress-controller:${DRONE_TAG}-arm64"
environment:
PASSWORD:
from_secret: docker_password
USERNAME:
from_secret: docker_username
volumes:
- name: docker
path: /var/run/docker.sock
when:
event:
- tag
instance:
- drone-publish.rancher.io

volumes:
- name: docker
host:
path: /var/run/docker.sock

node:
docker_version: 19.03

---
kind: pipeline
name: manifest

platform:
os: linux
arch: amd64

steps:
- name: push-manifest
image: plugins/manifest:1.0.2
settings:
password:
from_secret: docker_password
platforms:
- linux/amd64
- linux/arm64
target: "rancher/nginx-ingress-controller:${DRONE_TAG}"
template: "rancher/nginx-ingress-controller:${DRONE_TAG}-ARCH"
username:
from_secret: docker_username
when:
event:
- tag
instance:
- drone-publish.rancher.io

depends_on:
- ci
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ images/fastcgi-helloserver/rootfs/fastcgi-helloserver
cmd/plugin/release/ingress-nginx.yaml
cmd/plugin/release/*.tar.gz
cmd/plugin/release/LICENSE

# rancher ci
.dapper
/dist/
39 changes: 39 additions & 0 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM docker:19.03.8
ARG DAPPER_HOST_ARCH
ENV ARCH=${DAPPER_HOST_ARCH}
RUN mkdir -p /.docker/cli-plugins
RUN apk update && apk upgrade && apk add bash && ln -sf /bin/bash /bin/sh # use bash for subsequent variable expansion
ENV DOCKER_BUILDX_URL_arm=https://github.com/docker/buildx/releases/download/v0.3.1/buildx-v0.3.1.linux-arm-v7 \
DOCKER_BUILDX_URL_arm64=https://github.com/docker/buildx/releases/download/v0.3.1/buildx-v0.3.1.linux-arm64 \
DOCKER_BUILDX_URL_amd64=https://github.com/docker/buildx/releases/download/v0.3.1/buildx-v0.3.1.linux-amd64 \
DOCKER_BUILDX_URL=DOCKER_BUILDX_URL_${ARCH}
RUN wget -O - ${!DOCKER_BUILDX_URL} > /.docker/cli-plugins/docker-buildx && chmod +x /.docker/cli-plugins/docker-buildx

FROM ubuntu:18.04
ARG DAPPER_HOST_ARCH
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
RUN apt-get update && \
apt-get install -y gcc ca-certificates git wget curl vim less file zip make && \
rm -f /bin/sh && ln -s /bin/bash /bin/sh
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm=armv6l GOLANG_ARCH_arm64=arm64 GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash
RUN wget -O - https://dl.google.com/go/go1.14.1.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local && \
go get github.com/rancher/trash && go get golang.org/x/lint/golint && go get -u github.com/jteeuwen/go-bindata/...
COPY --from=0 /usr/local/bin/docker /usr/bin/docker
RUN mkdir -p /.docker/cli-plugins
COPY --from=0 /.docker/cli-plugins/docker-buildx /.docker/cli-plugins/docker-buildx
ENV DOCKER_CLI_EXPERIMENTAL=enabled \
DOCKER_CONFIG=/.docker
RUN docker buildx install
ENV DAPPER_SOURCE /go/src/k8s.io/ingress-nginx/
ENV DAPPER_OUTPUT ./bin ./dist
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_ENV CROSS TAG
ENV DAPPER_RUN_ARGS="--net host"
ENV TRASH_CACHE ${DAPPER_SOURCE}/.trash-cache
ENV HOME ${DAPPER_SOURCE}
ENV GIT_IN_DAPPER true
RUN mkdir -p /etc/nginx/geoip
WORKDIR ${DAPPER_SOURCE}
ENTRYPOINT ["./scripts/entry"]
CMD ["ci"]
23 changes: 23 additions & 0 deletions Makefile_rancher
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TARGETS := $(shell ls scripts)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m` > .dapper.tmp
@@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper

$(TARGETS): .dapper
./.dapper $@

trash: .dapper
./.dapper -m bind trash

trash-keep: .dapper
./.dapper -m bind trash -k

deps: trash

.DEFAULT_GOAL := ci

.PHONY: $(TARGETS)
14 changes: 14 additions & 0 deletions internal/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import (
"k8s.io/client-go/tools/cache"
)

const (
internalAddressAnnotation = "rke.cattle.io/internal-ip"
externalAddressAnnotation = "rke.cattle.io/external-ip"
)

// ParseNameNS parses a string searching a namespace and name
func ParseNameNS(input string) (string, string, error) {
nsName := strings.Split(input, "/")
Expand Down Expand Up @@ -64,6 +69,15 @@ func GetNodeIPOrName(kubeClient clientset.Interface, name string, useInternalIP
return defaultOrInternalIP
}

if node.Annotations != nil {
if annotatedIP := node.Annotations[externalAddressAnnotation]; annotatedIP != "" {
return annotatedIP
}
if annotatedIP := node.Annotations[internalAddressAnnotation]; annotatedIP != "" {
return annotatedIP
}
}

for _, address := range node.Status.Addresses {
if address.Type == apiv1.NodeExternalIP {
if address.Address != "" {
Expand Down
17 changes: 17 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

source $(dirname $0)/version

cd $(dirname $0)/..

PKG="k8s.io/ingress-nginx"

rm -rf bin/*
mkdir -p bin

declare -a arches=("arm64" "amd64")
for arch in "${arches[@]}"
do
ARCH=$arch USE_DOCKER=false make build
done
9 changes: 9 additions & 0 deletions scripts/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

cd $(dirname $0)

./validate
./build
./test
./package
11 changes: 11 additions & 0 deletions scripts/entry
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

mkdir -p bin dist
if [ -e ./scripts/$1 ]; then
./scripts/"$@"
else
exec "$@"
fi

chown -R $DAPPER_UID:$DAPPER_GID .
11 changes: 11 additions & 0 deletions scripts/package
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

REPO=${REPO:-rancher}

source $(dirname $0)/version
cd $(dirname $0)/..

for arch in $(ls bin); do
REGISTRY=${REPO} ARCH=${arch} TAG=${TAG} make container
done
3 changes: 3 additions & 0 deletions scripts/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec $(dirname $0)/ci
15 changes: 15 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

cd $(dirname $0)/..

echo Running tests

FIND_COMMAND="find"
if [ "$(go env GOHOSTOS)" = "darwin" ]; then
FIND_COMMAND="find ."
fi

PACKAGES="$($FIND_COMMAND -name '*.go' | xargs -I{} dirname {} | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin|docs|test|controller/store|images|examples|hack)')"

go test -v -p 1 -tags "cgo" -cover ${PACKAGES}
14 changes: 14 additions & 0 deletions scripts/validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

cd $(dirname $0)/..

echo Running validation

PACKAGES="$(go list ./... | grep -v /vendor/)"

echo Running: go vet
go vet -mod=readonly ${PACKAGES}

echo Running: go fmt
test -z "$(go fmt -mod=readonly ${PACKAGES} | tee /dev/stderr)"
31 changes: 31 additions & 0 deletions scripts/version
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [ "$GIT_IN_DAPPER" = true ]; then
git config --global user.email "rancher-ci@rancher.com"
git config --global user.name "rancher-ci"
fi

if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
DIRTY="-dirty"
fi

# fetch tag information
git fetch

GIT_COMMIT=${GIT_COMMIT:-$(git rev-parse --short HEAD)}
GIT_TAG=$(git tag -l --contains HEAD | head -n 1)
REPO_INFO=$(git config --get remote.origin.url)

if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then
VERSION=$GIT_TAG
else
VERSION="${GIT_COMMIT}${DIRTY}"
fi

if [ -z "$ARCH" ]; then
ARCH=amd64
fi

TAG=${TAG:-$VERSION}

PKG="k8s.io/ingress-nginx"

0 comments on commit 29dd976

Please sign in to comment.