Skip to content

Ensure ImageConfig which is mounted to cass-operator works as it woul… #29

Ensure ImageConfig which is mounted to cass-operator works as it woul…

Ensure ImageConfig which is mounted to cass-operator works as it woul… #29

---
name: Integration Tests and Release
on:
pull_request:
paths:
- 'pkg/**'
- 'cmd/**'
- 'charts/**'
- 'tests/integration/**'
- '.github/workflows/**'
push:
branches:
branches-ignore:
- 'docs'
- 'docs-v1'
- 'docs-v2'
paths:
- 'pkg/**'
- 'cmd/**'
- 'charts/**'
- 'tests/integration/**'
- '.github/workflows/**'
release:
types:
- published
workflow_dispatch:
inputs:
kubernetes_version:
description: 'Kubernetes version'
required: true
default: 'v1.21.1'
tags:
description: 'Run integration tests with different versions of K8s'
jobs:
set_k8s_version:
runs-on: ubuntu-latest
outputs:
kubernetes_version: ${{ steps.k8s-version.outputs.kubernetes_version }}
steps:
- id: k8s-version
name: Set Kubernetes version
env:
DEFAULT_K8S_VERSION: v1.21.1
run: |
if [[ -z "${{ github.event.inputs.kubernetes_version }}" ]]; then
echo '::set-output name=kubernetes_version::${{ env.DEFAULT_K8S_VERSION }}'
else
echo '::set-output name=kubernetes_version::${{ github.event.inputs.kubernetes_version }}'
fi
build_docker_images:
name: Build Docker Images
needs: [set_k8s_version]
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-integ-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-integ-
- name: Create env variables
run: ./.github/scripts/env_variables.sh
- name: Create chart release for the upgrader image
run: |
scripts/install-yq.sh ${{ env.YQ_VERSION }}
VER=$(bin/yq eval '.version' charts/k8ssandra/Chart.yaml)
mkdir -p build/$VER
cp -rv charts/* build/$VER/
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: cmd/k8ssandra-client/Dockerfile
push: false
tags: k8ssandra/k8ssandra-tools:latest
platforms: linux/amd64
outputs: type=docker,dest=/tmp/k8ssandra-tools.tar
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Upload k8ssandra-tools image
uses: actions/upload-artifact@v2
with:
name: k8ssandra-tools
path: /tmp/k8ssandra-tools.tar
integration-tests:
runs-on: ubuntu-latest
needs: [set_k8s_version, build_docker_images]
strategy:
fail-fast: false
matrix:
k8s_version: ["${{ needs.set_k8s_version.outputs.kubernetes_version }}"]
cassandra_version: ["3.11.10", "4.0.0"]
scenario:
- "TestMedusaDeploymentScenario/\"S3\""
- "TestMedusaDeploymentScenario/\"Minio\""
- "TestMedusaDeploymentScenario/\"local\""
- "TestMedusaDeploymentScenario/\"azure_blobs\""
- "TestReaperDeploymentScenario"
- "TestMonitoringDeploymentScenario"
- "TestStargateDeploymentScenario"
#- "TestRestoreAfterUpgrade"
#- "TestUpgradeScenario"
- "TestCustomCassandraConfiguration"
exclude:
- scenario: "TestUpgradeScenario"
k8s_version: "v1.22.2"
- scenario: "TestRestoreAfterUpgrade"
k8s_version: "v1.22.2"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-k8ssandra-buildx
restore-keys: |
${{ runner.os }}-k8ssandra-buildx
- name: Create env variables
run: ./.github/scripts/env_variables.sh
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: ${{ env.HELM_VERSION }}
- name: Kind kube-proxy issue workaround
run: sudo sysctl net/netfilter/nf_conntrack_max=524288
- name: Download k8ssandra-tools image
uses: actions/download-artifact@v2
with:
name: k8ssandra-tools
path: /tmp
- name: Load Docker images
run: |
docker load --input /tmp/k8ssandra-tools.tar
- name: Install Dependencies
run: |
set -x
sudo apt-get update || echo "something went slightly wrong with apt-get update"
# install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# Update Helm dependencies
./scripts/update-helm-deps.sh
- name: Write Secrets
run: |
printf "%s" '${{ secrets.K8SSANDRA_MEDUSA_SECRET_S3 }}' > ~/medusa_secret_s3.yaml
printf "%s" '${{ secrets.K8SSANDRA_MEDUSA_SECRET_AZURE }}' > ~/medusa_secret_azure.yaml
- name: Check if integration tests can run
env:
SCENARIO: ${{ matrix.scenario }}
run: |
if [[ $SCENARIO == *"S3"* ]]; then
# Medusa on S3 requires a secret. Skip integration tests if the secret is absent.
if [[ -s ~/medusa_secret_s3.yaml ]]; then
echo "IT_CAN_RUN=yes" >> $GITHUB_ENV
fi
elif [[ $SCENARIO == *"azure"* ]]; then
# Medusa on Azure requires a secret. Skip integration tests if the secret is absent.
if [[ -s ~/medusa_secret_azure.yaml ]]; then
echo "IT_CAN_RUN=yes" >> $GITHUB_ENV
fi
else
echo "IT_CAN_RUN=yes" >> $GITHUB_ENV
fi
- name: Run Integration Tests
if: ${{ env.IT_CAN_RUN == 'yes' }}
env:
SCENARIO: ${{ matrix.scenario }}
K8SSANDRA_CASSANDRA_VERSION: ${{ matrix.cassandra_version }}
K8SSANDRA_MEDUSA_BUCKET_NAME: ${{ secrets.K8SSANDRA_MEDUSA_BUCKET_NAME }}
K8SSANDRA_MEDUSA_BUCKET_REGION: ${{ secrets.K8SSANDRA_MEDUSA_BUCKET_REGION }}
run: |
# Set a valid name for the artifacts in case of failure
echo "ARTIFACT_NAME=k8s-artifacts-${K8SSANDRA_CASSANDRA_VERSION}-$(echo $SCENARIO|tr '":/' '___')" >> $GITHUB_ENV
make kind-integ-test TESTS="$SCENARIO" GO_FLAGS="-v" CLUSTER_CLEANUP="success"
- name: Collect artifacts
if: ${{ failure() }}
env:
ARTIFACTS_DIR: artifacts
run: tests/integration/scripts/collect_artifacts.sh
- uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: k8s-artifacts-${{ env.ARTIFACT_NAME }}
path: artifacts/
# Uncomment to run with SSH on failure
- name: Setup tmate session
if: "failure() && contains(github.event.head_commit.message, '[SSH]')"
uses: mxschmitt/action-tmate@v3
timeout-minutes: 10
release:
# Release job should never run on forks and should only trigger on main pushes and published releases
if: |
( github.event_name == 'release' && github.event.action == 'published' )
|| ( github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'k8ssandra' )
runs-on: ubuntu-latest
needs: integration-tests
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update PATH
run: |
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
- name: Create env variables
run: ./.github/scripts/env_variables.sh
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: ${{ env.HELM_VERSION }}
- name: Install and validate tool versions
run: |
scripts/install-yq.sh ${{ env.YQ_VERSION }}
helm version
yq -V
- name: Update chart dependencies
run: |
scripts/update-helm-deps.sh
- name: Compute release chart version
id: compute_next_version
run: |
DATE_TIME=$(date '+%Y%m%d%H%M%S')
RELEASE_VERSION=$(echo $(yq e '.version' charts/k8ssandra/Chart.yaml) | sed "s/-.*/-${DATE_TIME}-${GITHUB_SHA::8}/")
echo "Release version is: $RELEASE_VERSION"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
echo "::set-output name=RELEASE_VERSION::${RELEASE_VERSION}"
- name: Update Helm chart version
run: |
yq eval ".version |= \"${RELEASE_VERSION}\"" charts/k8ssandra/Chart.yaml -i
cat charts/k8ssandra/Chart.yaml
- name: Create working directory and copy charts
run: |
mkdir -p build/$RELEASE_VERSION
cp -rv charts/* build/$RELEASE_VERSION/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-integ-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-integ-
- name: Update k8ssandra-tools cleaner tag
run: |
yq eval ".cleaner.image.tag |= \"${RELEASE_VERSION}\"" charts/k8ssandra/values.yaml -i
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: cmd/k8ssandra-client/Dockerfile
push: true
tags: k8ssandra/k8ssandra-tools:latest, k8ssandra/k8ssandra-tools:${{ steps.compute_next_version.outputs.RELEASE_VERSION }}
platforms: linux/amd64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Generate package archives
run: |
ls | while read c; do
if [[ -d $c ]]; then
helm package $c
fi
done
working-directory: build/${{ steps.compute_next_version.outputs.RELEASE_VERSION }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
# Helm Release
- uses: google-github-actions/setup-gcloud@v0
with:
version: '318.0.0'
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Download current index from Google Cloud
env:
GCP_HELM_BUCKET_NAME: ${{ secrets.GCP_HELM_BUCKET_NAME }}
run: gsutil cp gs://$GCP_HELM_BUCKET_NAME/stable/index.yaml ./
working-directory: build/${{ steps.compute_next_version.outputs.RELEASE_VERSION }}
- name: Regenerate Helm index
env:
GCP_HELM_BUCKET_NAME: ${{ secrets.GCP_HELM_BUCKET_NAME }}
run: helm repo index . --merge index.yaml --url "https://$GCP_HELM_BUCKET_NAME/stable/"
working-directory: build/${{ steps.compute_next_version.outputs.RELEASE_VERSION }}
- name: Upload packages and index
env:
GCP_HELM_BUCKET_NAME: ${{ secrets.GCP_HELM_BUCKET_NAME }}
run: |
gsutil cp ./*.tgz gs://$GCP_HELM_BUCKET_NAME/stable/
gsutil cp ./index.yaml gs://$GCP_HELM_BUCKET_NAME/stable/
working-directory: build/${{ steps.compute_next_version.outputs.RELEASE_VERSION }}
# GitHub Release
- name: Upload chart package to GitHub Release
uses: fnkr/github-action-ghr@v1
if: github.event_name == 'release' && github.event.action == 'published'
env:
GHR_PATH: build/${{ steps.compute_next_version.outputs.RELEASE_VERSION }}/k8ssandra-${{ env.RELEASE_VERSION }}.tgz
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}