Adding wildcard support (#190)

* Commenting out unused functions. TODO: remove when it is not needed

* Update README with namespace and template example

* Adding note about changing the record name format via a template

* Adding test scripts to automate k8s startup

* Automating k8s namespace creation

* Adding automation to start 4 k8s services

* Updating documentation for k8s tests

* Avoid downloading kubectl if already exists

* Adding debug statement when namespace is not exposed.

* Adding basic kubernetes integration tests

* Makefile now contains a "testk8s" target. This target requires k8s to
  be running.
* Adding test/kubernetes_test.go file with a couple of basic A record
  tests.

* Updating k8s integration tests to only run k8s integration tests

* Adding support for namespace wildcards

* Refactoring to move filtering logic to kubernetes.go file

* go fmt fixes

* Adding wildcard support for namespaces and service names

* Kubernetes integration tests updated for A records.
* Expanded record name assembly for answer section not yet implemented.
* Refactoring to focus k8sclient code just on accessing k8s API.
 Filtering now handled in kubernetes.go

* Adding wildcard test cases

* Adding skydns startup script. (To allow side by side testing of wildcards.)
* Commenting out record name assmebly based on NameTemplate. Need to improve template before this makes sense.

* Adding basic SRV integration tests

* Need to add verification for additional answer section

* Fixing comments and formatting

* Moving wildcard constants to vars

* Travis test execution appears to be failing on access to these
 constants

* Fixing access to util package

* Trying to work around Travis test bug

* Reverting to access kubernetes/util as "util"

Travis breakage is due to "Infoblox-CTO" in src path
This commit is contained in:
Michael Richmond
2016-07-14 14:50:14 -07:00
committed by Miek Gieben
parent 319d30697a
commit 3f4ec783d2
17 changed files with 527 additions and 67 deletions

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Based on instructions at: http://kubernetes.io/docs/getting-started-guides/docker/
#K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/latest.txt)
K8S_VERSION="v1.2.4"
ARCH="amd64"
export K8S_VERSION
export ARCH
#RUN_SKYDNS="yes"
RUN_SKYDNS="no"
if [ "${RUN_SKYDNS}" = "yes" ]; then
DNS_ARGUMENTS="--cluster-dns=10.0.0.10 --cluster-domain=cluster.local"
else
DNS_ARGUMENTS=""
fi
docker run -d \
--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 \
gcr.io/google_containers/hyperkube-${ARCH}:${K8S_VERSION} \
/hyperkube kubelet \
--containerized \
--hostname-override=127.0.0.1 \
--api-servers=http://localhost:8080 \
--config=/etc/kubernetes/manifests \
${DNS_ARGUMENTS} \
--allow-privileged --v=2

View File

@@ -0,0 +1,18 @@
#!/bin/bash
PWD=`pwd`
BASEDIR=`realpath $(dirname ${0})`
cd ${BASEDIR}
if [ ! -e kubectl ]; then
curl -O http://storage.googleapis.com/kubernetes-release/release/v1.2.4/bin/linux/amd64/kubectl
chmod u+x kubectl
fi
${BASEDIR}/kubectl config set-cluster test-doc --server=http://localhost:8080
${BASEDIR}/kubectl config set-context test-doc --cluster=test-doc
${BASEDIR}/kubectl config use-context test-doc
cd ${PWD}
alias kubctl="${BASEDIR}/kubectl"

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# Running skydns based on instructions at: https://testdatamanagement.wordpress.com/2015/09/01/running-kubernetes-in-docker-with-dns-on-a-single-node/
KUBECTL='./kubectl'
#RUN_SKYDNS="yes"
RUN_SKYDNS="no"
wait_until_k8s_ready() {
# Wait until kubernetes is up and fully responsive
while :
do
${KUBECTL} get nodes 2>/dev/null | grep -q '127.0.0.1'
if [ "${?}" = "0" ]; then
break
else
echo "sleeping for 5 seconds"
sleep 5
fi
done
echo "kubernetes nodes:"
${KUBECTL} get nodes
}
if [ "${RUN_SKYDNS}" = "yes" ]; then
wait_until_k8s_ready
echo "Launch kube2sky..."
docker run -d --net=host gcr.io/google_containers/kube2sky:1.11 --kube_master_url=http://127.0.0.1:8080 --domain=cluster.local
echo ""
echo "Launch SkyDNS..."
docker run -d --net=host gcr.io/google_containers/skydns:2015-03-11-001 --machines=http://localhost:4001 --addr=0.0.0.0:53 --domain=cluster.local
else
true
fi

View File

@@ -0,0 +1,80 @@
#!/bin/bash
KUBECTL='./kubectl'
wait_until_k8s_ready() {
# Wait until kubernetes is up and fully responsive
while :
do
${KUBECTL} get nodes 2>/dev/null | grep -q '127.0.0.1'
if [ "${?}" = "0" ]; then
break
else
echo "sleeping for 5 seconds"
sleep 5
fi
done
echo "kubernetes nodes:"
${KUBECTL} get nodes
}
create_namespaces() {
for n in ${NAMESPACES};
do
echo "Creating namespace: ${n}"
${KUBECTL} get namespaces --no-headers 2>/dev/null | grep -q ${n}
if [ "${?}" != "0" ]; then
${KUBECTL} create namespace ${n}
fi
done
echo "kubernetes namespaces:"
${KUBECTL} get namespaces
}
# run_and_expose_service <servicename> <namespace> <image> <port>
run_and_expose_service() {
if [ "${#}" != "4" ]; then
return -1
fi
service="${1}"
namespace="${2}"
image="${3}"
port="${4}"
echo " starting service '${service}' in namespace '${namespace}"
${KUBECTL} get deployment --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service}
if [ "${?}" != "0" ]; then
${KUBECTL} run ${service} --namespace=${namespace} --image=${image}
else
echo "warn: service '${service}' already running in namespace '${namespace}'"
fi
${KUBECTL} get service --namespace=${namespace} --no-headers 2>/dev/null | grep -q ${service}
if [ "${?}" != "0" ]; then
${KUBECTL} expose deployment ${service} --namespace=${namespace} --port=${port}
else
echo "warn: service '${service}' already exposed in namespace '${namespace}'"
fi
}
wait_until_k8s_ready
NAMESPACES="demo test"
create_namespaces
echo ""
echo "Starting services:"
run_and_expose_service mynginx demo nginx 80
run_and_expose_service webserver demo nginx 80
run_and_expose_service mynginx test nginx 80
run_and_expose_service webserver test nginx 80
echo ""
echo "Services exposed:"
${KUBECTL} get services --all-namespaces

View File

@@ -0,0 +1,35 @@
## Test scripts to automate kubernetes startup
Requirements:
docker
curl
The scripts in this directory startup kubernetes with docker as the container runtime.
After starting kubernetes, a couple of kubernetes services are started to allow automatic
testing of CoreDNS with kubernetes.
To use, run the scripts as:
~~~
$ ./00_run_k8s.sh && ./10_setup_kubectl.sh && ./20_setup_k8s_services.sh
~~~
After running the above scripts, kubernetes will be running on the localhost with the following services
exposed:
~~
NAMESPACE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes 10.0.0.1 <none> 443/TCP 48m
demo mynginx 10.0.0.168 <none> 80/TCP 9m
demo webserver 10.0.0.28 <none> 80/TCP 2m
test mynginx 10.0.0.4 <none> 80/TCP 2m
test webserver 10.0.0.39 <none> 80/TCP 2m
~~
Kubernetes and all running containers can be uncerimoniously stopped by
running the `kill_all_containers.sh` script.
~~~
$ ./kill_all_containers.sh
~~~

View File

@@ -0,0 +1,5 @@
#!/bin/bash
docker rm -f $(docker ps -a -q)
sleep 1
docker rm -f $(docker ps -a -q)