Skip to content

Commit

Permalink
feat: share protobuf files between containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Santos committed Jan 13, 2025
1 parent 8d4aecd commit 6c151f7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/simple/host-simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ metadata:
spawn-eigr.io/sidecar-image-tag: "ghcr.io/eigr/spawn-proxy:1.4.3"
spec:
host:
image: ttl.sh/spawn-java-example:24h # Mandatory
image: ttl.sh/spawn-java-example:48h # Mandatory
ports:
- name: http
containerPort: 8090
Expand Down
3 changes: 2 additions & 1 deletion spawn_operator/spawn_operator/lib/spawn_operator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ defmodule SpawnOperator do
actors_global_backpressure_min_demand:
Map.get(annotations, "spawn-eigr.io/actors-global-backpressure-min-demand", "-1"),
actors_global_backpressure_enabled:
Map.get(annotations, "spawn-eigr.io/actors-global-backpressure-enabled", "true")
Map.get(annotations, "spawn-eigr.io/actors-global-backpressure-enabled", "true"),
grpc_include_protos_path: Map.get(annotations, "spawn-eigr.io/grpc-include-protos-path", "/shared/protos"),
}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ defmodule SpawnOperator.K8s.Proxy.CM.Configmap do
annotations.actors_global_backpressure_max_demand,
"ACTORS_GLOBAL_BACKPRESSURE_MIN_DEMAND" =>
annotations.actors_global_backpressure_min_demand,
"ACTORS_GLOBAL_BACKPRESSURE_ENABLED" => annotations.actors_global_backpressure_enabled
"ACTORS_GLOBAL_BACKPRESSURE_ENABLED" => annotations.actors_global_backpressure_enabled,
"PROXY_GRPC_INCLUDE_PROTOS_PATH" => annotations.grpc_include_protos_path,
}
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,29 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
}
}

@proto_volume %{
"name" => "shared-volume",
"emptyDir" => %{}
}


@default_certs_volume %{
"name" => "certs",
"secret" => %{"secretName" => "tls-certs", "optional" => true}
}

@default_volumes [
@default_certs_volume
]

@proto_volume_mounts [
%{"name" => "proto-volume", "mountPath" => "/actors"}
@default_certs_volume,
@proto_volume
]

@default_certs_volume_mounts %{"name" => "certs", "mountPath" => "/app/certs"}

@default_proto_volume_mounts %{"name" => "shared-volume", "mountPath" => "/shared"}

@default_volume_mounts [
@default_certs_volume_mounts
@default_certs_volume_mounts,
@default_proto_volume_mounts
]

@default_termination_period_seconds 405
Expand Down Expand Up @@ -436,48 +442,21 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
Map.put(spec, "terminationGracePeriodSeconds", @default_termination_period_seconds)
end

defp maybe_put_volumes(spec, %{"volumes" => volumes} = params) do
host_params = Map.get(params, "host")
actor_host_function_image = Map.get(host_params, "image")

proto_volume_mounts = [
%{
"name" => "proto-volume",
"image" => %{
"reference" => actor_host_function_image,
"pullPolicy" => "IfNotPresent"
}
}
]

defp maybe_put_volumes(spec, %{"volumes" => volumes} = _params) do
volumes =
(volumes ++
@default_volumes)
|> Kernel.++(proto_volume_mounts)
|> List.flatten()
|> Enum.uniq(& &1["name"])

Map.merge(spec, %{"volumes" => volumes})
end

defp maybe_put_volumes(spec, params) do
host_params = Map.get(params, "host")
actor_host_function_image = Map.get(host_params, "image")

proto_volume_mounts = [
%{
"name" => "proto-volume",
"image" => %{
"reference" => actor_host_function_image,
"pullPolicy" => "IfNotPresent"
}
}
]

defp maybe_put_volumes(spec, _params) do
volumes =
@default_volumes
|> Kernel.++(proto_volume_mounts)
|> List.flatten()
|> Enum.uniq(& &1["name"])

Map.put(spec, "volumes", volumes)
end
Expand Down Expand Up @@ -505,7 +484,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
volumeMounts =
volumeMounts
|> Kernel.++(@default_volume_mounts)
|> Kernel.++(@proto_volume_mounts)
|> List.flatten()
|> Enum.uniq(& &1["name"])

Expand All @@ -515,7 +493,6 @@ defmodule SpawnOperator.K8s.Proxy.Deployment do
defp maybe_put_volume_mounts_to_host_container(spec, _, :sidecar) do
volumeMounts =
@default_volume_mounts
|> Kernel.++(@proto_volume_mounts)
|> List.flatten()
|> Enum.uniq(& &1["name"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule SpawnOperator.K8sConn do

@spec get(atom()) :: K8s.Conn.t()
def get(:dev) do
{:ok, conn} = K8s.Conn.from_file("~/.kube/config", context: "k3d-eigr-spawn")
{:ok, conn} = K8s.Conn.from_file("~/.kube/config", context: "minikube")
struct!(conn, insecure_skip_tls_verify: true)
end

Expand Down

0 comments on commit 6c151f7

Please sign in to comment.