mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
170 lines
6.4 KiB
Go
170 lines
6.4 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3"
|
|
"github.com/formancehq/operator/internal/modules"
|
|
"github.com/formancehq/operator/internal/modules/ledger"
|
|
"github.com/formancehq/operator/internal/modules/payments"
|
|
"github.com/formancehq/operator/internal/modules/wallets"
|
|
)
|
|
|
|
type module struct{}
|
|
|
|
// DependsOn implements modules.DependsOnAwareModule.
|
|
func (*module) DependsOn() []modules.Module {
|
|
return []modules.Module{
|
|
ledger.Module,
|
|
wallets.Module,
|
|
payments.Module,
|
|
}
|
|
}
|
|
|
|
func (o module) Name() string {
|
|
return "orchestration"
|
|
}
|
|
|
|
func (o module) Postgres(ctx modules.ReconciliationConfig) stackv1beta3.PostgresConfig {
|
|
return ctx.Configuration.Spec.Services.Orchestration.Postgres
|
|
}
|
|
|
|
func (o module) Versions() map[string]modules.Version {
|
|
return map[string]modules.Version{
|
|
"v0.0.0": {
|
|
Services: func(ctx modules.ReconciliationConfig) modules.Services {
|
|
return modules.Services{
|
|
{
|
|
Port: 8080,
|
|
AuthConfiguration: func(config modules.ReconciliationConfig) stackv1beta3.ClientConfiguration {
|
|
return stackv1beta3.
|
|
NewClientConfiguration().
|
|
WithAdditionalScopes(modules.ModulesToScopes(o.DependsOn()...)...)
|
|
},
|
|
ExposeHTTP: modules.DefaultExposeHTTP,
|
|
HasVersionEndpoint: true,
|
|
InjectPostgresVariables: true,
|
|
Annotations: ctx.Configuration.Spec.Services.Orchestration.Annotations.Service,
|
|
Container: func(resolveContext modules.ContainerResolutionConfiguration) modules.Container {
|
|
return modules.Container{
|
|
Env: orchestrationEnvVars(resolveContext),
|
|
Image: modules.GetImage("orchestration", resolveContext.Versions.Spec.Orchestration),
|
|
Resources: modules.GetResourcesWithDefault(
|
|
resolveContext.Configuration.Spec.Services.Orchestration.ResourceProperties,
|
|
modules.ResourceSizeSmall(),
|
|
),
|
|
Debug: resolveContext.Configuration.Spec.Services.Orchestration.Debug,
|
|
}
|
|
},
|
|
},
|
|
{
|
|
Name: "worker",
|
|
InjectPostgresVariables: true,
|
|
Liveness: modules.LivenessDisable,
|
|
Container: func(resolveContext modules.ContainerResolutionConfiguration) modules.Container {
|
|
return modules.Container{
|
|
Env: orchestrationEnvVars(resolveContext),
|
|
Image: modules.GetImage("orchestration", resolveContext.Versions.Spec.Orchestration),
|
|
Args: []string{"worker"},
|
|
Resources: modules.GetResourcesWithDefault(
|
|
resolveContext.Configuration.Spec.Services.Orchestration.ResourceProperties,
|
|
modules.ResourceSizeSmall(),
|
|
),
|
|
Debug: resolveContext.Configuration.Spec.Services.Orchestration.Debug,
|
|
}
|
|
},
|
|
},
|
|
}
|
|
},
|
|
},
|
|
"v0.2.0": {
|
|
Services: func(ctx modules.ReconciliationConfig) modules.Services {
|
|
return modules.Services{
|
|
{
|
|
Port: 8080,
|
|
AuthConfiguration: func(config modules.ReconciliationConfig) stackv1beta3.ClientConfiguration {
|
|
return stackv1beta3.NewClientConfiguration().WithAdditionalScopes(modules.ModulesToScopes(o.DependsOn()...)...)
|
|
|
|
},
|
|
ExposeHTTP: modules.DefaultExposeHTTP,
|
|
HasVersionEndpoint: true,
|
|
InjectPostgresVariables: true,
|
|
Annotations: ctx.Configuration.Spec.Services.Orchestration.Annotations.Service,
|
|
Container: func(resolveContext modules.ContainerResolutionConfiguration) modules.Container {
|
|
return modules.Container{
|
|
Env: orchestrationEnvVars(resolveContext),
|
|
Image: modules.GetImage("orchestration", resolveContext.Versions.Spec.Orchestration),
|
|
Resources: modules.GetResourcesWithDefault(
|
|
resolveContext.Configuration.Spec.Services.Orchestration.ResourceProperties,
|
|
modules.ResourceSizeSmall(),
|
|
),
|
|
Debug: resolveContext.Configuration.Spec.Services.Orchestration.Debug,
|
|
}
|
|
},
|
|
},
|
|
{
|
|
Name: "worker",
|
|
InjectPostgresVariables: true,
|
|
Liveness: modules.LivenessDisable,
|
|
Container: func(resolveContext modules.ContainerResolutionConfiguration) modules.Container {
|
|
env := orchestrationEnvVars(resolveContext)
|
|
env = append(env, modules.BrokerEnvVars(resolveContext.Configuration.Spec.Broker, "orchestration")...)
|
|
|
|
// TODO(gfyrag): Make more generic
|
|
env = append(env, modules.Env("TOPICS", fmt.Sprintf("%s-ledger %s-payments",
|
|
resolveContext.Stack.Name, resolveContext.Stack.Name)))
|
|
return modules.Container{
|
|
Env: env,
|
|
Image: modules.GetImage("orchestration", resolveContext.Versions.Spec.Orchestration),
|
|
Args: []string{"worker"},
|
|
Resources: modules.GetResourcesWithDefault(
|
|
resolveContext.Configuration.Spec.Services.Orchestration.ResourceProperties,
|
|
modules.ResourceSizeSmall(),
|
|
),
|
|
Debug: resolveContext.Configuration.Spec.Services.Orchestration.Debug,
|
|
}
|
|
},
|
|
},
|
|
}
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
var Module = &module{}
|
|
|
|
var _ modules.Module = Module
|
|
var _ modules.PostgresAwareModule = Module
|
|
var _ modules.DependsOnAwareModule = Module
|
|
|
|
func init() {
|
|
modules.Register(Module)
|
|
}
|
|
|
|
func orchestrationEnvVars(resolveContext modules.ContainerResolutionConfiguration) modules.ContainerEnv {
|
|
env := modules.NewEnv().Append(
|
|
modules.Env("POSTGRES_DSN", "$(POSTGRES_URI)"),
|
|
modules.Env("TEMPORAL_TASK_QUEUE", resolveContext.Stack.Name),
|
|
modules.Env("TEMPORAL_ADDRESS", resolveContext.Configuration.Spec.Temporal.Address),
|
|
modules.Env("TEMPORAL_NAMESPACE", resolveContext.Configuration.Spec.Temporal.Namespace),
|
|
modules.Env("STACK_CLIENT_ID", resolveContext.Stack.Status.StaticAuthClients["orchestration"].ID),
|
|
modules.Env("STACK_CLIENT_SECRET", resolveContext.Stack.Status.StaticAuthClients["orchestration"].Secrets[0]),
|
|
).Append(
|
|
modules.AuthEnvVars(resolveContext.Stack.URL(), "orchestration", resolveContext.Configuration.Spec.Auth)...,
|
|
)
|
|
|
|
if resolveContext.Configuration.Spec.Temporal.TLS.SecretName == "" {
|
|
env = env.Append(
|
|
modules.Env("TEMPORAL_SSL_CLIENT_KEY", resolveContext.Configuration.Spec.Temporal.TLS.Key),
|
|
modules.Env("TEMPORAL_SSL_CLIENT_CERT", resolveContext.Configuration.Spec.Temporal.TLS.CRT),
|
|
)
|
|
} else {
|
|
env = env.Append(
|
|
modules.EnvFromSecret("TEMPORAL_SSL_CLIENT_KEY", resolveContext.Configuration.Spec.Temporal.TLS.SecretName, "tls.key"),
|
|
modules.EnvFromSecret("TEMPORAL_SSL_CLIENT_CERT", resolveContext.Configuration.Spec.Temporal.TLS.SecretName, "tls.crt"),
|
|
)
|
|
}
|
|
|
|
return env
|
|
}
|