Skip to content

Commit

Permalink
Use CRD parameter to configure ActorHost
Browse files Browse the repository at this point in the history
  • Loading branch information
sleipnir committed Jan 21, 2023
1 parent 8801941 commit 8001913
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 54 deletions.
5 changes: 3 additions & 2 deletions examples/k8s/elixir-native/host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ apiVersion: spawn-eigr.io/v1
kind: ActorHost
metadata:
name: spawn-dice-game
system: game-system
namespace: default
annotations:
spawn-eigr.io/actor-system: game-system
spec:
host:
embedded: true
image: eigr/dice-game-example:0.1.1
image: eigr/dice-game-example:0.5.3
ports:
- name: "http"
containerPort: 8800
49 changes: 46 additions & 3 deletions examples/k8s/simple/host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,53 @@
apiVersion: spawn-eigr.io/v1
kind: ActorHost
metadata:
name: spawn-springboot-example-1 # Mandatory. Name of the Node containing Actor Host Functions
name: spawn-springboot-example # Mandatory. Name of the Node containing Actor Host Functions
namespace: default # Optional. Default namespace is "default"
labels:
spawn-eigr.io.actor-system: test-1
annotations:
# Mandatory. Name of the ActorSystem declared in ActorSystem CRD
spawn-eigr.io/actor-system: spawn-system

# Optional. User Function Host Address
spawn-eigr.io/app-host: "0.0.0.0"

# Optional. User Function Host Port
spawn-eigr.io/app-port:
"8090"

# Optional
spawn-eigr.io/cluster-poling-interval: "3000"

# Optional. Default "sidecar". Possible values are "sidecar" | "daemon"
spawn-eigr.io/sidecar-mode: "sidecar"

# Optional
spawn-eigr.io/sidecar-image-tag: "docker.io/eigr/spawn-proxy:0.5.0-rc.13"

# Optional. Default 9001
spawn-eigr.io/sidecar-http-port: "9001"

# Optional. Default false
spawn-eigr.io/sidecar-uds-enabled: "false"

# Optional. Default "/var/run/spawn.sock"
spawn-eigr.io/sidecar-uds-socket-path: "/var/run/sidecar.sock"

# Optional. Default false
spawn-eigr.io/sidecar-metrics-disabled: "false"

# Optional. Default "9090"
spawn-eigr.io/sidecar-metrics-port: "9090"

# Optional. Default false
spawn-eigr.io/sidecar-metrics-log-console: "false"

# Optional. Default "native".
# Using Phoenix PubSub Adapter.
# Possible values: "native" | "nats"
spawn-eigr.io/sidecar-pubsub-adapter: "native"

# Optional. Default "nats://127.0.0.1:4222"
spawn-eigr.io/sidecar-pubsub-nats-hosts: "nats://127.0.0.1:4222"
spec:
# sidecar:
# image: docker.io/eigr/spawn-proxy:0.5.0
Expand Down
2 changes: 1 addition & 1 deletion examples/k8s/simple/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: spawn-eigr.io/v1
kind: ActorSystem
metadata:
name: test-1 # Mandatory. Name of the state store
name: spawn-system # Mandatory. Name of the state store
namespace: default # Optional. Default namespace is "default"
spec:
cluster: # Optional
Expand Down
2 changes: 1 addition & 1 deletion examples/k8s/test-operator/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
image: eigr/spawn-operator:0.5.0-rc.12
image: eigr/spawn-operator:0.5.0-rc.13
name: spawn-operator
resources:
limits:
Expand Down
2 changes: 1 addition & 1 deletion examples/k8s/test/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
- secretRef:
name: spawn-system-secret
name: actor-host-function
image: eigr/spawn-proxy:0.5.0-rc.12
image: eigr/spawn-proxy:0.5.0-rc.13
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8800
Expand Down
2 changes: 1 addition & 1 deletion examples/k8s/test/proxy-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
labels:
spawn-eigr.io/controller.version: 0.5.0-rc.12
spawn-eigr.io/controller.version: 0.5.0-rc.13
name: spawn-proxy-test
namespace: default
spec:
Expand Down
4 changes: 3 additions & 1 deletion lib/actors/config/vapor_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Actors.Config.Vapor do
bindings: [
{:app_name, "PROXY_APP_NAME", default: Config.Name.generate(), required: false},
{:http_port, "PROXY_HTTP_PORT",
default: 4000, map: &String.to_integer/1, required: false},
default: 9001, map: &String.to_integer/1, required: false},
{:deployment_mode, "PROXY_DEPLOYMENT_MODE", default: "sidecar", required: false},
{:node_host_interface, "NODE_IP", default: "0.0.0.0", required: false},
{:proxy_cluster_strategy, "PROXY_CLUSTER_STRATEGY", default: "gossip", required: false},
Expand All @@ -44,6 +44,8 @@ defmodule Actors.Config.Vapor do
{:proxy_sock_addr, "PROXY_UDS_ADDRESS",
default: "/var/run/spawn.sock", required: false},
{:proxy_host_interface, "POD_IP", default: "0.0.0.0", required: false},
{:proxy_disable_metrics, "SPAWN_DISABLE_METRICS", default: "false", required: false},
{:proxy_console_metrics, "SPAWN_CONSOLE_METRICS", default: "false", required: false},
{:user_function_host, "USER_FUNCTION_HOST", default: "0.0.0.0", required: false},
{:user_function_port, "USER_FUNCTION_PORT",
default: 8090, map: &String.to_integer/1, required: false},
Expand Down
2 changes: 1 addition & 1 deletion spawn_operator/spawn_operator/config/config.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Config

config :spawn_operator,
proxy_image: "docker.io/eigr/spawn-proxy:0.5.0-rc.12"
proxy_image: "docker.io/eigr/spawn-proxy:0.5.0-rc.13"

config :bonny,
# Add each Controller module for this operator to load here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Mix.Tasks.Bonny.Gen.Manifest.SpawnOperatorCustomizer do
valueFrom: %{fieldRef: %{fieldPath: "spec.serviceAccountName"}}
}
],
image: "eigr/spawn-operator:0.5.0-rc.12",
image: "eigr/spawn-operator:0.5.0-rc.13",
name: "spawn-operator",
resources: %{
limits: %{cpu: "200m", memory: "200Mi"},
Expand Down
49 changes: 42 additions & 7 deletions spawn_operator/spawn_operator/lib/spawn_operator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ defmodule SpawnOperator do
def get_args(resource) do
_metadata = K8s.Resource.metadata(resource)
labels = K8s.Resource.labels(resource)
annotations = K8s.Resource.annotations(resource)
resource_annotations = K8s.Resource.annotations(resource)
annotations = get_annotations_or_defaults(resource_annotations)

name = K8s.Resource.name(resource)
ns = K8s.Resource.namespace(resource) || "default"

system =
if K8s.Resource.has_label?(resource, @actorsystem_label),
do: K8s.Resource.label(resource, @actorsystem_label),
else: @actorsystem_default_name
name = K8s.Resource.name(resource)
system = annotations.actor_system

spec = Map.get(resource, "spec")

Expand All @@ -31,4 +28,42 @@ defmodule SpawnOperator do
annotations: annotations
}
end

def get_annotations_or_defaults(annotations) do
%{
actor_system: Map.get(annotations, "spawn-eigr.io/actor-system", @actorsystem_default_name),
user_function_host: Map.get(annotations, "spawn-eigr.io/app-host", "0.0.0.0"),
user_function_port: Map.get(annotations, "spawn-eigr.io/app-port", "8090"),
cluster_poling_interval:
Map.get(annotations, "spawn-eigr.io/cluster-poling-interval", "3000"),
proxy_mode: Map.get(annotations, "spawn-eigr.io/sidecar-mode", "sidecar"),
proxy_http_port: Map.get(annotations, "spawn-eigr.io/sidecar-http-port", "9001"),
proxy_image_tag:
Map.get(
annotations,
"spawn-eigr.io/sidecar-image-tag",
"docker.io/eigr/spawn-proxy:0.5.0"
),
proxy_uds_enabled: Map.get(annotations, "spawn-eigr.io/sidecar-uds-enabled", "false"),
proxy_uds_address:
Map.get(annotations, "spawn-eigr.io/sidecar-uds-socket-path", "/var/run/spawn.sock"),
metrics_port: Map.get(annotations, "spawn-eigr.io/sidecar-metrics-port", "9090"),
metrics_disabled: Map.get(annotations, "spawn-eigr.io/sidecar-metrics-disabled", "false"),
metrics_log_console:
Map.get(annotations, "spawn-eigr.io/sidecar-metrics-log-console", "true"),
pubsub_adapter: Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-adapter", "native"),
pubsub_nats_hosts:
Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-hosts", "nats://127.0.0.1:4222"),
pubsub_nats_tls: Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-tls", "false"),
pubsub_nats_auth_type:
Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-auth-type", "simple"),
pubsub_nats_auth: Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-auth", "false"),
pubsub_nats_auth_jwt:
Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-auth-jwt", ""),
pubsub_nats_auth_user:
Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-auth-user", "admin"),
pubsub_nats_auth_pass:
Map.get(annotations, "spawn-eigr.io/sidecar-pubsub-nats-auth-pass", "admin")
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,69 @@ defmodule SpawnOperator.Handler.ActorHostHandler do
kind: ActorHost
metadata:
name: my-node-app # Mandatory. Name of the Node containing Actor Host Functions
system: my-actor-system # mandatory. Name of the ActorSystem declared in ActorSystem CRD
namespace: default # Optional. Default namespace is "default"
labels:
# Mandatory. Name of the ActorSystem declared in ActorSystem CRD
spawn-eigr.io.actor-system: my-actor-system
# Optional
spawn-eigr.io.cluser.polingInterval: 3000
# Optional. Default "sidecar". Possible values are "sidecar" | "daemon"
spawn-eigr.io.sidecar.deploymentMode: "sidecar"
# Optional
spawn-eigr.io.sidecar.containerImage: "docker.io/eigr/spawn-proxy"
# Optional
spawn-eigr.io.sidecar.containerVersion: "0.5.0"
# Optional. Default 9001
spawn-eigr.io.sidecar.httpPort: 9001
# Optional. Default false
spawn-eigr.io.sidecar.udsEnable: false
# Optional. Default "/var/run/spawn.sock"
spawn-eigr.io.sidecar.udsAddress: "/var/run/sidecar.sock"
# Optional. Default false
spawn-eigr.io.sidecar.disableMetrics: false
# Optional. Default true
spawn-eigr.io.sidecar.consoleDisableMetrics: true
# Optional
spawn-eigr.io.sidecar.userFunctionHost: "0.0.0.0"
# Optional
spawn-eigr.io.sidecar.userFunctionPort: 8090
# Optional. Default "native".
# Using Phoenix PubSub Adapter.
# Possible values: "native" | "nats"
spawn-eigr.io.sidecar.pubsub.adapter: "native"
# Optional. Default "nats://127.0.0.1:4222"
spawn-eigr.io.sidecar.pubsub.nats.hosts: "nats://127.0.0.1:4222"
# Optional. Default false
spawn-eigr.io.sidecar.pubsub.nats.tls: "false"
# Optional. Default false
spawn-eigr.io.sidecar.pubsub.nats.auth: false
# Optioal. Default "simple"
spawn-eigr.io.sidecar.pubsub.nats.authType: "simple"
# Optional. Default "admin"
spawn-eigr.io.sidecar.pubsub.nats.authUser: "admin"
# Optional. Default "admin"
spawn-eigr.io.sidecar.pubsub.nats.authPass: "admin"
# Optional. Default ""
spawn-eigr.io.sidecar.pubsub.nats.authJwt: ""
spec:
autoscaler: # Optional
min: 1
Expand All @@ -26,9 +87,6 @@ defmodule SpawnOperator.Handler.ActorHostHandler do
ports:
- containerPort: 80
sidecar: # Optional. If embedded true then this section will be ignored
image: docker.io/eigr/spawn-proxy:0.5.0
"""

alias SpawnOperator.K8s.ConfigMap.SidecarCM
Expand All @@ -42,7 +100,6 @@ defmodule SpawnOperator.Handler.ActorHostHandler do
@impl Pluggable
def call(%Bonny.Axn{action: action} = axn, nil) when action in [:add, :modify] do
%Bonny.Axn{resource: resource} = axn
IO.inspect(resource, label: "Resource ---")
host_resource = build_host_deploy(resource)

host_config_map = build_host_configmap(resource)
Expand Down
Loading

0 comments on commit 8001913

Please sign in to comment.