Skip to content

Commit

Permalink
update externalinvocation
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdarruda committed Jan 17, 2025
1 parent be07ca5 commit bdd2536
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 31 deletions.
10 changes: 6 additions & 4 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,12 @@ metadata:
name: spawn-system # 1. Required. Name of the ActorSystem
namespace: default # 2. Optional. Default namespace is "default"
spec:
# This externalInvocation section is required only if using the Nats broker in your project.
externalInvocation:
enabled: "true"
externalConnectorRef: nats-invocation-conn-secret # 3. Nats broker credentials
cluster:
features:
# This nats section is required only if using the Nats broker in your project.
nats:
enabled: true
credentialsSecretRef: "nats-invocation-conn-secret" # 3. Nats broker credentials
statestore:
type: MariaDB # 4. Set database provider. Valid options: [MariaDB, Postgres, Native]
credentialsSecretRef: mariadb-connection-secret # 5. Secret with database connection details created earlier
Expand Down
2 changes: 1 addition & 1 deletion examples/activators/cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
spec:
activator:
type: Cron
externalConnectorRef: invocation-connection-ref-secret
externalConnectorRef: nats-invocation-conn-secret
bindings:
sources:
- name: minute-scheduler
Expand Down
2 changes: 1 addition & 1 deletion examples/secret/invocation-connection-secret-example.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kubectl -n default create secret generic invocation-connection-ref-secret \
kubectl -n default create secret generic nats-invocation-conn-secret \
--from-literal=url=spawn-nats:4222 \
--from-literal=authEnabled="false" \
--from-literal=tlsEnabled="false" \
Expand Down
8 changes: 5 additions & 3 deletions examples/security/acl/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
name: spawn-system # Mandatory. Name of the state store
namespace: default # Optional. Default namespace is "default"
spec:
externalInvocation:
enabled: "true"
externalConnectorRef: invocation-connection-ref-secret
cluster:
features:
nats:
enabled: true
credentialsSecretRef: "nats-invocation-conn-secret"
statestore:
type: MySql
credentialsSecretRef: mysql-connection-secret # The secret containing connection params
Expand Down
8 changes: 5 additions & 3 deletions examples/security/authentication/basic/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
name: spawn-system # Mandatory. Name of the state store
namespace: default # Optional. Default namespace is "default"
spec:
externalInvocation:
enabled: "true"
externalConnectorRef: invocation-connection-ref-secret
cluster:
features:
nats:
enabled: true
credentialsSecretRef: "nats-invocation-conn-secret" # 3. Nats broker credentials
statestore:
type: MySql
credentialsSecretRef: mysql-connection-secret # The secret containing connection params
Expand Down
8 changes: 5 additions & 3 deletions examples/security/authentication/jwt/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
name: spawn-system # Mandatory. Name of the state store
namespace: default # Optional. Default namespace is "default"
spec:
externalInvocation:
enabled: "true"
externalConnectorRef: invocation-connection-ref-secret
cluster:
features:
nats:
enabled: true
credentialsSecretRef: "nats-invocation-conn-secret" # 3. Nats broker credentials
statestore:
type: MySql
credentialsSecretRef: mysql-connection-secret # The secret containing connection params
Expand Down
8 changes: 5 additions & 3 deletions examples/simple/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
name: spawn-system # Mandatory. Name of the state store
namespace: default # Optional. Default namespace is "default"
spec:
# externalInvocation:
# enabled: "true"
# externalConnectorRef: invocation-connection-ref-secret
# cluster:
# features:
# nats:
# enabled: true
# credentialsSecretRef: "nats-invocation-conn-secret" # 3. Nats broker credentials
statestore:
type: "MariaDB"
credentialsSecretRef: "mariadb-connection-secret" # The secret containing connection params
Expand Down
8 changes: 5 additions & 3 deletions examples/topology/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
name: spawn-system # Mandatory. Name of the state store
namespace: default # Optional. Default namespace is "default"
spec:
externalInvocation:
enabled: "true"
externalConnectorRef: invocation-connection-ref-secret
cluster:
features:
nats:
enabled: true
credentialsSecretRef: "nats-invocation-conn-secret" # 3. Nats broker credentials
statestore:
type: MySql
credentialsSecretRef: mysql-connection-secret # The secret containing connection params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
end

defp maybe_use_nats_cluster(config, _name, namespace, params) do
nats_params = Map.get(params, "externalInvocation", %{})
enabled = Map.get(nats_params, "enabled", "false")
cluster_params = Map.get(params, "cluster", %{})
features = Map.get(cluster_params, "features", %{})
nats_params = Map.get(features, "nats", %{})
enabled = "#{Map.get(nats_params, "enabled", false)}"

nats_config =
case enabled do
"false" ->
%{}

"true" ->
nats_secret_ref = Map.fetch!(nats_params, "externalConnectorRef")
nats_secret_ref = Map.fetch!(nats_params, "credentialsSecretRef")

{:ok, secret} =
K8s.Client.get("v1", :secret,
Expand All @@ -139,11 +141,11 @@ defmodule SpawnOperator.K8s.System.Secret.ActorSystemSecret do
)
|> then(&K8s.Client.run(conn(), &1))

secret_data = Map.fetch!(secret, "data")
nats_host_url = Map.fetch!(secret_data, "url")
secret_data = Map.get(secret, "data")
nats_host_url = Map.get(secret_data, "url", nats_params["url"])
nats_auth = Map.get(secret_data, "authEnabled", "false")
nats_user = Map.fetch!(secret_data, "username")
nats_secret = Map.fetch!(secret_data, "password")
nats_user = Map.get(secret_data, "username")
nats_secret = Map.get(secret_data, "password")
nats_tls = Map.get(secret_data, "tlsEnabled", "false")

%{
Expand Down
8 changes: 5 additions & 3 deletions spawnctl/.k8s/example/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ metadata:
name: spawn-system
namespace: default
spec:
externalInvocation:
enabled: "false"
externalConnectorRef: invocation-connection-ref-secret
cluster:
features:
nats:
enabled: true
credentialsSecretRef: "nats-invocation-conn-secret" # 3. Nats broker credentials
statestore:
type: MySql
credentialsSecretRef: mysql-connection-secret
Expand Down

0 comments on commit bdd2536

Please sign in to comment.