Skip to content

Commit

Permalink
CORE-17476 Modifying helm charts to create ClusterIP services for wor…
Browse files Browse the repository at this point in the history
…kers, passing to FlowWorker (#4777)

Modified the deployment helm charts to add a ClusterIP service to each worker; this acts as a load balancer allowing us to call a single endpoint per worker type and have the calls routed to various worker instances. A new "ServicesAccessed" field allows us to pass in, for each worker, the worker types communicated with in `workers.yaml` which will cause the endpoints for those services to be provided as startup args for that worker.
  • Loading branch information
ben-millar authored Oct 6, 2023
1 parent 5e7ed28 commit 5ca49de
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference
import org.slf4j.LoggerFactory
import picocli.CommandLine.Mixin
import picocli.CommandLine.Option

/** The worker for handling flows. */
@Suppress("Unused", "LongParameterList")
Expand Down Expand Up @@ -92,4 +93,7 @@ class FlowWorker @Activate constructor(
private class FlowWorkerParams {
@Mixin
var defaultParams = DefaultWorkerParams()
}

@Option(names = ["--endpoint"], description = ["Internal REST endpoints for Corda workers"], required = true)
val workerEndpoints: Map<String, String> = emptyMap()
}
25 changes: 25 additions & 0 deletions charts/corda-lib/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -614,3 +614,28 @@ data:
{{ $keySecretKey }}: {{ $keySecretValue }}
{{ $caSecretKey }}: {{ $caSecretValue }}
{{- end }}

{{/*
The port which should be used to connect to Corda worker instances
*/}}
{{- define "corda.workerServicePort" -}}
7000
{{- end -}}

{{/*
Cluster IP service name
*/}}
{{- define "corda.workerInternalServiceName" -}}
{{- printf "%s-internal-service" . -}}
{{- end -}}

{{/*
Get the endpoint argument for a given worker
*/}}
{{- define "corda.getWorkerEndpoint" }}
{{- $context := .context }}
{{- $worker := .worker }}
{{- $workerName := printf "%s-%s-worker" (include "corda.fullname" $context) (include "corda.workerTypeKebabCase" $worker) }}
{{- $workerServiceName := include "corda.workerInternalServiceName" $workerName }}
{{- printf "worker.http.endpoint.%s=%s:%s" $worker $workerServiceName (include "corda.workerServicePort" $) }}
{{- end }}
21 changes: 20 additions & 1 deletion charts/corda-lib/templates/_worker.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ spec:
targetPort: http
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "corda.workerInternalServiceName" $workerName }}
spec:
type: ClusterIP
selector:
app: {{ $workerName }}
ports:
- protocol: TCP
port: {{ include "corda.workerServicePort" . }}
targetPort: "monitor"
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -318,6 +331,12 @@ spec:
{{- if $.Values.tracing.samplesPerSecond }}
- "--trace-samples-per-second={{ $.Values.tracing.samplesPerSecond }}"
{{- end }}
{{- if $optionalArgs.servicesAccessed }}
{{- range $worker := $optionalArgs.servicesAccessed }}
{{- $endpoint := include "corda.getWorkerEndpoint" (dict "context" $ "worker" $worker) }}
- --endpoint={{ $endpoint }}
{{- end }}
{{- end }}
{{- range $i, $arg := $optionalArgs.additionalWorkerArgs }}
- {{ $arg | quote }}
{{- end }}
Expand Down Expand Up @@ -513,4 +532,4 @@ Worker affinity
{{- $_ := set $affinity.podAntiAffinity "preferredDuringSchedulingIgnoredDuringExecution" ( append $affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution ( fromYaml ( include "corda.defaultAffinity" ( list ( add ( len $affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution ) 1 ) $worker ) ) ) ) }}
affinity:
{{- toYaml $affinity | nindent 2 }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/corda/templates/workers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
( dict "clusterDbAccess" true )
) }}
{{- include "corda.worker" ( list $ .Values.workers.flow "flow"
( dict "stateManagerDbAccess" true )
( dict "stateManagerDbAccess" true "servicesAccessed" (list "crypto" "verification" "uniqueness" "persistence") )
) }}
{{- include "corda.worker" ( list $ .Values.workers.flowMapper "flowMapper" ) }}
{{- include "corda.worker" ( list $ .Values.workers.verification "verification" ) }}
Expand Down

0 comments on commit 5ca49de

Please sign in to comment.