diff --git a/charts/postgres-operator/crds/operatorconfigurations.yaml b/charts/postgres-operator/crds/operatorconfigurations.yaml index 2c432a082..09b718de4 100644 --- a/charts/postgres-operator/crds/operatorconfigurations.yaml +++ b/charts/postgres-operator/crds/operatorconfigurations.yaml @@ -623,6 +623,9 @@ spec: logging_rest_api: type: object properties: + api_address: + type: string + default: "" api_port: type: integer default: 8080 diff --git a/charts/postgres-operator/values.yaml b/charts/postgres-operator/values.yaml index 6d0161bfb..23f0ea176 100644 --- a/charts/postgres-operator/values.yaml +++ b/charts/postgres-operator/values.yaml @@ -314,6 +314,8 @@ configDebug: # parameters affecting logging and REST API listener configLoggingRestApi: + # REST API listener binds to this address + # api_address: "" # REST API listener listens to this port api_port: 8080 # number of entries in the cluster history ring buffer diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index a62f67dfb..c9ac8f5e6 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -999,6 +999,9 @@ key. Parameters affecting logging and REST API listener. In the CRD-based configuration they are grouped under the `logging_rest_api` key. +* **api_address** + REST API listener binds to this address. The default is empty. + * **api_port** REST API listener listens to this port. The default is `8080`. diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 1cf455e57..4976f330a 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -7,6 +7,7 @@ data: # additional_pod_capabilities: "SYS_NICE" # additional_secret_mount: "some-secret-name" # additional_secret_mount_path: "/some/dir" + # api_address: "" api_port: "8080" aws_region: eu-central-1 cluster_domain: cluster.local diff --git a/manifests/operatorconfiguration.crd.yaml b/manifests/operatorconfiguration.crd.yaml index 03534cefb..d15bf5599 100644 --- a/manifests/operatorconfiguration.crd.yaml +++ b/manifests/operatorconfiguration.crd.yaml @@ -621,6 +621,9 @@ spec: logging_rest_api: type: object properties: + api_address: + type: string + default: "" api_port: type: integer default: 8080 diff --git a/manifests/postgresql-operator-default-configuration.yaml b/manifests/postgresql-operator-default-configuration.yaml index 9c54e4379..6292403cf 100644 --- a/manifests/postgresql-operator-default-configuration.yaml +++ b/manifests/postgresql-operator-default-configuration.yaml @@ -209,6 +209,7 @@ configuration: log_statement: all # teams_api_url: "" logging_rest_api: + # api_address: "" api_port: 8080 cluster_history_entries: 1000 ring_log_lines: 100 diff --git a/pkg/apis/acid.zalan.do/v1/crds.go b/pkg/apis/acid.zalan.do/v1/crds.go index 46739e46d..c1ac87ccb 100644 --- a/pkg/apis/acid.zalan.do/v1/crds.go +++ b/pkg/apis/acid.zalan.do/v1/crds.go @@ -835,6 +835,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{ "logging_rest_api": { Type: "object", Properties: map[string]apiextv1.JSONSchemaProps{ + "api_address": { + Type: "string", + }, "api_port": { Type: "integer", }, diff --git a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go index bfad24b0d..aa72ed79c 100644 --- a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go +++ b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go @@ -191,9 +191,10 @@ type TeamsAPIConfiguration struct { // LoggingRESTAPIConfiguration defines Logging API conf type LoggingRESTAPIConfiguration struct { - APIPort int `json:"api_port,omitempty"` - RingLogLines int `json:"ring_log_lines,omitempty"` - ClusterHistoryEntries int `json:"cluster_history_entries,omitempty"` + APIAddress string `json:"api_address,omitempty"` + APIPort int `json:"api_port,omitempty"` + RingLogLines int `json:"ring_log_lines,omitempty"` + ClusterHistoryEntries int `json:"cluster_history_entries,omitempty"` } // ScalyrConfiguration defines the configuration for ScalyrAPI diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 97e389970..94f59bbc3 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -4,10 +4,12 @@ import ( "context" "encoding/json" "fmt" + "net" "net/http" "net/http/pprof" "regexp" "strconv" + "strings" "sync" "time" @@ -72,7 +74,7 @@ var ( ) // New creates new HTTP API server -func New(controller controllerInformer, port int, logger *logrus.Logger) *Server { +func New(controller controllerInformer, address string, port int, logger *logrus.Logger) *Server { s := &Server{ logger: logger.WithField("pkg", "apiserver"), controller: controller, @@ -94,7 +96,7 @@ func New(controller controllerInformer, port int, logger *logrus.Logger) *Server mux.HandleFunc("/databases/", s.databases) s.http = http.Server{ - Addr: fmt.Sprintf(":%d", port), + Addr: net.JoinHostPort(strings.Trim(address, "[]"), strconv.Itoa(port)), Handler: http.TimeoutHandler(mux, httpAPITimeout, ""), ReadTimeout: httpReadTimeout, } diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 13e4017c8..fa54de064 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -368,7 +368,7 @@ func (c *Controller) initController() { }) } - c.apiserver = apiserver.New(c, c.opConfig.APIPort, c.logger.Logger) + c.apiserver = apiserver.New(c, c.opConfig.APIAddress, c.opConfig.APIPort, c.logger.Logger) } func (c *Controller) initSharedInformers() { diff --git a/pkg/controller/operator_config.go b/pkg/controller/operator_config.go index 7719a2939..6930b064f 100644 --- a/pkg/controller/operator_config.go +++ b/pkg/controller/operator_config.go @@ -233,6 +233,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur result.RoleDeletionSuffix = util.Coalesce(fromCRD.TeamsAPI.RoleDeletionSuffix, "_deleted") // logging REST API config + result.APIAddress = util.Coalesce(fromCRD.LoggingRESTAPI.APIAddress, "") result.APIPort = util.CoalesceInt(fromCRD.LoggingRESTAPI.APIPort, 8080) result.RingLogLines = util.CoalesceInt(fromCRD.LoggingRESTAPI.RingLogLines, 100) result.ClusterHistoryEntries = util.CoalesceInt(fromCRD.LoggingRESTAPI.ClusterHistoryEntries, 1000) diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 468cf9328..b53b44096 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -230,6 +230,7 @@ type Config struct { EnableSidecars *bool `name:"enable_sidecars" default:"true"` SharePgSocketWithSidecars *bool `name:"share_pgsocket_with_sidecars" default:"false"` Workers uint32 `name:"workers" default:"8"` + APIAddress string `name:"api_address" default:""` APIPort int `name:"api_port" default:"8080"` RingLogLines int `name:"ring_log_lines" default:"100"` ClusterHistoryEntries int `name:"cluster_history_entries" default:"1000"`