diff --git a/.gitignore b/.gitignore index cdfd27903..74ce3b019 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ testdata/sidecar/.sidecar docker/fluxy-dumbconf.priv test/profiles test/bin/ -!test/bin/test-flux test/e2e/bats # Docs diff --git a/Makefile b/Makefile index c95d2e2e9..8baec3011 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ test/bin/shellcheck: cache/$(CURRENT_OS_ARCH)/shellcheck-$(SHELLCHECK_VERSION) test/bin/shfmt: cache/$(CURRENT_OS_ARCH)/shfmt-$(SHFMT_VERSION) build/kubectl test/bin/kubectl build/kustomize test/bin/kustomize build/helm test/bin/helm test/bin/shellcheck test/bin/shfmt: - mkdir -p build + mkdir -p $(@D) cp $< $@ if [ `basename $@` = "build" -a $(CURRENT_OS_ARCH) = "linux-$(ARCH)" ]; then strip $@; fi chmod a+x $@ diff --git a/test/bin/test-flux b/test/bin/test-flux deleted file mode 100755 index 3e2cf2c80..000000000 --- a/test/bin/test-flux +++ /dev/null @@ -1,130 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail - -BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)" -PROFILE="flux-test" -PROFILE_DIR="$BASEDIR/profiles/$PROFILE" -KNOWN_HOSTS="$PROFILE_DIR/.known_hosts" -CONFIG_REPO="$PROFILE_DIR/config" -SSH_PRIVATE_KEY="$HOME/.minikube/machines/$PROFILE/id_rsa" - -############################################################################# -# Setup -############################################################################# - -# Clear profile temp dir and reset minikube profile -rm -rf "$PROFILE_DIR" -mkdir -p "$PROFILE_DIR" -minikube delete --profile "$PROFILE" || true -minikube start --profile "$PROFILE" --keep-context -MINIKUBE_IP=$(minikube --profile "$PROFILE" ip) - -# Copy the latest Flux image into the minikube VM -docker save "docker.io/fluxcd/flux:latest" | (eval $(minikube --profile "$PROFILE" docker-env) && docker load) - -# Create a central git repo inside the minikube VM and get the host key for ssh access -minikube --profile "$PROFILE" ssh -- git init --bare /home/docker/flux.git -ssh-keyscan $MINIKUBE_IP > "$KNOWN_HOSTS" - -# Deploy Flux in kube-system namespace, supplying it with the SSH keys it needs to access & authenticate the config repo -kubectl --context "$PROFILE" -n kube-system create secret generic flux-git-deploy --from-file=identity="$SSH_PRIVATE_KEY" -kubectl --context "$PROFILE" -n kube-system create configmap ssh-known-hosts --from-file=known_hosts="$KNOWN_HOSTS" -sed -e "s/MINIKUBE_IP/$MINIKUBE_IP/" "$BASEDIR/flux-deploy-all.yaml" | kubectl --context "$PROFILE" -n kube-system apply -f- - -# Create a git repo in the local filesystem configured with the central git repo in minikube as origin -git init "$CONFIG_REPO" -git -C "$CONFIG_REPO" remote add origin ssh://docker@$MINIKUBE_IP/home/docker/flux.git -export GIT_SSH_COMMAND="ssh -i $SSH_PRIVATE_KEY -o UserKnownHostsFile=$KNOWN_HOSTS" - -############################################################################# -# Test Helpers -############################################################################# - -fail() { - echo - echo "*** FAILED ***" - echo - exit 1 -} - -success() { - echo - echo "*** SUCCESS ***" - echo - exit 0 -} - -wait_for_sync() { - echo -n "Waiting for sync" - HEAD_REV=$(git -C "$CONFIG_REPO" rev-list -n 1 HEAD) - for i in $(seq 1 $1); do - git -C "$CONFIG_REPO" fetch --tags > /dev/null 2>&1 - FLUX_SYNC_REV=$(git -C "$CONFIG_REPO" rev-list -n 1 flux-sync 2>/dev/null || true) - if [ "$FLUX_SYNC_REV" = "$HEAD_REV" ]; then - echo - return - fi - sleep 1 - echo -n . - done - fail -} - -wait_for_upstream_commits() { - echo -n "Waiting for $2 upstream commits" - for i in $(seq 1 $1); do - git -C "$CONFIG_REPO" fetch --tags > /dev/null 2>&1 - if [ "$(git -C "$CONFIG_REPO" rev-list --count HEAD..flux-sync)" -eq "2" ]; then - echo - return - fi - sleep 1 - echo -n . - done - fail -} - -workloads() { - curl -s "http://$MINIKUBE_IP:30080/api/flux/v6/services?namespace=$1" -} - -workload_container() { - jq --raw-output ".[]|select(.ID==\"$1\")|.Containers[]|select(.Name==\"$2\")|.Current.ID" -} - -assert_workload_container() { - if [ "$(workloads $1|workload_container $2 $3)" != "$4" ]; then - fail - fi -} - -############################################################################# -# Tests -############################################################################# - -# Add the helloworld deployment to the config repo and push to the central config repo in minikube -cp "$BASEDIR/helloworld-deployment.yaml" "$CONFIG_REPO" -git -C "$CONFIG_REPO" add helloworld-deployment.yaml -git -C "$CONFIG_REPO" commit -m 'Deploy helloworld' -git -C "$CONFIG_REPO" push -u origin master - -# Wait two minutes for flux-sync tag to point to local HEAD -wait_for_sync 120 - -# Examine workloads via Flux API an assert container versions are correct -assert_workload_container default default:deployment/helloworld helloworld quay.io/weaveworks/helloworld:master-a000001 -assert_workload_container default default:deployment/helloworld sidecar quay.io/weaveworks/sidecar:master-a000001 - -# Now enable automation -fluxctl --url http://$(minikube -p flux-test ip):30080/api/flux automate --workload=default:deployment/helloworld - -# Wait two minutes for two (automation and release) commits to appear -wait_for_upstream_commits 120 2 - -# Examine workload via Flux API an assert container versions are updated -assert_workload_container default default:deployment/helloworld helloworld quay.io/weaveworks/helloworld:master-9a16ff945b9e -assert_workload_container default default:deployment/helloworld sidecar quay.io/weaveworks/sidecar:master-a000002 - -success diff --git a/test/flux-deploy-all.yaml b/test/flux-deploy-all.yaml deleted file mode 100644 index 0ac072d25..000000000 --- a/test/flux-deploy-all.yaml +++ /dev/null @@ -1,98 +0,0 @@ ---- -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: memcached -spec: - replicas: 1 - template: - metadata: - labels: - name: memcached - spec: - containers: - - name: memcached - image: memcached:1.4.25 - imagePullPolicy: IfNotPresent - args: - - -m 64 # Maximum memory to use, in megabytes. 64MB is default. - - -p 11211 # Default port, but being explicit is nice. - - -vv # This gets us to the level of request logs. - ports: - - name: clients - containerPort: 11211 ---- -apiVersion: v1 -kind: Service -metadata: - name: memcached -spec: - # The memcache client uses DNS to get a list of memcached servers and then - # uses a consistent hash of the key to determine which server to pick. - clusterIP: None - ports: - - name: memcached - port: 11211 - selector: - name: memcached ---- -# Expose Flux to fluxctl -apiVersion: v1 -kind: Service -metadata: - name: flux -spec: - type: NodePort - ports: - - port: 80 - targetPort: 3030 - nodePort: 30080 # Hardwired for test harness access - selector: - name: flux ---- -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: flux -spec: - replicas: 1 - strategy: - type: Recreate - template: - metadata: - labels: - name: flux - spec: - volumes: - - name: git-key - secret: - secretName: flux-git-deploy - - name: ssh-known-hosts - configMap: - name: ssh-known-hosts - items: - - key: known_hosts - path: known_hosts - containers: - - name: flux - # Require locally built image - image: docker.io/fluxcd/flux:latest - imagePullPolicy: Never - ports: - - containerPort: 3030 # informational - volumeMounts: - - name: git-key - mountPath: /etc/fluxd/ssh - - name: ssh-known-hosts - mountPath: /root/.ssh - args: - - --memcached-hostname=memcached - - --memcached-timeout=100ms - - --memcached-service=memcached - - --registry-cache-expiry=20m - # Access minikube hosted config repo by ssh - - --git-url=ssh://docker@MINIKUBE_IP:/home/docker/flux.git - - --git-branch=master - # Tune up to make tests run quicker - - --automation-interval=60s - - --git-poll-interval=60s diff --git a/test/helloworld-deployment.yaml b/test/helloworld-deployment.yaml deleted file mode 100644 index 84446dd46..000000000 --- a/test/helloworld-deployment.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: helloworld -spec: - minReadySeconds: 5 - replicas: 2 - template: - metadata: - labels: - name: helloworld - spec: - containers: - - name: helloworld - image: quay.io/weaveworks/helloworld:master-a000001 - args: - - -msg=Ahoy - ports: - - containerPort: 80 - - name: sidecar - image: quay.io/weaveworks/sidecar:master-a000001 - args: - - -addr=:8080 - ports: - - containerPort: 8080