Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] CI reworked and bugs affecting tests fixed #368

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .flake8
@@ -0,0 +1,5 @@
[flake8]
select = F
ignore = E,W,C,F401,F841
exclude = __init__.py

9 changes: 9 additions & 0 deletions .gitignore
@@ -1,3 +1,12 @@
# Artifacts from running kubespawner tests with minikube
bin/
lib64
minikube-linux-amd64
node_modules/
package-lock.json
pyvenv.cfg
share/

# JupyterHub running from kubespawner folder for development purposes
jupyterhub-proxy.pid
jupyterhub.sqlite
Expand Down
72 changes: 52 additions & 20 deletions .travis.yml
@@ -1,22 +1,20 @@
language: python
sudo: required
dist: xenial
dist: bionic

# install dependencies
install:
- pip install --upgrade setuptools pip
- |
if [[ ! -z "$KUBE_PY" ]]; then
# install pinned kubernetes
pip install -e ".[test]" "kubernetes==$KUBE_PY.*"
else
# add --pre so that we test with prereleases of dependencies
# to catch compatibility issues before they enter final releases
pip install --upgrade --pre -e ".[test]"
fi
# Only add the --pre flag if $PRE_RELEASES is specified to test pre-releases
# of dependencies, and only pin kubernetes if $KUBE_PY is specified.
- pip install -e ".[test]" ${PRE_RELEASES:+--pre} ${KUBE_PY:+kubernetes==${KUBE_PY}}
- pip freeze
# flake8 runs a very quick code analysis
# without running any of the code it analyses
- flake8 kubespawner
# install kubectl, minikube and start minikube
- source ci/minikube.env
- ./ci/install-kube.sh
- pip freeze

# command to run tests
script:
Expand All @@ -26,14 +24,48 @@ after_success:
- codecov

matrix:
fast_finish: true
allow_failures:
- python: nightly
# NOTE: We may end up updating these set versions with time, when doing that,
# these links are relevant.
#
# ref: KUBE_VERSION's valid values
# https://github.com/kubernetes/kubernetes/tags
# ref: KUBE_PY's valid values
# https://github.com/kubernetes-client/python#compatibility
include:
- python: nightly
- python: 3.5
env: KUBE_PY=7
- python: 3.6
env: KUBE_PY=7
# Test the oldest supported python on
# the latest supported kubernetes-client,
# and use the latest supported kubernetes
# version along for the kubernetes-client.
- python: 3.8
env: KUBE_PY=8 KUBE_VERSION=1.12.10
- python: 3.7
env: KUBE_PY=8
env: KUBE_PY=9 KUBE_VERSION=1.13.12
- python: 3.6
env: &latest_supported KUBE_PY=10 KUBE_VERSION=1.14.9

# Allowed failure tests:
# ----------------------

# 1. Test with pre-releases of kubernetes-client/python and other
# python dependencies
- &allowed_failure_1
python: 3.8
env: PRE_RELEASES=TRUE KUBE_VERSION=1.15.3

# 2. Test with latest stable kubernetes client along with the latest
# kubernetes cluster version
- &allowed_failure_2
python: 3.8
env: KUBE_PY=10 KUBE_VERSION=1.16.3

# 3. Test with a nightly python build using latest known
# supported configuration.
- &allowed_failure_3
python: nightly
env: *latest_supported

allow_failures:
- *allowed_failure_1
- *allowed_failure_2
- *allowed_failure_3
fast_finish: true
24 changes: 18 additions & 6 deletions ci/install-kube.sh
Expand Up @@ -3,10 +3,11 @@
# this sets up minikube with vm-driver=none, so should not be used anywhere but CI
set -eux

mkdir -p bin
mkdir -p bin $HOME/.kube $HOME/.minikube
touch $KUBECONFIG

# install kubectl, minikube
# based on https://blog.travis-ci.com/2017-10-26-running-kubernetes-on-travis-ci-with-minikube
# based on https://github.com/LiliC/travis-minikube
echo "installing kubectl"
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v${KUBE_VERSION}/bin/linux/amd64/kubectl
chmod +x kubectl
Expand All @@ -17,13 +18,24 @@ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v${MINIKUBE_V
chmod +x minikube
mv minikube bin/

echo "starting minikube with RBAC"
sudo CHANGE_MINIKUBE_NONE_USER=true $PWD/bin/minikube start --vm-driver=none --kubernetes-version=v${KUBE_VERSION} --extra-config=apiserver.Authorization.Mode=RBAC --bootstrapper=localkube
echo "starting minikube"
sudo $PWD/bin/minikube start --vm-driver=none --kubernetes-version=v${KUBE_VERSION}
sudo chown -R travis: /home/travis/.minikube/
minikube update-context

echo "waiting for kubernetes"

# can be used to check a condition of nodes and pods
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do

echo "waiting for kube-addon-manager"
until kubectl -n kube-system get pods -l component=kube-addon-manager -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
sleep 1
done

echo "waiting for kube-dns"
until kubectl -n kube-system get pods -l k8s-app=kube-dns -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
sleep 1
done

kubectl get nodes
kubectl get pods --all-namespaces
22 changes: 18 additions & 4 deletions ci/minikube.env
@@ -1,5 +1,19 @@
# environment variables for installing kubernetes on CI
export MINIKUBE_VERSION=0.28.0
export HELM_VERSION=2.9.1
export KUBE_VERSION=1.10.0
# default values for relevant environment variables

# ref: https://github.com/kubernetes/minikube/releases
export KUBE_VERSION=${KUBE_VERSION:-1.16.3}

# ref: https://github.com/kubernetes/minikube/releases
export MINIKUBE_VERSION=${MINIKUBE_VERSION:-1.5.2}

# ref: https://github.com/helm/helm/releases
export HELM_VERSION=${HELM_VERSION:-2.16.1}

# ref: https://github.com/LiliC/travis-minikube/blob/master/.travis.yml
export CHANGE_MINIKUBE_NONE_USER=true
export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=$HOME
export KUBECONFIG=$HOME/.kube/config

export PATH="$PWD/bin:$PATH"
2 changes: 1 addition & 1 deletion jupyterhub_config.py
Expand Up @@ -24,7 +24,7 @@
host_ip = s.getsockname()[0]
s.close()

c.KubeSpawner.hub_connect_ip = host_ip
c.JupyterHub.hub_connect_ip = host_ip
c.JupyterHub.hub_connect_ip = c.KubeSpawner.hub_connect_ip

c.KubeSpawner.service_account = 'default'
Expand Down
17 changes: 12 additions & 5 deletions kubespawner/reflector.py
Expand Up @@ -221,13 +221,20 @@ def _watch_and_update(self):
watch_args['timeout_seconds'] = self.timeout_seconds
# in case of timeout_seconds, the w.stream just exits (no exception thrown)
# -> we stop the watcher and start a new one
for ev in w.stream(
getattr(self.api, self.list_method_name),
**watch_args
for watch_event in w.stream(
getattr(self.api, self.list_method_name),
**watch_args
):
# Remember that these events are k8s api related WatchEvents
# objects, not k8s Event or Pod representations, they will
# reside in the WatchEvent's object field depending on what
# kind of resource is watched.
#
# ref: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#watchevent-v1-meta
# ref: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#event-v1-core
cur_delay = 0.1
resource = ev['object']
if ev['type'] == 'DELETED':
resource = watch_event['object']
if watch_event['type'] == 'DELETED':
# This is an atomic delete operation on the dictionary!
self.resources.pop(resource.metadata.name, None)
else:
Expand Down