Skip to content

Commit

Permalink
26377 - ingress-nginx 0.30.0, modify ingress-nginx to work with new u…
Browse files Browse the repository at this point in the history
…pstream build process, apply rancher specific code changes
  • Loading branch information
ryansann committed May 7, 2020
1 parent f1f90ef commit f327746
Show file tree
Hide file tree
Showing 14 changed files with 277 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 @@ -53,3 +53,7 @@ build/images/nginx/aws.tfvars
build/images/nginx/env.tfvars

images/fastcgi-helloserver/rootfs/fastcgi-helloserver

# 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)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
Expand Down Expand Up @@ -507,6 +508,7 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -863,6 +865,7 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
Expand Down
14 changes: 14 additions & 0 deletions internal/k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 @@ -62,6 +67,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}
19 changes: 19 additions & 0 deletions scripts/validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -e

cd $(dirname $0)/..

echo Running validation

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

PACKAGES="$($FIND_COMMAND -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin|docs|images|examples|hack)' | sed -e 's!^!./!' -e 's!$!/...!')"

echo Running: go vet
go vet ${PACKAGES}

echo Running: go fmt
test -z "$(go fmt ${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 f327746

Please sign in to comment.