Skip to content

Commit

Permalink
Run E2E test when testing mysql image
Browse files Browse the repository at this point in the history
Signed-off-by: d-kuro <[email protected]>
  • Loading branch information
d-kuro committed Jul 22, 2023
1 parent 1d6ae3a commit 1898276
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 42 deletions.
46 changes: 5 additions & 41 deletions .github/workflows/build-mysql-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,47 +56,11 @@ jobs:
run: |
container-structure-test test --image ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }} --config ./containers/mysql/${{ matrix.mysql-version }}/container-structure-test.yaml
- name: Create kind cluster
run: kind create cluster --name=moco --config=./e2e/kind-config_actions.yaml --image=kindest/node:v${{ matrix.k8s-version }} --wait 1m

- name: Load mysqld image
run: kind load docker-image ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }} --name moco

- name: Install MOCO
run: |
kubectl apply -f https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml
kubectl -n cert-manager wait --for=condition=available --timeout=180s --all deployments
kubectl apply -f https://github.com/cybozu-go/moco/releases/latest/download/moco.yaml
kubectl -n moco-system wait --for=condition=available --timeout=180s --all deployments
- name: Create MySQLCluster
run: |
cat > mycluster.yaml <<'EOF'
apiVersion: moco.cybozu.com/v1beta1
kind: MySQLCluster
metadata:
namespace: default
name: test
spec:
replicas: 3
podTemplate:
spec:
containers:
- name: mysqld
image: ghcr.io/cybozu-go/moco/mysql:${{ matrix.mysql-version }}
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
EOF
kubectl apply -f mycluster.yaml
- name: Wait for MySQLCluster
run: kubectl wait -n default --for=condition=Available mysqlcluster/test --timeout=180s
- uses: ./.github/workflows/e2e.yaml
with:
k8s-version: ${{ matrix.k8s-version }}
mysql-version: ${{ matrix.mysql-version }}
use-local-mysql-image: true

build:
if: github.ref == 'refs/heads/main'
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
k8s-version:
required: true
type: string
use-local-mysql-image:
required: false
type: boolean

jobs:
e2e:
Expand All @@ -24,8 +27,16 @@ jobs:
sudo swapoff -a
cat swapon.txt | tail -n+2 | awk '$2=="file" {print $1}' | sudo xargs --no-run-if-empty rm
- run: sudo mkdir /mnt/local-path-provisioner0 /mnt/local-path-provisioner1 /mnt/local-path-provisioner2
- run: make start KUBERNETES_VERSION=${{ inputs.k8s-version }} MYSQL_VERSION=${{ inputs.mysql-version }} KIND_CONFIG=kind-config_actions.yaml

- name: Setup test cluster
run: make start KUBERNETES_VERSION=${{ inputs.k8s-version }} MYSQL_VERSION=${{ inputs.mysql-version }} KIND_CONFIG=kind-config_actions.yaml
if: ${{ inputs.use-local-mysql-image }} == 'false'
working-directory: e2e
- name: Setup test cluster with local mysql image
run: make start KUBERNETES_VERSION=${{ inputs.k8s-version }} MYSQL_VERSION=${{ inputs.mysql-version }} KIND_CONFIG=kind-config_actions.yaml USE_LOCAL_MYSQL_IMAGE=1
if: ${{ inputs.use-local-mysql-image }} == 'true'
working-directory: e2e

- run: make test
working-directory: e2e
- run: make logs
Expand Down
6 changes: 6 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export MYSQL_VERSION KUBECTL KUBECONFIG
AGENT_DIR =
AGENT_IMAGE := ghcr.io/cybozu-go/moco-agent:$(shell awk '/moco-agent/ {print substr($$2, 2)}' ../go.mod)

## to test development version of mysqld, run make with USE_LOCAL_MYSQL_IMAGE=1
USE_LOCAL_MYSQL_IMAGE =

## We need to switch the configuration of kind on GitHub Actions
KIND_CONFIG = kind-config.yaml

Expand All @@ -36,6 +39,9 @@ start: $(KIND) $(KUBECTL) $(KUSTOMIZE) $(KUBECTL_MOCO)
ifdef AGENT_DIR
cd $(AGENT_DIR); docker buildx build --load --no-cache -t $(AGENT_IMAGE) .
$(KIND) load docker-image $(AGENT_IMAGE) --name=moco
endif
ifdef USE_LOCAL_MYSQL_IMAGE
$(KIND) load docker-image ghcr.io/cybozu-go/moco/mysql:$(MYSQL_VERSION) --name=moco
endif
$(KUBECTL) apply -f https://github.com/jetstack/cert-manager/releases/download/v$(CERT_MANAGER_VERSION)/cert-manager.yaml
$(KUBECTL) -n cert-manager wait --for=condition=available --timeout=180s --all deployments
Expand Down

0 comments on commit 1898276

Please sign in to comment.