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

log services in CLI tests #270

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ jobs:
kubectl wait --for=condition=Ready=true pod -n cert-manager --all
kubectl get pods -A

# check services
kubectl get svc ingress-nginx-controller
kubectl get svc istio-ingressgateway -n istio-system
kubectl get svc traefik

# install bats
sudo apt-get update -yq && sudo apt-get install bats -y

- name: Run Integration Tests
# TODO enable cli_tests/app.sh after ingress updates
run: |
cli_tests/job.sh
cli_tests/job.sh
cli_tests/app.sh
114 changes: 114 additions & 0 deletions .github/workflows/deploy_nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: deploy

on: push

jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Go Version
uses: actions/setup-go@v2
with:
go-version: '1.17'
- name: Unit Tests
run: |
make install-kubebuilder KUBEBUILDER_INSTALL_DIR=/tmp/kubebuilder/bin
sudo chmod -R 777 /tmp/kubebuilder

curl -L -o /tmp/kubebuilder/bin/kube-apiserver https://dl.k8s.io/v1.24.1/bin/linux/amd64/kube-apiserver
chmod a+x /tmp/kubebuilder/bin/kube-apiserver
cp /tmp/kubebuilder/bin/kube-apiserver /usr/local/bin/kube-apiserver
export TEST_ASSET_KUBE_APISERVER=/tmp/kubebuilder/bin/kube-apiserver

curl -L -o /tmp/etcd-v3.5.4-linux-amd64.tar.gz https://github.com/etcd-io/etcd/releases/download/v3.5.4/etcd-v3.5.4-linux-amd64.tar.gz
tar -xzvf /tmp/etcd-v3.5.4-linux-amd64.tar.gz -C /tmp/
mv /tmp/etcd-v3.5.4-linux-amd64/etcd /tmp/kubebuilder/bin
rm -rf /tmp/etcd-v3.5.4-linux-amd64*
export TEST_ASSET_ETCD=/tmp/kubebuilder/bin/etcd

make test
- name: Checkout unit-test-coverage
uses: actions/checkout@v2
with:
repository: theketchio/unit-test-coverage
ref: main
path: unit-test-coverage
- name: build coverage-tester
run: go build -o unit-tester unit-test-coverage/main.go
- name: validate unit Tests
run: ./unit-tester --coverage coverage.txt --limits ci/limits.json
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub
uses: docker/build-push-action@v2
with:
tags: shipasoftware/ketch:${{github.sha}}
push: true
- uses: AbsaOSS/k3d-action@v2.3.0
name: "Create K3D Cluster"
with:
cluster-name: "test-cluster-1"
args: >-
--agents 1
--k3s-arg "--disable=traefik@server:*"
- name: Install Integration Test Dependencies
run: |
# kubebuilder
make install-kubebuilder KUBEBUILDER_INSTALL_DIR=/tmp/kubebuilder/bin
sudo chmod -R 777 /tmp/kubebuilder

# kube-apiserver
curl -L -o /tmp/kubebuilder/bin/kube-apiserver https://dl.k8s.io/v1.24.1/bin/linux/amd64/kube-apiserver
chmod a+x /tmp/kubebuilder/bin/kube-apiserver
cp /tmp/kubebuilder/bin/kube-apiserver /usr/local/bin/kube-apiserver
export TEST_ASSET_KUBE_APISERVER=/tmp/kubebuilder/bin/kube-apiserver

# etcd
curl -L -o /tmp/etcd-v3.5.4-linux-amd64.tar.gz https://github.com/etcd-io/etcd/releases/download/v3.5.4/etcd-v3.5.4-linux-amd64.tar.gz
tar -xzvf /tmp/etcd-v3.5.4-linux-amd64.tar.gz -C /tmp/
mv /tmp/etcd-v3.5.4-linux-amd64/etcd /tmp/kubebuilder/bin
rm -rf /tmp/etcd-v3.5.4-linux-amd64*
export TEST_ASSET_ETCD=/tmp/kubebuilder/bin/etcd

# kustomize
make install-kustomize KUSTOMIZE_INSTALL_DIR=/tmp
export PATH=$PATH:/tmp

# ketch
kubectl cluster-info
make manifests install ketch manager
export PATH=$PATH:$(pwd)/bin
ketch -v

# helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 get_helm.sh && ./get_helm.sh

# cert-manager
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.1/cert-manager.yaml

# nginx
kubectl create ns ingress-nginx
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx

# wait for containers
kubectl wait --for=condition=Ready=true pod -n cert-manager --all
kubectl get pods -A

# check services
kubectl get svc ingress-nginx-controller -n ingress-nginx

# install bats
sudo apt-get update -yq && sudo apt-get install bats -y

- name: Run Integration Tests
run: |
cli_tests/job.sh
cli_tests/app.sh
16 changes: 11 additions & 5 deletions cli_tests/app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ setup() {
else
KETCH="${KETCH_EXECUTABLE_PATH}"
fi
INGRESS_TRAEFIK=$(kubectl get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
INGRESS_NGINX=$(kubectl get svc ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}' -n ingress-nginx)
INGRESS_ISTIO=$(kubectl get svc istio-ingressgateway -n istio-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
INGRESS_TRAEFIK=$(kubectl get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}' || echo '')
INGRESS_NGINX=$(kubectl get svc ingress-nginx-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}' -n ingress-nginx || echo '')
INGRESS_ISTIO=$(kubectl get svc istio-ingressgateway -n istio-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}' || echo '')
NAMESPACE="appnamespace"
APP_IMAGE="gcr.io/shipa-ci/sample-go-app:latest"
APP_NAME="sample-app"
Expand All @@ -36,17 +36,20 @@ teardown() {
[[ $result =~ "Flags" ]]
}

@test "app deploy" {
@test "app deploy traefik" {
if [ -z "$INGRESS_TRAEFIK" ]; then skip "no traefik ingress"; fi
run $KETCH app deploy "$APP_NAME" --namespace "$NAMESPACE" -i "$APP_IMAGE"
[[ $status -eq 0 ]]
}

@test "app deploy istio" {
if [ -z "$INGRESS_ISTIO" ]; then skip "no istio ingress"; fi
run $KETCH app deploy "$APP_NAME-istio" --namespace "$NAMESPACE-istio" -i "$APP_IMAGE"
[[ $status -eq 0 ]]
}

@test "app deploy nginx" {
if [ -z "$INGRESS_NGINX" ]; then skip "no nginx ingress"; fi
run $KETCH app deploy "$APP_NAME-nginx" --namespace "$NAMESPACE-nginx" -i "$APP_IMAGE"
[[ $status -eq 0 ]]
}
Expand Down Expand Up @@ -182,19 +185,22 @@ EOF
[[ ! $result =~ "$TEST_ENVVAR_VALUE" ]]
}

@test "app remove" {
@test "app-traefik remove" {
if [ -z "$INGRESS_TRAEFIK" ]; then skip "no traefik ingress"; fi
result=$($KETCH app remove "$APP_NAME")
echo "RECEIVED:" $result
[[ $result =~ "Successfully removed!" ]]
}

@test "app-istio remove" {
if [ -z "$INGRESS_ISTIO" ]; then skip "no istio ingress"; fi
result=$($KETCH app remove "$APP_NAME-istio")
echo "RECEIVED:" $result
[[ $result =~ "Successfully removed!" ]]
}

@test "app-nginx remove" {
if [ -z "$INGRESS_NGINX" ]; then skip "no nginx ingress"; fi
result=$($KETCH app remove "$APP_NAME-nginx")
echo "RECEIVED:" $result
[[ $result =~ "Successfully removed!" ]]
Expand Down