Skip to content

Commit

Permalink
Have Travis use k3s to test the containers.
Browse files Browse the repository at this point in the history
Test basic Pulp functionality, including writing to disk Using
pulp_file's sync tests.

Also, don't set CONTENT_HOST in the pulp-server ConfigMap.
If set incorrectly, it causes pulp_file test scripts to fail.
We haven't implemented querying it via the K8s APIs,
or having users specify it yet.

Note that the RequestsDependencyWarning messages from httpie are
annoying output, but pip3 is not on Ubuntu on Travis.
It appears that Travis relies on the virtual env for Python3

fixes #5061
https://pulp.plan.io/issues/5061
  • Loading branch information
mikedep333 committed Jul 23, 2019
1 parent 09e4af9 commit bcbf528
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 7 deletions.
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@ dist: xenial
sudo: required
services: docker
language: python
services:
- docker
before_install:
- git clone https://github.com/pulp/pulp_file.git
install:
- pip install docker molecule openshift jmespath
# Need /usr/bin/http script, so use sudo
# It can mess up ownership of the python cache dir, so run it after the
# non-sudo pip command.
- sudo pip install httpie
- .travis/k3s-install.sh
script:
- molecule test -s test-local
- sudo ./up.sh
- .travis/pulp-operator-check-and-wait.sh
- .travis/pulp_file-tests.sh
after_failure:
- http --timeout 30 --check-status --pretty format --print hb http://localhost:24817/pulp/api/v3/status/
# With the selector (which eliminates the need to look up the pod name),
# we cannot show all logs. 10000 lines should be sufficient.
- sudo kubectl logs -l app=pulp-api --tail=10000
44 changes: 44 additions & 0 deletions .travis/k3s-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# coding=utf-8

# k3s-install.sh
# This script installs k3s (lightweight Kubernetes (K8s) and does anything else
# to setup the single-node k3s infrastructure for running Pulp containers in
# Travis CI.

# This is their convenience installer script.
# Does a bunch of stuff, such as setting up a `kubectl` -> `k3s kubectl` symlink.
#
# It will install the latest version.
# We can always pass args to use a specific version or change other options.
#
# TODO: Fix access to registry.centos.org
# https://github.com/rancher/k3s/issues/145#issuecomment-490143506
curl -sfL https://get.k3s.io | sudo sh -
status=$(sudo systemctl status --full --lines=200 k3s)
if ! [[ $? ]] ; then
echo "${status}"
echo "SYSTEMD UNIT:"
sudo cat /etc/systemd/system/k3s.service
exit 1
fi
echo "k3s NODE Status:"
sudo kubectl get node

# By default, k3s lacks a storage class.
# https://github.com/rancher/k3s/issues/85#issuecomment-468293334
# This is the way to add a simple hostPath storage class.
sudo kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
sudo kubectl get storageclass
# How make it the default StorageClass
sudo kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
sudo kubectl get storageclass

echo "NAT"
sudo iptables -L -t nat
echo "IPTABLES"
sudo iptables -L
echo "UFW"
sudo ufw status verbose
echo "CLUSTER-INFO"
sudo kubectl cluster-info
98 changes: 98 additions & 0 deletions .travis/pulp-operator-check-and-wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
# coding=utf-8

# pulp-operator-check-and-wait.sh:
# 1. Check that pulp-operator was successfully deployed on top of K8s
# 2. Wait for pulp-operator to be deployed to the point that pulp-api is able to
# serve requests.
#
# Currently only tested with k3s rather than a full K8s implementation.
# Uses generic K8s logic though.

storage_debug() {
echo "VOLUMES:"
sudo kubectl get pvc
sudo kubectl get pv
df -h
sudo kubectl -n local-path-storage get pod
sudo kubectl -n local-path-storage logs $STORAGE_POD
}

# Once the services are both up, the pods will be in a Pending state.
# Before the services are both up, the pods may not exist at all.
# So check for the services being up 1st.
for tries in {0..30}; do
services=$(sudo kubectl get services)
if [[ $(echo "$services" | grep -c NodePort) -eq 2 ]]; then
# parse string like this. 30805 is the external port
# pulp-api NodePort 10.43.170.79 <none> 24817:30805/TCP 0s
API_PORT=$( echo "$services" | awk -F '[ :/]+' '/pulp-api/{print $6}')
echo "SERVICES:"
echo "$services"
break
else
if [[ $tries -eq 30 ]]; then
echo "ERROR 2: 1 or more external services never came up"
echo "SERVICES:"
echo "$services"
storage_debug
exit 2
fi
fi
sleep 5
done

# This needs to be down here. Otherwise, the storage pod may not be
# up in time.
STORAGE_POD=$(sudo kubectl -n local-path-storage get pod | awk '/local-path-provisioner/{print $1}')

for tries in {0..120}; do
pods=$(sudo kubectl get pods -o wide)
if [[ $(echo "$pods" | grep -c -v -E "STATUS|Running") -eq 0 ]]; then
echo "PODS:"
echo "$pods"
API_NODE=$( echo "$pods" | awk -F '[ :/]+' '/pulp-api/{print $8}')
break
else
# Often after 30 tries (150 secs), not all of the pods are running yet.
# Let's keep Travis from ending the build by outputting.
if [[ $(( tries % 30 )) == 0 ]]; then
echo "STATUS: Still waiting on pods to transitiion to running state."
echo "PODS:"
echo "$pods"
fi
if [[ $tries -eq 120 ]]; then
echo "ERROR 3: Pods never all transitioned to Running state"
storage_debug
exit 3
fi
fi
sleep 5
done

# Later tests in other scripts will use localhost:24817, which was not a safe
# assumption at the time this script was originally written.
URL=http://$API_NODE:$API_PORT/pulp/api/v3/status/
echo "URL:"
echo $URL
# Sometimes 30 tries is not enough for the service to actually come up
# Until it does:
# http: error: Request timed out (5.0s).
#
# --pretty format --print hb almost make it behave as if it were not redirected
for tries in {0..120}; do
output=$(http --timeout 5 --check-status --pretty format --print hb $URL 2>&1)
rc=$?
if echo "$output" | grep "Errno 111" ; then
# if connection refused, httpie does not wait 5 seconds
sleep 5
elif [[ $rc ]] ; then
echo "Successfully got the status page after _roughly_ $((tries * 5)) seconds"
echo "$output"
break
elif [[ $tries -eq 120 ]]; then
echo "ERROR 4: Status page never accessible or returning success"
storage_debug
exit 4
fi
done
15 changes: 15 additions & 0 deletions .travis/pulp_file-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# coding=utf-8

# From the pulp-server/pulp-api config-map
echo "machine localhost
login admin
password password\
" > ~/.netrc

pushd pulp_file/docs/_scripts
# Let's only do sync tests.
# So as to check that Pulp can work in containers, including writing to disk.
# If the upload tests are simpler in the long run, just use them.
source docs_check_sync_publish.sh

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
`./up.sh`

`minikube service list`

or

Get external ports:

`kubectl get services`

Get external IP addresses:

`kubectl get pods -o wide`
4 changes: 2 additions & 2 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ spec:
- /usr/local/bin/ao-logs
- /tmp/ansible-operator/runner
- stdout
image: "quay.io/pulp/pulp-operator:latest"
image: "quay.io/pulp/pulp-operator:k3s-travis"
imagePullPolicy: "Always"
volumeMounts:
- mountPath: /tmp/ansible-operator/runner
name: runner
readOnly: true
- name: operator
image: "quay.io/pulp/pulp-operator:latest"
image: "quay.io/pulp/pulp-operator:k3s-travis"
imagePullPolicy: "Always"
volumeMounts:
- mountPath: /tmp/ansible-operator/runner
Expand Down
2 changes: 0 additions & 2 deletions roles/pulp-api/templates/pulp-api.config-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ data:
REDIS_HOST = 'redis'
REDIS_PORT = 6379
REDIS_PASSWORD = ''
CONTENT_HOST = 'pulp-server'
4 changes: 2 additions & 2 deletions roles/pulp-api/templates/pulp-file-storage.pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ metadata:
spec:
resources:
requests:
storage: 375Gi
storage: 1Gi
accessModes:
- ReadWriteMany
- ReadWriteOnce

0 comments on commit bcbf528

Please sign in to comment.