Merge "bigtrace: Add minikube integration" into main
diff --git a/python/perfetto/bigtrace/api.py b/python/perfetto/bigtrace/api.py
index 97c5b92..9b67932 100644
--- a/python/perfetto/bigtrace/api.py
+++ b/python/perfetto/bigtrace/api.py
@@ -25,8 +25,10 @@
 
 class Bigtrace:
 
-  def __init__(self, wait_for_ready_for_testing=False):
-    channel = grpc.insecure_channel("localhost:5051")
+  def __init__(self,
+               orchestrator_address="127.0.0.1:5051",
+               wait_for_ready_for_testing=False):
+    channel = grpc.insecure_channel(orchestrator_address)
     self.stub = BigtraceOrchestratorStub(channel)
     self.wait_for_ready_for_testing = wait_for_ready_for_testing
 
diff --git a/src/bigtrace/orchestrator-deployment.yaml b/src/bigtrace/orchestrator-deployment.yaml
new file mode 100644
index 0000000..ba1db87
--- /dev/null
+++ b/src/bigtrace/orchestrator-deployment.yaml
@@ -0,0 +1,35 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: orchestrator-deployment
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: orchestrator-deployment
+  template:
+    metadata:
+      labels:
+        app: orchestrator-deployment
+    spec:
+      containers:
+      - image: docker.io/library/orchestrator_image:latest
+        imagePullPolicy: Never
+        name: orchestrator
+        ports:
+        - containerPort: 5051
+          protocol: TCP
diff --git a/src/bigtrace/orchestrator-service.yaml b/src/bigtrace/orchestrator-service.yaml
new file mode 100644
index 0000000..23009f6
--- /dev/null
+++ b/src/bigtrace/orchestrator-service.yaml
@@ -0,0 +1,27 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: orchestrator
+spec:
+  type: NodePort
+  ports:
+  - protocol: TCP
+    nodePort: 30051
+    port: 5051
+    targetPort: 5051
+  selector:
+    app: orchestrator-deployment
diff --git a/src/bigtrace/orchestrator/Dockerfile b/src/bigtrace/orchestrator/Dockerfile
index 1a08874..2ca0905 100644
--- a/src/bigtrace/orchestrator/Dockerfile
+++ b/src/bigtrace/orchestrator/Dockerfile
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-FROM debian
+FROM debian:12
 
 RUN apt update && apt install -y git python3 curl build-essential
 RUN  git clone --depth 1 https://android.googlesource.com/platform/external/perfetto/
diff --git a/src/bigtrace/orchestrator/orchestrator_main.cc b/src/bigtrace/orchestrator/orchestrator_main.cc
index 8e40cf1..c065781 100644
--- a/src/bigtrace/orchestrator/orchestrator_main.cc
+++ b/src/bigtrace/orchestrator/orchestrator_main.cc
@@ -162,7 +162,11 @@
                                    ? "ipv4:"
                                    : options->name_resolution_scheme;
 
-  uint32_t pool_size = options->pool_size == 0 ? 5 : options->pool_size;
+  uint32_t pool_size = options->pool_size == 0
+                           ? std::thread::hardware_concurrency()
+                           : options->pool_size;
+
+  PERFETTO_DCHECK(pool_size);
 
   if (worker_address_list.empty()) {
     // Use a set of n workers incrementing from a starting port
diff --git a/src/bigtrace/worker-deployment.yaml b/src/bigtrace/worker-deployment.yaml
new file mode 100644
index 0000000..d9b66ad
--- /dev/null
+++ b/src/bigtrace/worker-deployment.yaml
@@ -0,0 +1,34 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: worker
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: worker
+  template:
+    metadata:
+      labels:
+        app: worker
+    spec:
+      containers:
+      - name: worker
+        image: docker.io/library/worker_image:latest
+        imagePullPolicy: Never
+        ports:
+        - containerPort: 5052
diff --git a/src/bigtrace/worker-service.yaml b/src/bigtrace/worker-service.yaml
new file mode 100644
index 0000000..a6abf3d
--- /dev/null
+++ b/src/bigtrace/worker-service.yaml
@@ -0,0 +1,26 @@
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+apiVersion: v1
+kind: Service
+metadata:
+  name: worker
+spec:
+  type: NodePort
+  ports:
+  - protocol: TCP
+    port: 5052
+    targetPort: 5052
+  selector:
+    app: worker
diff --git a/src/bigtrace/worker/Dockerfile b/src/bigtrace/worker/Dockerfile
index 40c7e88..65e22fc 100644
--- a/src/bigtrace/worker/Dockerfile
+++ b/src/bigtrace/worker/Dockerfile
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-FROM debian
+FROM debian:12
 
 RUN apt update && apt install -y git python3 curl build-essential
 RUN  git clone --depth 1 https://android.googlesource.com/platform/external/perfetto/
diff --git a/tools/setup_minikube_cluster.sh b/tools/setup_minikube_cluster.sh
new file mode 100755
index 0000000..c2549c7
--- /dev/null
+++ b/tools/setup_minikube_cluster.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cd $PROJECT_ROOT/src/bigtrace
+
+minikube start
+eval $(minikube docker-env)
+
+docker build -t orchestrator_image ./orchestrator
+docker build -t worker_image ./worker
+
+minikube kubectl -- apply -f worker-deployment.yaml
+minikube kubectl -- apply -f worker-service.yaml
+minikube kubectl -- apply -f orchestrator-deployment.yaml
+minikube kubectl -- apply -f orchestrator-service.yaml
+
+eval $(minikube docker-env -u)
\ No newline at end of file