Make bind address of apiserver configurable
Signed-off-by: Szilard Vincze <szilard.vincze@est.tech>
This commit is contained in:
		
							parent
							
								
									68c4b49636
								
							
						
					
					
						commit
						5d1492fea4
					
				|  | @ -616,6 +616,9 @@ spec: | ||||||
|               logging_rest_api: |               logging_rest_api: | ||||||
|                 type: object |                 type: object | ||||||
|                 properties: |                 properties: | ||||||
|  |                   api_address: | ||||||
|  |                     type: string | ||||||
|  |                     default: "" | ||||||
|                   api_port: |                   api_port: | ||||||
|                     type: integer |                     type: integer | ||||||
|                     default: 8080 |                     default: 8080 | ||||||
|  |  | ||||||
|  | @ -309,6 +309,8 @@ configDebug: | ||||||
| 
 | 
 | ||||||
| # parameters affecting logging and REST API listener | # parameters affecting logging and REST API listener | ||||||
| configLoggingRestApi: | configLoggingRestApi: | ||||||
|  |   # REST API listener binds to this address | ||||||
|  |   # api_address: "" | ||||||
|   # REST API listener listens to this port |   # REST API listener listens to this port | ||||||
|   api_port: 8080 |   api_port: 8080 | ||||||
|   # number of entries in the cluster history ring buffer |   # number of entries in the cluster history ring buffer | ||||||
|  |  | ||||||
|  | @ -978,6 +978,9 @@ key. | ||||||
| Parameters affecting logging and REST API listener. In the CRD-based | Parameters affecting logging and REST API listener. In the CRD-based | ||||||
| configuration they are grouped under the `logging_rest_api` key. | 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** | * **api_port** | ||||||
|   REST API listener listens to this port. The default is `8080`. |   REST API listener listens to this port. The default is `8080`. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ data: | ||||||
|   # additional_pod_capabilities: "SYS_NICE" |   # additional_pod_capabilities: "SYS_NICE" | ||||||
|   # additional_secret_mount: "some-secret-name" |   # additional_secret_mount: "some-secret-name" | ||||||
|   # additional_secret_mount_path: "/some/dir" |   # additional_secret_mount_path: "/some/dir" | ||||||
|  |   # api_address: "" | ||||||
|   api_port: "8080" |   api_port: "8080" | ||||||
|   aws_region: eu-central-1 |   aws_region: eu-central-1 | ||||||
|   cluster_domain: cluster.local |   cluster_domain: cluster.local | ||||||
|  |  | ||||||
|  | @ -614,6 +614,9 @@ spec: | ||||||
|               logging_rest_api: |               logging_rest_api: | ||||||
|                 type: object |                 type: object | ||||||
|                 properties: |                 properties: | ||||||
|  |                   api_address: | ||||||
|  |                     type: string | ||||||
|  |                     default: "" | ||||||
|                   api_port: |                   api_port: | ||||||
|                     type: integer |                     type: integer | ||||||
|                     default: 8080 |                     default: 8080 | ||||||
|  |  | ||||||
|  | @ -205,6 +205,7 @@ configuration: | ||||||
|       log_statement: all |       log_statement: all | ||||||
|     # teams_api_url: "" |     # teams_api_url: "" | ||||||
|   logging_rest_api: |   logging_rest_api: | ||||||
|  |     # api_address: "" | ||||||
|     api_port: 8080 |     api_port: 8080 | ||||||
|     cluster_history_entries: 1000 |     cluster_history_entries: 1000 | ||||||
|     ring_log_lines: 100 |     ring_log_lines: 100 | ||||||
|  |  | ||||||
|  | @ -1878,6 +1878,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{ | ||||||
| 					"logging_rest_api": { | 					"logging_rest_api": { | ||||||
| 						Type: "object", | 						Type: "object", | ||||||
| 						Properties: map[string]apiextv1.JSONSchemaProps{ | 						Properties: map[string]apiextv1.JSONSchemaProps{ | ||||||
|  | 							"api_address": { | ||||||
|  | 								Type: "string", | ||||||
|  | 							}, | ||||||
| 							"api_port": { | 							"api_port": { | ||||||
| 								Type: "integer", | 								Type: "integer", | ||||||
| 							}, | 							}, | ||||||
|  |  | ||||||
|  | @ -191,6 +191,7 @@ type TeamsAPIConfiguration struct { | ||||||
| 
 | 
 | ||||||
| // LoggingRESTAPIConfiguration defines Logging API conf
 | // LoggingRESTAPIConfiguration defines Logging API conf
 | ||||||
| type LoggingRESTAPIConfiguration struct { | type LoggingRESTAPIConfiguration struct { | ||||||
|  | 	APIAddress            string `json:"api_address,omitempty"` | ||||||
| 	APIPort               int    `json:"api_port,omitempty"` | 	APIPort               int    `json:"api_port,omitempty"` | ||||||
| 	RingLogLines          int    `json:"ring_log_lines,omitempty"` | 	RingLogLines          int    `json:"ring_log_lines,omitempty"` | ||||||
| 	ClusterHistoryEntries int    `json:"cluster_history_entries,omitempty"` | 	ClusterHistoryEntries int    `json:"cluster_history_entries,omitempty"` | ||||||
|  |  | ||||||
|  | @ -4,10 +4,12 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"net" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/pprof" | 	"net/http/pprof" | ||||||
| 	"regexp" | 	"regexp" | ||||||
| 	"strconv" | 	"strconv" | ||||||
|  | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | @ -72,7 +74,7 @@ var ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // New creates new HTTP API server
 | // 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{ | 	s := &Server{ | ||||||
| 		logger:     logger.WithField("pkg", "apiserver"), | 		logger:     logger.WithField("pkg", "apiserver"), | ||||||
| 		controller: controller, | 		controller: controller, | ||||||
|  | @ -94,7 +96,7 @@ func New(controller controllerInformer, port int, logger *logrus.Logger) *Server | ||||||
| 	mux.HandleFunc("/databases/", s.databases) | 	mux.HandleFunc("/databases/", s.databases) | ||||||
| 
 | 
 | ||||||
| 	s.http = http.Server{ | 	s.http = http.Server{ | ||||||
| 		Addr:        fmt.Sprintf(":%d", port), | 		Addr:        net.JoinHostPort(strings.Trim(address, "[]"), strconv.Itoa(port)), | ||||||
| 		Handler:     http.TimeoutHandler(mux, httpAPITimeout, ""), | 		Handler:     http.TimeoutHandler(mux, httpAPITimeout, ""), | ||||||
| 		ReadTimeout: httpReadTimeout, | 		ReadTimeout: httpReadTimeout, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -366,7 +366,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() { | func (c *Controller) initSharedInformers() { | ||||||
|  |  | ||||||
|  | @ -222,6 +222,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur | ||||||
| 	result.RoleDeletionSuffix = util.Coalesce(fromCRD.TeamsAPI.RoleDeletionSuffix, "_deleted") | 	result.RoleDeletionSuffix = util.Coalesce(fromCRD.TeamsAPI.RoleDeletionSuffix, "_deleted") | ||||||
| 
 | 
 | ||||||
| 	// logging REST API config
 | 	// logging REST API config
 | ||||||
|  | 	result.APIAddress = util.Coalesce(fromCRD.LoggingRESTAPI.APIAddress, "") | ||||||
| 	result.APIPort = util.CoalesceInt(fromCRD.LoggingRESTAPI.APIPort, 8080) | 	result.APIPort = util.CoalesceInt(fromCRD.LoggingRESTAPI.APIPort, 8080) | ||||||
| 	result.RingLogLines = util.CoalesceInt(fromCRD.LoggingRESTAPI.RingLogLines, 100) | 	result.RingLogLines = util.CoalesceInt(fromCRD.LoggingRESTAPI.RingLogLines, 100) | ||||||
| 	result.ClusterHistoryEntries = util.CoalesceInt(fromCRD.LoggingRESTAPI.ClusterHistoryEntries, 1000) | 	result.ClusterHistoryEntries = util.CoalesceInt(fromCRD.LoggingRESTAPI.ClusterHistoryEntries, 1000) | ||||||
|  |  | ||||||
|  | @ -228,6 +228,7 @@ type Config struct { | ||||||
| 	EnableSidecars                           *bool             `name:"enable_sidecars" default:"true"` | 	EnableSidecars                           *bool             `name:"enable_sidecars" default:"true"` | ||||||
| 	SharePgSocketWithSidecars                *bool             `name:"share_pgsocket_with_sidecars" default:"false"` | 	SharePgSocketWithSidecars                *bool             `name:"share_pgsocket_with_sidecars" default:"false"` | ||||||
| 	Workers                                  uint32            `name:"workers" default:"8"` | 	Workers                                  uint32            `name:"workers" default:"8"` | ||||||
|  | 	APIAddress                               string            `name:"api_address" default:""` | ||||||
| 	APIPort                                  int               `name:"api_port" default:"8080"` | 	APIPort                                  int               `name:"api_port" default:"8080"` | ||||||
| 	RingLogLines                             int               `name:"ring_log_lines" default:"100"` | 	RingLogLines                             int               `name:"ring_log_lines" default:"100"` | ||||||
| 	ClusterHistoryEntries                    int               `name:"cluster_history_entries" default:"1000"` | 	ClusterHistoryEntries                    int               `name:"cluster_history_entries" default:"1000"` | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue