Commit 073b11f3 authored by Adam Reese's avatar Adam Reese
Browse files

Merge pull request #541 from adamreese/feat/e2e-test

feat(e2e): add script for local kubernetes cluster
parents 2150fc92 179c0d4d
main Release add-codeql dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible dependabot/go_modules/github.com/lib/pq-1.10.9 dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0 dependabot/go_modules/golang.org/x/crypto-0.9.0 dependabot/go_modules/golang.org/x/term-0.8.0 dependabot/go_modules/k8s.io/klog/v2-2.100.1 dev-v2 feat-v3/event-emitter-lua kube-update-test release-2.0 release-2.1 release-2.10 release-2.11 release-2.12 release-2.13 release-2.14 release-2.15 release-2.16 release-2.17 release-2.2 release-2.3 release-2.4 release-2.5 release-2.6 release-2.7 release-2.8 release-2.9 release-3.0 release-3.1 release-3.10 release-3.11 release-3.12 release-3.2 release-3.3 release-3.4 release-3.5 release-3.6 release-3.6.1 release-3.6.2 release-3.7 release-3.8 release-3.9 release-v3.0.0-beta.4 1.999.0 v3.12.0 v3.12.0-rc.1 v3.12.0-dev.1 v3.11.3 v3.11.2 v3.11.1 v3.11.0 v3.11.0-rc.2 v3.11.0-rc.1 v3.10.3 v3.10.2 v3.10.1 v3.10.0 v3.10.0-rc.1 v3.9.4 v3.9.3 v3.9.2 v3.9.1 v3.9.0 v3.9.0-rc.1 v3.8.2 v3.8.1 v3.8.0 v3.8.0-rc.2 v3.8.0-rc.1 v3.7.2 v3.7.1 v3.7.0 v3.7.0-rc.3 v3.7.0-rc.2 v3.7.0-rc.1 v3.6.3 v3.6.2 v3.6.1 v3.6.0 v3.6.0-rc.1 v3.5.4 v3.5.3 v3.5.2 v3.5.1 v3.5.0 v3.5.0-rc.2 v3.5.0-rc.1 v3.4.2 v3.4.1 v3.4.0 v3.4.0-rc.1 v3.3.4 v3.3.3 v3.3.2 v3.3.1 v3.3.0 v3.3.0-rc.2 v3.3.0-rc.1 v3.2.4 v3.2.3 v3.2.2 v3.2.1 v3.2.0 v3.2.0-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ha.4 v2.0.0-alpha.3 v2.0.0-alpha.2 v2.0.0-alpha.1
No related merge requests found
Showing with 309 additions and 0 deletions
+309 -0
...@@ -16,3 +16,4 @@ nohup.out ...@@ -16,3 +16,4 @@ nohup.out
/rootfs/expandybird/opt/expansion /rootfs/expandybird/opt/expansion
.DS_Store .DS_Store
/log/ /log/
/scripts/env.sh
...@@ -27,6 +27,10 @@ error_exit() { ...@@ -27,6 +27,10 @@ error_exit() {
exit 1 exit 1
} }
is_osx() {
[[ "$(uname)" == "Darwin" ]]
}
assign_version() { assign_version() {
if [[ -z "${VERSION:-}" ]]; then if [[ -z "${VERSION:-}" ]]; then
VERSION=$(version_from_git) VERSION=$(version_from_git)
......
#!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# 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.
set -eo pipefail
DOCKER_HOST_IP=$(echo $DOCKER_HOST | awk -F'[/:]' '{print $4}')
: ${DOCKER_HOST_IP:=$(ifconfig docker0 \
| grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' \
| grep -Eo '([0-9]*\.){3}[0-9]*')}
is_docker_machine() {
[[ $(docker-machine active 2>/dev/null) ]]
}
active_docker_machine() {
if command -v docker-machine >/dev/null 2>&1; then
docker-machine active
fi
}
dev_registry() {
if docker inspect registry >/dev/null 2>&1; then
docker start registry
else
docker run --restart="always" -d -p 5000:5000 --name registry registry:2
fi
}
#!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# 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.
# Tear down kubernetes in docker
set -eo pipefail
[[ "$TRACE" ]] && set -x
HELM_ROOT="${BASH_SOURCE[0]%/*}/.."
source "${HELM_ROOT}/scripts/common.sh"
source "${HELM_ROOT}/scripts/docker.sh"
KUBE_PORT=${KUBE_PORT:-8080}
KUBE_HOST=${KUBE_HOST:-$DOCKER_HOST_IP}
KUBE_HOST=${KUBE_HOST:-localhost}
KUBECTL="kubectl -s ${KUBE_HOST}:${KUBE_PORT}"
delete_kube_resources() {
echo "Deleting resources in kubernetes..."
$KUBECTL delete replicationcontrollers,services,pods,secrets --all > /dev/null 2>&1 || :
$KUBECTL delete replicationcontrollers,services,pods,secrets --all --namespace=kube-system > /dev/null 2>&1 || :
$KUBECTL delete namespace kube-system > /dev/null 2>&1 || :
}
delete_hyperkube_containers() {
echo "Stopping main kubelet..."
docker stop helm_kubelet > /dev/null 2>&1 || true
docker rm --force --volumes helm_kubelet > /dev/null 2>&1 || true
echo "Stopping remaining kubernetes containers..."
local kube_containers=$(docker ps -aqf "name=k8s_")
if [ ! -z "$kube_containers" ]; then
docker stop $kube_containers > /dev/null 2>&1
docker wait $kube_containers > /dev/null 2>&1
docker rm --force --volumes $kube_containers > /dev/null 2>&1
fi
}
main() {
echo "Bringing down the kube..."
delete_kube_resources
delete_hyperkube_containers
echo "done."
}
main "$@"
exit 0
#!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# 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.
# Start a kubenetes cluster in docker
#
# Tested on darwin using docker-machine and linux
set -eo pipefail
[[ "$TRACE" ]] && set -x
HELM_ROOT="${BASH_SOURCE[0]%/*}/.."
source "${HELM_ROOT}/scripts/common.sh"
source "${HELM_ROOT}/scripts/docker.sh"
K8S_VERSION=${K8S_VERSION:-1.2.0}
KUBE_PORT=${KUBE_PORT:-8080}
KUBE_HOST=${KUBE_HOST:-$DOCKER_HOST_IP}
KUBE_HOST=${KUBE_HOST:-localhost}
KUBECTL="kubectl -s ${KUBE_HOST}:${KUBE_PORT}"
require_command() {
if ! command -v "$1" >/dev/null 2>&1; then
error_exit "Cannot find command ${1}"
fi
}
verify_prereqs() {
echo "Verifying Prerequisites...."
require_command docker
require_command kubectl
if is_osx; then
require_command docker-machine
fi
if ! docker info > /dev/null 2>&1 ; then
error_exit "Can't connect to 'docker' daemon. please fix and retry."
fi
echo "You are golden, carry on..."
}
setup_iptables() {
local machine=$(active_docker_machine)
if [ -z "$machine" ]; then
return
fi
echo "Adding iptables hackery for docker-machine..."
local machine_ip=$(docker-machine ip "$machine")
if ! docker-machine ssh "${machine}" "sudo /usr/local/sbin/iptables -t nat -L -n" | grep -q "${machine_ip}" | grep -q ":${KUBE_PORT}"; then
docker-machine ssh "${machine}" "sudo /usr/local/sbin/iptables -t nat -I PREROUTING -p tcp -d ${machine_ip} --dport ${KUBE_PORT} -j DNAT --to-destination 127.0.0.1:${KUBE_PORT}"
fi
}
start_kubernetes() {
echo "Getting the party going..."
#if docker ps --filter "name=helm_kubelet" >/dev/null; then
#error_exit "Kubernetes already running"
#fi
docker run \
--name=helm_kubelet \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:rw \
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
--pid=host \
--privileged=true \
-d \
gcr.io/google_containers/hyperkube-amd64:v${K8S_VERSION} \
/hyperkube kubelet \
--containerized \
--hostname-override="127.0.0.1" \
--address="0.0.0.0" \
--api-servers="http://localhost:${KUBE_PORT}" \
--config=/etc/kubernetes/manifests \
--cluster-dns=10.0.0.10 \
--cluster-domain=cluster.local \
--allow-privileged=true --v=2
}
wait_for_kubernetes() {
echo "Waiting for Kubernetes cluster to become available..."
until $($KUBECTL cluster-info &> /dev/null); do
sleep 1
done
echo "Kubernetes cluster is up."
}
create_kube_system_namespace() {
echo "Creating kube-system namespace..."
$KUBECTL create -f - << EOF
kind: Namespace
apiVersion: v1
metadata:
name: kube-system
labels:
name: kube-system
EOF
}
create_kube_dns() {
echo "Setting up internal dns..."
$KUBECTL --namespace=kube-system create -f - <<EOF
apiVersion: v1
kind: Endpoints
metadata:
name: kube-dns
namespace: kube-system
subsets:
- addresses:
- ip: $DOCKER_HOST_IP
ports:
- port: 53
protocol: UDP
name: dns
---
kind: Service
apiVersion: v1
metadata:
name: kube-dns
namespace: kube-system
spec:
clusterIP: 10.0.0.10
ports:
- name: dns
port: 53
protocol: UDP
EOF
}
main() {
verify_prereqs
if is_docker_machine; then
setup_iptables
fi
start_kubernetes
wait_for_kubernetes
create_kube_system_namespace
create_kube_dns
$KUBECTL cluster-info
}
main "$@"
exit 0
#!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# 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.
set -eo pipefail
[[ "$TRACE" ]] && set -x
HELM_ROOT="${BASH_SOURCE[0]%/*}/.."
source "${HELM_ROOT}/scripts/common.sh"
source "${HELM_ROOT}/scripts/docker.sh"
KUBE_PORT=${KUBE_PORT:-8080}
KUBE_HOST=${KUBE_HOST:-localhost}
if is_docker_machine; then
KUBE_HOST=$(docker-machine ip "$(active_docker_machine)")
fi
kubectl -s ${KUBE_HOST}:${KUBE_PORT} "$@"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment