-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
262 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ on: | |
|
||
env: | ||
MIX_ENV: test | ||
KUBECONFIG: /home/runner/.kube/config | ||
|
||
jobs: | ||
code-quality: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Integration Tests | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
env: | ||
MIX_ENV: test | ||
KUBECONFIG: /home/runner/.kube/config | ||
|
||
jobs: | ||
code-quality: | ||
name: Integration Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 | ||
|
||
- name: Setup elixir | ||
id: beam | ||
uses: erlef/setup-beam@v1 | ||
with: | ||
version-file: .tool-versions | ||
version-type: strict | ||
install-rebar: true | ||
install-hex: true | ||
|
||
- name: Retrieve Build Cache | ||
uses: actions/cache@v3 | ||
id: build-folder-cache | ||
with: | ||
path: _build/test | ||
key: ${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-build-test-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} | ||
|
||
- name: Retrieve Mix Dependencies Cache | ||
uses: actions/cache@v3 | ||
id: mix-cache | ||
with: | ||
path: deps | ||
key: ${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} | ||
|
||
- name: Install Mix Dependencies | ||
run: mix deps.get | ||
|
||
- uses: engineerd/[email protected] | ||
id: kind | ||
with: | ||
version: v0.20.0 | ||
name: flame-integration-test | ||
|
||
- name: Integration Tests | ||
run: MIX_ENV=test mix test --only integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Config | ||
|
||
config :flame, :terminator, log: :debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
FROM hexpm/elixir:1.15.7-erlang-26.1.2-debian-buster-20231009 | ||
|
||
ENV MIX_ENV=test \ | ||
MIX_HOME=/opt/mix \ | ||
HEX_HOME=/opt/hex | ||
|
||
RUN mix local.hex --force && \ | ||
mix local.rebar --force && \ | ||
apt-get update && apt-get install -y git | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
RUN mix deps.get --only-prod && \ | ||
mix deps.clean --unused && \ | ||
mix deps.compile | ||
|
||
CMD ["sh", "-c", "iex --name ${RELEASE_NODE} --cookie nosecret -S mix run -e 'FlameK8sBackend.IntegrationTestRunner.runner()'"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule FlameK8sBackend.IntegrationTest do | ||
use ExUnit.Case | ||
|
||
setup_all do | ||
{clusters_out, exit_code} = System.cmd("kind", ~w(get clusters)) | ||
assert 0 == exit_code, "kind is not installed. Please install kind." | ||
|
||
if not (clusters_out | ||
|> String.split("\n", trim: true) | ||
|> Enum.member?("flame-integration-test")) do | ||
exit_code = Mix.Shell.IO.cmd("kind create cluster --name flame-integration-test") | ||
assert 0 == exit_code, "Could not create kind cluster 'flame-integration-test'" | ||
end | ||
|
||
Mix.Shell.IO.cmd( | ||
"docker build -f test/integration/Dockerfile.integration . -t flamek8sbackend:integration" | ||
) | ||
|
||
Mix.Shell.IO.cmd( | ||
"kind load docker-image --name flame-integration-test flamek8sbackend:integration" | ||
) | ||
|
||
Mix.Shell.IO.cmd("kubectl config set-context kind-flame-integration-test") | ||
Mix.Shell.IO.cmd("kubectl delete -f test/integration/manifest.yaml") | ||
Mix.Shell.IO.cmd("kubectl apply -f test/integration/manifest.yaml") | ||
|
||
on_exit(fn -> | ||
Mix.Shell.IO.cmd("kubectl delete -f test/integration/manifest.yaml") | ||
end) | ||
|
||
:ok | ||
end | ||
|
||
defp assert_logs_eventually(_pattern, timeout) when timeout < 0 do | ||
:not_found | ||
end | ||
|
||
defp assert_logs_eventually(pattern, timeout) do | ||
with {logs, 0} <- System.cmd("kubectl", ~w"-n integration logs integration"), | ||
true <- Regex.match?(pattern, logs) do | ||
:ok | ||
else | ||
_ -> | ||
Process.sleep(300) | ||
assert_logs_eventually(pattern, timeout - 300) | ||
end | ||
end | ||
|
||
@tag :integration | ||
test "check the logs" do | ||
assert :ok == assert_logs_eventually(~r/Result is :flame_ok/, 30_000), | ||
"Logs were not found" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: integration | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: integration | ||
namespace: integration | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
namespace: integration | ||
name: pod-mgr | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["pods"] | ||
verbs: ["create", "get", "list", "delete", "patch"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: integration-pod-mgr | ||
namespace: integration | ||
subjects: | ||
- kind: ServiceAccount | ||
name: integration | ||
namespace: integration | ||
roleRef: | ||
kind: Role | ||
name: pod-mgr | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: integration | ||
namespace: integration | ||
labels: | ||
app: flame_test | ||
spec: | ||
serviceAccountName: integration | ||
containers: | ||
- name: integration | ||
image: flamek8sbackend:integration | ||
command: ["sh", "-c"] | ||
args: ["iex --name flame_test@$(POD_IP) --cookie nosecret -S mix run -e FlameK8sBackend.IntegrationTestRunner.run_flame"] | ||
resources: | ||
requests: | ||
cpu: 300m | ||
memory: 300Mi | ||
limits: | ||
cpu: 300m | ||
memory: 300Mi | ||
env: | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: metadata.name | ||
- name: POD_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: metadata.namespace | ||
- name: POD_IP | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: status.podIP | ||
- name: RELEASE_DISTRIBUTION | ||
value: name | ||
- name: RELEASE_NODE | ||
value: flame_test@$(POD_IP) | ||
ports: | ||
- containerPort: 80 | ||
name: integration | ||
restartPolicy: Always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ExUnit.start() | ||
ExUnit.start(exclude: [:integration]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule FlameK8sBackend.IntegrationTestRunner do | ||
require Logger | ||
|
||
def setup() do | ||
Application.ensure_all_started(:flame) | ||
|
||
children = [{ | ||
FLAME.Pool, | ||
name: IntegrationTest.Runner, | ||
min: 0, | ||
max: 2, | ||
idle_shutdown_after: 1_000, | ||
backend: {FLAMEK8sBackend, insecure_skip_tls_verify: true}, | ||
log: :debug | ||
}] | ||
|
||
Supervisor.start_link(children, strategy: :one_for_one) | ||
end | ||
|
||
def run_flame() do | ||
setup() | ||
|
||
result = | ||
FLAME.call(IntegrationTest.Runner, fn -> | ||
:flame_ok | ||
end) | ||
|
||
Logger.info("Result is #{inspect(result)}") | ||
end | ||
|
||
def runner() do | ||
setup() | ||
Process.sleep(60_000) | ||
end | ||
end |