ingress-nginx-helm/build/dev-env.sh

128 lines
3.4 KiB
Bash
Raw Normal View History

2018-04-24 20:29:31 +00:00
#!/bin/bash
# Copyright 2018 The Kubernetes Authors.
#
# 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.
2019-06-28 21:40:18 +00:00
if [ -n "$DEBUG" ]; then
set -x
fi
2018-07-06 03:23:27 +00:00
set -o errexit
set -o nounset
set -o pipefail
2018-04-24 20:29:31 +00:00
DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
2020-02-17 10:13:13 +00:00
export TAG=1.0.0-dev
2018-07-06 03:23:27 +00:00
export REGISTRY=${REGISTRY:-ingress-controller}
2020-07-08 21:56:50 +00:00
DEV_IMAGE=${REGISTRY}/controller:${TAG}
2018-04-24 20:29:31 +00:00
2020-02-13 00:17:26 +00:00
if ! command -v kind &> /dev/null; then
echo "kind is not installed"
2020-02-19 16:49:02 +00:00
echo "Use a package manager (i.e 'brew install kind') or visit the official site https://kind.sigs.k8s.io"
2020-02-13 00:17:26 +00:00
exit 1
fi
if ! command -v kubectl &> /dev/null; then
echo "Please install kubectl 1.15 or higher"
exit 1
fi
2020-02-19 16:49:02 +00:00
if ! command -v helm &> /dev/null; then
echo "Please install helm"
exit 1
fi
2020-06-25 08:51:35 +00:00
HELM_VERSION=$(helm version 2>&1 | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+') || true
if [[ ${HELM_VERSION} < "v3.0.0" ]]; then
echo "Please upgrade helm to v3.0.0 or higher"
exit 1
fi
KUBE_CLIENT_VERSION=$(kubectl version --client --short | awk '{print $3}' | cut -d. -f2) || true
if [[ ${KUBE_CLIENT_VERSION} -lt 14 ]]; then
2020-02-13 00:17:26 +00:00
echo "Please update kubectl to 1.15 or higher"
exit 1
fi
2018-07-06 03:23:27 +00:00
2020-05-31 16:53:57 +00:00
echo "[dev-env] building image"
make build image
2020-07-08 21:56:50 +00:00
docker tag "${REGISTRY}/controller:${TAG}" "${DEV_IMAGE}"
2018-04-24 20:29:31 +00:00
Support cors-allow-origin with multiple origins (#7614) * Add Initial support for multiple cors origins in nginx - bump cluster version for `make dev-env` - add buildOriginRegex function in nginx.tmpl - add e2e 4 e2e tests for cors.go - refers to feature request #5496 * add tests + use search to identify '*' origin * add tests + use search to identify '*' origin Signed-off-by: Christopher Larivière <lariviere.c@gmail.com> * fix "should enable cors test" looking at improper values * Modify tests and add some logic for origin validation - add origin validation in cors ingress annotations - add extra tests to validate regex - properly escape regex using "QuoteMeta" - fix some copy/paste errors * add TrimSpace and length validation before adding a new origin * modify documentation for cors and remove dangling comment * add support for optional port mapping on origin * support single-level wildcard subdomains + tests * Remove automatic `*` fonctionality from incorrect origins - use []string instead of basic string to avoid reparsing in template.go - fix typo in docs - modify template to properly enable only if the whole block is enabled - modify cors parsing - test properly by validating that the value returned is the proper origin - update unit tests and annotation tests * Re-add `*` when no cors origins are supplied + fix tests - fix e2e tests to allow for `*` - re-add `*` to cors parsing if trimmed cors-allow-origin is empty (supplied but empty) and if it wasn't supplied at all. * remove unecessary logic for building cors origin + remove comments - add some edge cases in e2e tests - rework logic for building cors origin there was no need for logic in template.go for buildCorsOriginRegex if there is a `*` it ill be short-circuited by first if. if it's a wildcard domain or any domain (without a wildcard), it MUST match the main/cors.go regex format. if there's a star in a wildcard domain, it must be replaced with `[A-Za-z0-9]+` * add missing check in e2e tests
2021-11-02 19:31:42 +00:00
export K8S_VERSION=${K8S_VERSION:-v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6}
KIND_CLUSTER_NAME="ingress-nginx-dev"
if ! kind get clusters -q | grep -q ${KIND_CLUSTER_NAME}; then
echo "[dev-env] creating Kubernetes cluster with kind"
cat <<EOF | kind create cluster --name ${KIND_CLUSTER_NAME} --image "kindest/node:${K8S_VERSION}" --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
authorization-mode: "AlwaysAllow"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
else
echo "[dev-env] using existing Kubernetes kind cluster"
2019-07-08 20:43:34 +00:00
fi
echo "[dev-env] copying docker images to cluster..."
kind load docker-image --name="${KIND_CLUSTER_NAME}" "${DEV_IMAGE}"
echo "[dev-env] deploying NGINX Ingress controller..."
kubectl create namespace ingress-nginx &> /dev/null || true
2020-02-17 10:13:13 +00:00
cat << EOF | helm template ingress-nginx ${DIR}/../charts/ingress-nginx --namespace=ingress-nginx --values - | kubectl apply -n ingress-nginx -f -
2020-02-17 10:13:13 +00:00
controller:
image:
2020-07-08 21:56:50 +00:00
repository: ${REGISTRY}/controller
2020-02-17 10:13:13 +00:00
tag: ${TAG}
2020-07-13 18:22:06 +00:00
digest:
2020-02-17 10:13:13 +00:00
config:
worker-processes: "1"
podLabels:
deploy-date: "$(date +%s)"
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
hostPort:
enabled: true
terminationGracePeriodSeconds: 0
service:
type: NodePort
2020-02-17 10:13:13 +00:00
EOF
cat <<EOF
2019-07-08 20:43:34 +00:00
Kubernetes cluster ready and ingress-nginx listening in localhost using ports 80 and 443
2018-04-24 20:29:31 +00:00
To delete the dev cluster execute: 'kind delete cluster --name ingress-nginx-dev'
EOF