Skip to content

Commit

Permalink
NODE-5583 add mandatory function
Browse files Browse the repository at this point in the history
  • Loading branch information
braek-neck committed Aug 8, 2024
1 parent 6499e11 commit df8d72b
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ SMOKE_REGISTRY_SECRET=...
# Just keep it here since it is used in main Makefile if we don't have GO installed locally
ARCH=amd64

PYTEST_WORKERS=10

# Local env features

# To download from private registry set the following dkr.wallarm.com/wallarm-node/ingress-images-factory
Expand Down
68 changes: 67 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,26 @@ jobs:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Import secrets
uses: hashicorp/vault-action@130d1f5f4fe645bb6c83e4225c04d64cfb62de6e # v2.5.0
id: secrets
with:
exportEnv: true
url: ${{ secrets.VAULT_URL }}
role: ${{ secrets.VAULT_ROLE }}
method: kubernetes
path: kubernetes-ci
secrets: |
kv-gitlab-ci/data/github/shared/dockerhub-creds user | DOCKERHUB_USER ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password | DOCKERHUB_PASSWORD ;
- name: Build controller images
env:
REGISTRY: wallarm
TAG: 1.0.0-dev
USER: runner
run: |
echo ${DOCKERHUB_PASSWORD} | docker login -u ${DOCKERHUB_USER} --password-stdin
echo "Building controller images ..."
make clean-image build image image-chroot
echo "Building E2E image ..."
Expand Down Expand Up @@ -134,6 +148,8 @@ jobs:
kv-gitlab-ci/data/github/shared/allure allure_token ;
kv-gitlab-ci/data/github/shared/smoke-tests-registry-creds token_name ;
kv-gitlab-ci/data/github/shared/smoke-tests-registry-creds token_secret ;
kv-gitlab-ci/data/github/shared/dockerhub-creds user ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password ;
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand All @@ -146,13 +162,18 @@ jobs:
- name: Load images
run: docker load -i controller-${{ env.ARCH }}.tar

- name: Login to DockerHub
run: echo ${{ steps.secrets.outputs.password }} | docker login -u ${{ steps.secrets.outputs.user }} --password-stdin

- name: Create cluster
run: kind create cluster --image=kindest/node:${{ matrix.k8s }}

- name: Run smoke tests
env:
SKIP_CLUSTER_CREATION: true
SKIP_IMAGE_CREATION: true
DOCKERHUB_USER: ${{ steps.secrets.outputs.user }}
DOCKERHUB_PASSWORD: ${{ steps.secrets.outputs.password }}
WALLARM_API_TOKEN: ${{ steps.secrets.outputs.api_token }}
WALLARM_API_HOST: ${{ steps.secrets.outputs.api_host }}
WALLARM_API_PRESET: ${{ steps.secrets.outputs.api_preset }}
Expand All @@ -161,8 +182,10 @@ jobs:
SMOKE_REGISTRY_SECRET: ${{ steps.secrets.outputs.token_secret }}
WEBHOOK_API_KEY: ${{ steps.secrets.outputs.webhook_api_key }}
WEBHOOK_UUID: ${{ steps.secrets.outputs.webhook_uuid }}
CLIENT_ID: 5
ALLURE_UPLOAD_REPORT: true
ALLURE_GENERATE_REPORT: true
ALLURE_PROJECT_ID: 10
ALLURE_TOKEN: ${{ steps.secrets.outputs.allure_token }}
ALLURE_ENVIRONMENT_K8S: ${{ matrix.k8s }}
ALLURE_ENVIRONMENT_ARCH: ${{ matrix.ARCH }}
Expand Down Expand Up @@ -192,7 +215,10 @@ jobs:
role: ${{ secrets.VAULT_ROLE }}
method: kubernetes
path: kubernetes-ci
secrets: kv-gitlab-ci/data/github/ingress api_token
secrets: |
kv-gitlab-ci/data/github/ingress api_token ;
kv-gitlab-ci/data/github/shared/dockerhub-creds user ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password ;
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand All @@ -207,6 +233,9 @@ jobs:
- name: Load images
run: docker load -i controller-${{ env.ARCH }}.tar

- name: Login to DockerHub
run: echo ${{ steps.secrets.outputs.password }} | docker login -u ${{ steps.secrets.outputs.user }} --password-stdin

- name: Create cluster
run: kind create cluster --image=kindest/node:v1.25.8 --config test/e2e/kind.yaml

Expand Down Expand Up @@ -243,6 +272,22 @@ jobs:
- name: Load controller images
run: docker load -i controller-${{ env.ARCH }}.tar

- name: Import secrets
uses: hashicorp/vault-action@d1720f055e0635fd932a1d2a48f87a666a57906c # v3.0.0
id: secrets
with:
exportEnv: false
url: ${{ secrets.VAULT_URL }}
role: ${{ secrets.VAULT_ROLE }}
method: kubernetes
path: kubernetes-ci
secrets: |
kv-gitlab-ci/data/github/shared/dockerhub-creds user ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password ;
- name: Login to DockerHub
run: echo ${{ steps.secrets.outputs.password }} | docker login -u ${{ steps.secrets.outputs.user }} --password-stdin

- name: Create cluster
run: kind create cluster --image=kindest/node:v1.25.8 --config test/e2e/kind.yaml

Expand Down Expand Up @@ -285,6 +330,8 @@ jobs:
secrets: |
kv-gitlab-ci/data/github/ingress api_token ;
kv-gitlab-ci/data/github/ingress api_host ;
kv-gitlab-ci/data/github/shared/dockerhub-creds user ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password ;
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand All @@ -297,6 +344,9 @@ jobs:
- name: Load controller images
run: docker load -i controller-${{ env.ARCH }}.tar

- name: Login to DockerHub
run: echo ${{ steps.secrets.outputs.password }} | docker login -u ${{ steps.secrets.outputs.user }} --password-stdin

- name: Create cluster ${{ matrix.k8s }}
run: kind create cluster --image=kindest/node:${{ matrix.k8s }} --config test/e2e/kind.yaml

Expand Down Expand Up @@ -333,6 +383,22 @@ jobs:
- name: Load controller images
run: docker load -i controller-${{ env.ARCH }}.tar

- name: Import secrets
uses: hashicorp/vault-action@d1720f055e0635fd932a1d2a48f87a666a57906c # v3.0.0
id: secrets
with:
exportEnv: false
url: ${{ secrets.VAULT_URL }}
role: ${{ secrets.VAULT_ROLE }}
method: kubernetes
path: kubernetes-ci
secrets: |
kv-gitlab-ci/data/github/shared/dockerhub-creds user ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password ;
- name: Login to DockerHub
run: echo ${{ steps.secrets.outputs.password }} | docker login -u ${{ steps.secrets.outputs.user }} --password-stdin

- name: Scan controller image
uses: anchore/scan-action@3343887d815d7b07465f6fdcd395bd66508d486a
with:
Expand Down
4 changes: 2 additions & 2 deletions charts/ingress-nginx/templates/tarantool-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- if .Values.controller.wallarm.imagePullSecrets }}
imagePullSecrets: {{ toYaml .Values.controller.wallarm.imagePullSecrets | nindent 8 }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets: {{ toYaml .Values.imagePullSecrets | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.controller.wallarm.tarantool.terminationGracePeriodSeconds }}
initContainers:
Expand Down
6 changes: 3 additions & 3 deletions charts/ingress-nginx/templates/tarantool-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- if .Values.controller.wallarm.imagePullSecrets }}
imagePullSecrets: {{ toYaml .Values.controller.wallarm.imagePullSecrets | nindent 8 }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets: {{ toYaml .Values.imagePullSecrets | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.controller.wallarm.tarantool.terminationGracePeriodSeconds }}
initContainers:
Expand Down Expand Up @@ -145,4 +145,4 @@ spec:
name: {{ template "ingress-nginx.wallarmTarantoolCronConfig" . }}
{{- include "ingress-nginx.wallarmTokenVolume" . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
55 changes: 55 additions & 0 deletions test/smoke/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This file used for import in other files

RED='\033[0;31m'
NC='\033[0m'

function check_mandatory_vars() {

declare -a mandatory
declare -a allure_mandatory

mandatory=(
WALLARM_API_TOKEN
WALLARM_API_HOST
WALLARM_API_PRESET
CLIENT_ID
USER_TOKEN
WEBHOOK_API_KEY
WEBHOOK_UUID
SMOKE_REGISTRY_TOKEN
SMOKE_REGISTRY_SECRET
)

env_list=""

for var in "${mandatory[@]}"; do
if [[ -z "${!var:-}" ]]; then
env_list+=" $var"
fi
done

if [[ "${ALLURE_UPLOAD_REPORT:-false}" == "true" ]]; then

allure_mandatory=(
ALLURE_TOKEN
ALLURE_ENVIRONMENT_ARCH
ALLURE_PROJECT_ID
ALLURE_GENERATE_REPORT
ALLURE_ENVIRONMENT_K8S
)

for var in "${allure_mandatory[@]}"; do
if [[ -z "${!var:-}" ]]; then
env_list+=" $var"
fi
done
fi

if [[ -n "$env_list" ]]; then
for var in ${env_list}; do
echo -e "${RED}Environment variable $var must be set${NC}"
done
exit 1
fi

}
101 changes: 43 additions & 58 deletions test/smoke/run-smoke-suite.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
#!/bin/bash

if [[ -n "${DEBUG}" ]]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

export KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-ingress-smoke-test}
export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/kind-config-$KIND_CLUSTER_NAME}"

# Variables required for pulling Docker image with pytest
SMOKE_REGISTRY_NAME="${SMOKE_REGISTRY_NAME:-dkr.wallarm.com}"
SMOKE_IMAGE_PULL_SECRET_NAME="pytest-registry-creds"

SMOKE_IMAGE_NAME="${SMOKE_IMAGE_NAME:-dkr.wallarm.com/tests/smoke-tests}"
SMOKE_IMAGE_TAG="${SMOKE_IMAGE_TAG:-latest}"

# Allure related variables
ALLURE_ENDPOINT="${ALLURE_ENDPOINT:-https://allure.wallarm.com}"
ALLURE_PROJECT_ID=${ALLURE_PROJECT_ID:-10}
ALLURE_RESULTS="${ALLURE_RESULTS:-/tests/_out/allure_report}"
ALLURE_UPLOAD_REPORT="${ALLURE_UPLOAD_REPORT:-false}"
ALLURE_GENERATE_REPORT="${ALLURE_GENERATE_REPORT:-false}"

# Pytest related variables
CLIENT_ID="${CLIENT_ID:-5}"
WALLARM_API_CA_VERIFY="${WALLARM_API_CA_VERIFY:-true}"
WALLARM_API_HOST="${WALLARM_API_HOST:-api.wallarm.com}"
WALLARM_API_PRESET="${WALLARM_API_PRESET:-eu1}"
NODE_BASE_URL="${NODE_BASE_URL:-http://wallarm-ingress-controller.default.svc}"
PYTEST_ARGS=$(echo "${PYTEST_ARGS:---allure-features=Node}" | xargs)
PYTEST_WORKERS="${PYTEST_WORKERS:-10}"
#TODO We need it here just to don't let test fail. Remove this variable when test will be fixed.
HOSTNAME_OLD_NODE="smoke-tests-old-node"

NODE_VERSION=$(< "${CURDIR}/AIO_BASE" awk -F'[-.]' '{print $1"."$2"."$3}')
echo "AiO Node version: ${NODE_VERSION}"

function clean_allure_report() {
[[ "$ALLURE_GENERATE_REPORT" == false && -d "allure_report" ]] && rm -rf allure_report/* 2>/dev/null || true
}
Expand Down Expand Up @@ -106,7 +67,6 @@ function get_logs() {
echo -e "######################################################\n"
}


function extra_debug_logs {
echo "############################################"
echo "###### Extra cluster debug info ############"
Expand All @@ -120,26 +80,51 @@ function extra_debug_logs {

}

declare -a mandatory
mandatory=(
CLIENT_ID
USER_TOKEN
SMOKE_REGISTRY_TOKEN
SMOKE_REGISTRY_SECRET
)

missing=false
for var in "${mandatory[@]}"; do
if [[ -z "${!var:-}" ]]; then
echo "Environment variable $var must be set"
missing=true
fi
done

if [ "$missing" = true ]; then
exit 1
if [[ -n "${DEBUG}" ]]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

#import functions
source "${PWD}/test/smoke/functions.sh"

# check if all mandatory vars was defined
check_mandatory_vars

export KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-ingress-smoke-test}
export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/kind-config-$KIND_CLUSTER_NAME}"

# Variables required for pulling Docker image with pytest
SMOKE_REGISTRY_NAME="${SMOKE_REGISTRY_NAME:-dkr.wallarm.com}"
SMOKE_IMAGE_PULL_SECRET_NAME="pytest-registry-creds"

SMOKE_IMAGE_NAME="${SMOKE_IMAGE_NAME:-dkr.wallarm.com/tests/smoke-tests}"
SMOKE_IMAGE_TAG="${SMOKE_IMAGE_TAG:-latest}"

# Allure related variables
ALLURE_ENDPOINT="${ALLURE_ENDPOINT:-https://allure.wallarm.com}"
ALLURE_PROJECT_ID=${ALLURE_PROJECT_ID:-0}
ALLURE_RESULTS="${ALLURE_RESULTS:-/tests/_out/allure_report}"
ALLURE_UPLOAD_REPORT="${ALLURE_UPLOAD_REPORT:-false}"
ALLURE_GENERATE_REPORT="${ALLURE_GENERATE_REPORT:-false}"

# Pytest related variables
CLIENT_ID="${CLIENT_ID}"
WALLARM_API_CA_VERIFY="${WALLARM_API_CA_VERIFY:-true}"
WALLARM_API_HOST="${WALLARM_API_HOST}"
WALLARM_API_PRESET="${WALLARM_API_PRESET}"
NODE_BASE_URL="${NODE_BASE_URL:-http://wallarm-ingress-controller.default.svc}"
PYTEST_ARGS=$(echo "${PYTEST_ARGS:---allure-features=Node}" | xargs)
PYTEST_WORKERS="${PYTEST_WORKERS:-10}"
#TODO We need it here just to don't let test fail. Remove this variable when test will be fixed.
HOSTNAME_OLD_NODE="smoke-tests-old-node"

NODE_VERSION=$(< "${CURDIR}/AIO_BASE" awk -F'[-.]' '{print $1"."$2"."$3}')
echo "AiO Node version: ${NODE_VERSION}"

if [[ "${CI:-false}" == "false" ]]; then
trap 'kubectl delete pod pytest --now --ignore-not-found' EXIT ERR
# Colorize pytest output if run locally
Expand Down
Loading

0 comments on commit df8d72b

Please sign in to comment.