Skip to content

Commit 4e4d77d

Browse files
authored
Merge pull request #1 from Froot-NetSys/modify_workflow
Modify workflow
2 parents 02ea4bf + 41cb14c commit 4e4d77d

File tree

10 files changed

+187
-25
lines changed

10 files changed

+187
-25
lines changed

.github/workflows/run-k8s.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run K8s Evaluation
2+
3+
on:
4+
push:
5+
paths:
6+
- 'k8s_scenario.toml'
7+
8+
jobs:
9+
run-k8s:
10+
runs-on: ubuntu-latest
11+
if: github.event.repository.fork == true || github.ref != 'refs/heads/main'
12+
permissions:
13+
contents: write
14+
packages: read
15+
16+
steps:
17+
- name: Run assessment
18+
uses: ./.github/workflows/run-scenario.yml
19+
with:
20+
scenario-file: 'k8s_scenario.toml'
21+
benchmark-app: 'k8s'

.github/workflows/run-malt.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run MALT Evaluation
2+
3+
on:
4+
push:
5+
paths:
6+
- 'malt_scenario.toml'
7+
8+
jobs:
9+
run-malt:
10+
runs-on: ubuntu-latest
11+
if: github.event.repository.fork == true || github.ref != 'refs/heads/main'
12+
permissions:
13+
contents: write
14+
packages: read
15+
16+
steps:
17+
- name: Run assessment
18+
uses: ./.github/workflows/run-scenario.yml
19+
with:
20+
scenario-file: 'malt_scenario.toml'
21+
benchmark-app: 'malt'

.github/workflows/run-route.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run Route Evaluation
2+
3+
on:
4+
push:
5+
paths:
6+
- 'route_scenario.toml'
7+
8+
jobs:
9+
run-route:
10+
runs-on: ubuntu-latest
11+
if: github.event.repository.fork == true || github.ref != 'refs/heads/main'
12+
permissions:
13+
contents: write
14+
packages: read
15+
16+
steps:
17+
- name: Run assessment
18+
uses: ./.github/workflows/run-scenario.yml
19+
with:
20+
scenario-file: 'route_scenario.toml'
21+
benchmark-app: 'route'

.github/workflows/run-scenario.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
name: Run Scenario
22

33
on:
4-
push:
5-
paths:
6-
- 'scenario.toml'
4+
workflow_call:
5+
inputs:
6+
scenario-file:
7+
description: 'Path to the scenario TOML file'
8+
required: false
9+
default: 'scenario.toml'
10+
type: string
11+
benchmark-app:
12+
description: 'Type of application: malt, route, k8s'
13+
required: true
14+
default: 'malt'
15+
type: string
716

817
jobs:
918
run:
@@ -22,11 +31,26 @@ jobs:
2231
with:
2332
python-version: '3.11'
2433

34+
- name: Start KinD cluster (for k8s app)
35+
if: ${{ inputs.benchmark-app == 'k8s' }}
36+
uses: helm/kind-action@v1
37+
with:
38+
config: ./kind_config.yaml
39+
40+
- name: Create kubeconfig for KinD (for k8s app).
41+
if: ${{ inputs.benchmark-app == 'k8s' }}
42+
run: |
43+
mkdir -p ./kubeconfig
44+
cp "$HOME/.kube/config" "./kubeconfig/config"
45+
chmod +r ./kubeconfig/config
46+
# Modify the kubeconfig to use host.docker.internal
47+
sed -i 's/0.0.0.0/host.docker.internal/g' ./kubeconfig/config
48+
2549
- name: Install dependencies
2650
run: pip install tomli tomli-w pyyaml requests
2751

2852
- name: Generate docker-compose.yml
29-
run: python generate_compose.py --scenario scenario.toml
53+
run: python generate_compose.py --scenario ${{ inputs.scenario-file }} --app ${{ inputs.benchmark-app }}
3054

3155
- name: Pull images
3256
run: |
@@ -69,7 +93,10 @@ jobs:
6993
password: ${{ secrets.GHCR_TOKEN }}
7094

7195
- name: Run assessment
72-
run: docker compose up --timestamps --no-color --exit-code-from agentbeats-client --abort-on-container-exit
96+
run: |
97+
mkdir -p output
98+
chmod 777 output
99+
docker compose up --timestamps --no-color --exit-code-from agentbeats-client --abort-on-container-exit
73100
74101
- name: Record provenance
75102
run: python record_provenance.py --compose docker-compose.yml --output output/provenance.json

generate_compose.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def fetch_agent_info(agentbeats_id: str) -> dict:
6262
image: {green_image}
6363
platform: linux/amd64
6464
container_name: green-agent
65+
privileged: {privileged} # Needed for route-agent (to run Mininet).
6566
command: ["--host", "0.0.0.0", "--port", "{green_port}", "--card-url", "http://green-agent:{green_port}"]
6667
environment:{green_env}
6768
healthcheck:
@@ -73,6 +74,7 @@ def fetch_agent_info(agentbeats_id: str) -> dict:
7374
depends_on:{green_depends}
7475
networks:
7576
- agent-network
77+
{k8s_service_options}
7678
7779
{participant_services}
7880
agentbeats-client:
@@ -175,12 +177,19 @@ def format_depends_on(services: list) -> str:
175177
return "\n" + "\n".join(lines)
176178

177179

178-
def generate_docker_compose(scenario: dict[str, Any]) -> str:
180+
def generate_docker_compose(scenario: dict[str, Any], app: str) -> str:
179181
green = scenario["green_agent"]
180182
participants = scenario.get("participants", [])
181183

182184
participant_names = [p["name"] for p in participants]
183185

186+
# Expose kubeconfig and localhost for k8s app to allow communication with kind cluster
187+
k8s_service_options = """extra_hosts:
188+
- "host.docker.internal:host-gateway"
189+
volumes:
190+
- ./kubeconfig:/root/.kube/:ro
191+
"""
192+
184193
participant_services = "\n".join([
185194
PARTICIPANT_TEMPLATE.format(
186195
name=p["name"],
@@ -192,14 +201,21 @@ def generate_docker_compose(scenario: dict[str, Any]) -> str:
192201
])
193202

194203
all_services = ["green-agent"] + participant_names
204+
green_env = green.get("env", {})
205+
206+
if app == "k8s":
207+
# For k8s app, set KUBECONFIG env var for green agent
208+
green_env["KUBECONFIG"] = "/root/.kube/config"
195209

196210
return COMPOSE_TEMPLATE.format(
197211
green_image=green["image"],
198212
green_port=DEFAULT_PORT,
199-
green_env=format_env_vars(green.get("env", {})),
213+
green_env=format_env_vars(green_env),
200214
green_depends=format_depends_on(participant_names),
201215
participant_services=participant_services,
202-
client_depends=format_depends_on(all_services)
216+
client_depends=format_depends_on(all_services),
217+
privileged=str(app == "route").lower(),
218+
k8s_service_options=k8s_service_options if app == "k8s" else ""
203219
)
204220

205221

@@ -259,6 +275,7 @@ def generate_env_file(scenario: dict[str, Any]) -> str:
259275
def main():
260276
parser = argparse.ArgumentParser(description="Generate Docker Compose from scenario.toml")
261277
parser.add_argument("--scenario", type=Path)
278+
parser.add_argument("--app", type=str, choices=["malt", "route", "k8s"], default="malt", help="What app to generate for.")
262279
args = parser.parse_args()
263280

264281
if not args.scenario.exists():
@@ -268,7 +285,7 @@ def main():
268285
scenario = parse_scenario(args.scenario)
269286

270287
with open(COMPOSE_PATH, "w") as f:
271-
f.write(generate_docker_compose(scenario))
288+
f.write(generate_docker_compose(scenario, args.app))
272289

273290
with open(A2A_SCENARIO_PATH, "w") as f:
274291
f.write(generate_a2a_scenario(scenario))

k8s_scenario.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[green_agent]
2+
agentbeats_id = ""
3+
env = { LOG_LEVEL = "INFO" }
4+
5+
[[participants]]
6+
agentbeats_id = ""
7+
name = "k8s_operator"
8+
env = {}
9+
10+
[config]
11+
prompt_type = "zeroshot_base"
12+
num_queries = 1
13+
benchmark_path = "assessment_error_config.json"
14+
output_dir = "dump"
15+
microservice_dir = "/microservices-demo"
16+
max_iterations = 10
17+
regenerate_config = true

kind_config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
networking:
4+
# WARNING: It is _strongly_ recommended that you keep this the default
5+
# (127.0.0.1) for security reasons. However it is possible to change this.
6+
apiServerAddress: "0.0.0.0"
7+
# By default the API server listens on a random open port.
8+
# You may choose a specific port but probably don't need to in most cases.
9+
# Using a random port makes it easier to spin up multiple clusters.
10+
apiServerPort: 6443
11+
kubeadmConfigPatches:
12+
- |
13+
kind: ClusterConfiguration
14+
apiServer:
15+
certSANs:
16+
- "0.0.0.0"
17+
- "localhost"
18+
- "127.0.0.1"
19+
- "host.docker.internal"

malt_scenario.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[green_agent]
2+
agentbeats_id = ""
3+
env = { LOG_LEVEL = "INFO" }
4+
5+
[[participants]]
6+
agentbeats_id = ""
7+
name = "malt_operator"
8+
env = {}
9+
10+
[config]
11+
prompt_type = "zeroshot_base"
12+
num_queries = 1
13+
complexity_level = ["level1", "level2"]
14+
output_dir = "dump"
15+
output_file = "query_output.jsonl"
16+
benchmark_path = "assessment_queries.jsonl"
17+
regenerate_query = true

route_scenario.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[green_agent]
2+
agentbeats_id = ""
3+
env = { LOG_LEVEL = "INFO" }
4+
5+
[[participants]]
6+
agentbeats_id = ""
7+
name = "routing_operator"
8+
env = {}
9+
10+
[config]
11+
prompt_type = "zeroshot_base"
12+
num_queries = 1
13+
benchmark_path = "assessment_error_config.json"
14+
regenerate_benchmark = true
15+
output_dir = "dump"
16+
max_iterations = 10
17+
num_switches = 2
18+
num_hosts_per_subnet = 1

scenario.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)