diff --git a/components/operator/.earthly/configuration/templates/configuration.yaml b/components/operator/.earthly/configuration/templates/configuration.yaml index 096df7506e..29c5c97b07 100644 --- a/components/operator/.earthly/configuration/templates/configuration.yaml +++ b/components/operator/.earthly/configuration/templates/configuration.yaml @@ -29,11 +29,12 @@ spec: broker: nats: replicas: 1 - hostname: nats.default.svc.cluster.local + url: nats.nats.svc.cluster.local:4222 services: gateway: enableAuditPlugin: true fallback: {{ .Values.gateway.fallback}} + livenessEndpoint: http://nats.default.svc.cluster.local:8222/healthz control: disabled: true auth: diff --git a/components/operator/apis/stack/v1beta3/broker.go b/components/operator/apis/stack/v1beta3/broker.go index fec4ce196b..d703781d05 100644 --- a/components/operator/apis/stack/v1beta3/broker.go +++ b/components/operator/apis/stack/v1beta3/broker.go @@ -16,17 +16,8 @@ type KafkaConfig struct { } type NatsConfig struct { - Hostname string `json:"hostname"` - - // +kubebuilder:default:=4222 - // +optional - Port int32 `json:"port"` - + URL string `json:"url"` // +kubebuilder:default:=3 // +optional Replicas int `json:"replicas"` - - // +kubebuilder:default:=8222 - // +optional - MonitoringPort int32 `json:"monitoringPort,omitempty"` } diff --git a/components/operator/apis/stack/v1beta3/gateway_types.go b/components/operator/apis/stack/v1beta3/gateway_types.go index 093bc08b6a..910e3e1089 100644 --- a/components/operator/apis/stack/v1beta3/gateway_types.go +++ b/components/operator/apis/stack/v1beta3/gateway_types.go @@ -11,4 +11,7 @@ type GatewaySpec struct { // +optional EnableAuditPlugin *bool `json:"enableAuditPlugin,omitempty"` + + // +optional + LivenessEndpoint *string `json:"livenessEndpoint,omitempty"` } diff --git a/components/operator/internal/modules/broker.go b/components/operator/internal/modules/broker.go index 91ab615a01..cc71c8f150 100644 --- a/components/operator/internal/modules/broker.go +++ b/components/operator/internal/modules/broker.go @@ -1,7 +1,6 @@ package modules import ( - "strconv" "strings" "github.com/formancehq/operator/apis/stack/v1beta3" @@ -35,12 +34,10 @@ func BrokerEnvVarsWithPrefix(broker v1beta3.Broker, serviceName string) Containe ) } } else { - port := strconv.FormatInt(int64(broker.Nats.Port), 10) - ret = ret.Append( Env("BROKER", "nats"), Env("PUBLISHER_NATS_ENABLED", "true"), - Env("PUBLISHER_NATS_URL", broker.Nats.Hostname+":"+port), + Env("PUBLISHER_NATS_URL", broker.Nats.URL), Env("PUBLISHER_NATS_CLIENT_ID", serviceName), ) } diff --git a/components/operator/internal/modules/gateway/handler.go b/components/operator/internal/modules/gateway/handler.go index b96d7abe87..c72add701b 100644 --- a/components/operator/internal/modules/gateway/handler.go +++ b/components/operator/internal/modules/gateway/handler.go @@ -52,9 +52,10 @@ func (g module) Versions() map[string]modules.Version { ExposeHTTP: &modules.ExposeHTTP{ Path: "/", }, - Liveness: modules.LivenessDisable, - Topics: &modules.Topics{Name: "audit"}, - Annotations: ctx.Configuration.Spec.Services.Gateway.Annotations.Service, + Liveness: modules.LivenessDisable, + LivenessEndpoint: ctx.Configuration.Spec.Services.Gateway.LivenessEndpoint, + Topics: &modules.Topics{Name: "audit"}, + Annotations: ctx.Configuration.Spec.Services.Gateway.Annotations.Service, Configs: func(resolveContext modules.ServiceInstallConfiguration) modules.Configs { return modules.Configs{ "config": modules.Config{ @@ -84,16 +85,6 @@ func (g module) Versions() map[string]modules.Version { }, } - if ctx.Configuration.Spec.Broker.Nats != nil { - livenessEndpoint := fmt.Sprintf( - "nats://%s:%d/%s", - ctx.Configuration.Spec.Broker.Nats.Hostname, - ctx.Configuration.Spec.Broker.Nats.MonitoringPort, - "healthz", - ) - - service.LivenessEndpoint = &livenessEndpoint - } return modules.Services{service} }, }, diff --git a/components/operator/internal/modules/search.go b/components/operator/internal/modules/search.go index 43f9a530c1..9ed744672d 100644 --- a/components/operator/internal/modules/search.go +++ b/components/operator/internal/modules/search.go @@ -2,7 +2,6 @@ package modules import ( "fmt" - "strconv" "strings" stackv1beta3 "github.com/formancehq/operator/apis/stack/v1beta3" @@ -67,9 +66,8 @@ func ElasticSearchEnvVars(stack *stackv1beta3.Stack, configuration *stackv1beta3 } if configuration.Spec.Broker.Nats != nil { - port := strconv.FormatInt(int64(configuration.Spec.Broker.Nats.Port), 10) ret = ret.Append( - Env("NATS_URL", configuration.Spec.Broker.Nats.Hostname+":"+port), + Env("NATS_URL", configuration.Spec.Broker.Nats.URL), ) } if configuration.Spec.Services.Search.ElasticSearchConfig.BasicAuth != nil { diff --git a/components/operator/internal/modules/search/handler.go b/components/operator/internal/modules/search/handler.go index 5f8a3574c0..ab3279dc1b 100644 --- a/components/operator/internal/modules/search/handler.go +++ b/components/operator/internal/modules/search/handler.go @@ -6,7 +6,6 @@ import ( "fmt" "io/fs" "path/filepath" - "strconv" "strings" "golang.org/x/mod/semver" @@ -461,9 +460,8 @@ func elasticSearchEnvVars(stack *stackv1beta3.Stack, configuration *stackv1beta3 } } if configuration.Spec.Broker.Nats != nil { - port := strconv.FormatInt(int64(configuration.Spec.Broker.Nats.Port), 10) ret = ret.Append( - modules.Env("NATS_URL", configuration.Spec.Broker.Nats.Hostname+":"+port), + modules.Env("NATS_URL", configuration.Spec.Broker.Nats.URL), ) } if configuration.Spec.Services.Search.ElasticSearchConfig.BasicAuth != nil { diff --git a/components/operator/internal/modules/service.go b/components/operator/internal/modules/service.go index 7c50d0061e..ba845d08b0 100644 --- a/components/operator/internal/modules/service.go +++ b/components/operator/internal/modules/service.go @@ -6,7 +6,6 @@ import ( "encoding/base64" "fmt" "sort" - "strconv" "strings" "github.com/formancehq/stack/libs/go-libs/collectionutils" @@ -418,8 +417,7 @@ func (r *serviceReconciler) configureNats() { Retention: nats.InterestPolicy, Replicas: r.Configuration.Spec.Broker.Nats.Replicas, } - port := strconv.FormatInt(int64(r.Configuration.Spec.Broker.Nats.Port), 10) - nc, err := nats.Connect(r.Configuration.Spec.Broker.Nats.Hostname + ":" + port) + nc, err := nats.Connect(r.Configuration.Spec.Broker.Nats.URL) if err != nil { logging.Error(err) } diff --git a/components/operator/internal/storage/nats/client.go b/components/operator/internal/storage/nats/client.go index 85373a3088..fafed770da 100644 --- a/components/operator/internal/storage/nats/client.go +++ b/components/operator/internal/storage/nats/client.go @@ -1,8 +1,6 @@ package nats import ( - "strconv" - "github.com/formancehq/operator/apis/stack/v1beta3" "github.com/nats-io/nats.go" "github.com/pkg/errors" @@ -12,8 +10,7 @@ func NewClient(natsConfig *v1beta3.NatsConfig, clientId string) (*nats.Conn, err options := []nats.Option{ nats.Name(clientId), } - port := strconv.FormatInt(int64(natsConfig.Port), 10) - conn, err := nats.Connect(natsConfig.Hostname+":"+port, options...) + conn, err := nats.Connect(natsConfig.URL, options...) if err != nil { return nil, errors.Wrap(err, "cannot connect to nats-core") }