From 3e365f848ec2ea7d632c6aae9625c71a6173c1aa Mon Sep 17 00:00:00 2001 From: Adriano Santos Date: Fri, 15 Dec 2023 15:21:58 -0300 Subject: [PATCH] Add some examples of flame pool configuration --- README.md | 80 ++++++++++++++++++- .../handler/flame_pool_handler.ex | 63 +++++++-------- .../lib/flame_k8s_controller/operator.ex | 16 ++++ 3 files changed, 124 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 07573d4..9967527 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ end You need to enable Flame in Kubernetes as well. See the example below: ```yaml +# my-application.yaml --- apiVersion: apps/v1 kind: Deployment @@ -55,8 +56,8 @@ spec: flame.org/otp-app: "my_app_release_name" spec: containers: - - image: eigr/spawn-operator:1.1.1 - name: spawn-operator + - image: eigr/flame-parent-example:1.1.1 + name: flame-parent-example resources: limits: cpu: 200m @@ -91,4 +92,77 @@ Now you can start scaling your applications with [Flame](https://github.com/phoe ## Configuration -TODO \ No newline at end of file +TODO + +### 1. Flame Runner Pool + +The Flame k8s Controller gives you the possibility to configure different runner profiles. These profiles will be used when creating PODs to run Runners in Kubernetes. +To configure a new Runner Pool, simply define the following yaml file and apply it to the Kubernetes cluster. + +```yaml +# my-runner.yaml +--- + apiVersion: flame.org/v1 + kind: FlamePool + metadata: + name: my-runner-pool + namespace: default + spec: + podTemplate: + spec: # This is a pod template specification. See https://kubernetes.io/docs/concepts/workloads/pods/#pod-templates + containers: + - env: + - name: MY_VAR + value: "my-value" + resources: + limits: + cpu: 200m + memory: 1Gi + requests: + cpu: 200m + memory: 2Gi + volumeMounts: + - mountPath: /app/.cache/bakeware/ + name: bakeware-cache + volumes: + - name: bakeware-cache + emptyDir: {} +``` + +Then: + +```sh +kubectl apply -f my-runner.yaml +``` + +Once this is done, simply add the annotation `flame.org/pool-config-ref` to your Deployment file. Example: + +```yaml +# my-application.yaml +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flame-parent-example + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: flame-parent-example + template: + metadata: + annotations: + flame.org/enabled: "true" + flame.org/pool-config-ref: "my-runner-pool" + spec: + containers: + - image: eigr/flame-parent-example:1.1.1 +... +``` + +You can also list all Runner pools configured on the system with the command: + +```sh +kubectl --all-namespaces get pools +``` \ No newline at end of file diff --git a/flame_k8s_controller/lib/flame_k8s_controller/handler/flame_pool_handler.ex b/flame_k8s_controller/lib/flame_k8s_controller/handler/flame_pool_handler.ex index becad05..62a21aa 100644 --- a/flame_k8s_controller/lib/flame_k8s_controller/handler/flame_pool_handler.ex +++ b/flame_k8s_controller/lib/flame_k8s_controller/handler/flame_pool_handler.ex @@ -10,38 +10,37 @@ defmodule FlameK8sController.Handler.FlamePoolHandler do spec: podTemplate: spec: - containers: - - env: - - name: PHX_SERVER - value: "false" - - name: MIX_ENV - value: prod - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - name: spawn-operator - resources: - limits: - cpu: 200m - memory: 200Mi - requests: - cpu: 200m - memory: 200Mi - volumeMounts: - - mountPath: /app/.cache/bakeware/ - name: bakeware-cache - volumes: - - name: bakeware-cache - emptyDir: {} + containers: + - env: + - name: PHX_SERVER + value: "false" + - name: MIX_ENV + value: prod + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + resources: + limits: + cpu: 200m + memory: 200Mi + requests: + cpu: 200m + memory: 200Mi + volumeMounts: + - mountPath: /app/.cache/bakeware/ + name: bakeware-cache + volumes: + - name: bakeware-cache + emptyDir: {} """ @behaviour Pluggable diff --git a/flame_k8s_controller/lib/flame_k8s_controller/operator.ex b/flame_k8s_controller/lib/flame_k8s_controller/operator.ex index a67548e..c866faf 100644 --- a/flame_k8s_controller/lib/flame_k8s_controller/operator.ex +++ b/flame_k8s_controller/lib/flame_k8s_controller/operator.ex @@ -20,6 +20,10 @@ defmodule FlameK8sController.Operator do %{ query: K8s.Client.watch("flame.org/v1", "FlameRunner", namespace: watching_namespace), controller: FlameK8sController.Controller.FlameRunner + }, + %{ + query: K8s.Client.watch("flame.org/v1", "FlamePool", namespace: watching_namespace), + controller: FlameK8sController.Controller.FlamePool } ] end @@ -39,6 +43,18 @@ defmodule FlameK8sController.Operator do group: "flame.org", scope: :Namespaced, versions: [FlameK8sController.Versions.Api.V1.FlameRunner] + ), + Bonny.API.CRD.new!( + names: + Bonny.API.CRD.kind_to_names("FlamePool", [ + "framepool", + "framepools", + "pool", + "pools" + ]), + group: "flame.org", + scope: :Namespaced, + versions: [FlameK8sController.Versions.Api.V1.FlameRunner] ) ] end