Skip to content

Commit 556b083

Browse files
aanmraybejjani
authored andcommitted
operator: deprecate api-server-port flag
Also, as being deprecated, we should not open this port on all interfaces since cilium-operator is running in the host network. For now we will open on both IPv4 and IPv6 localhost addresses since the user might run the operator on IPv6-only clusters, or vice-versa, we don't want the operator to not being able from listening on a port on the IP version not available on the cluster. Signed-off-by: André Martins <andre@cilium.io>
1 parent 26e3ca0 commit 556b083

File tree

9 files changed

+90
-27
lines changed

9 files changed

+90
-27
lines changed

Documentation/cmdref/cilium-operator.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ cilium-operator [flags]
1515
### Options
1616

1717
```
18-
--api-server-port uint16 Port on which the operator should serve API requests (default 9234)
1918
--aws-client-burst int Burst value allowed for the AWS client used by the AWS ENI IPAM (default 4)
2019
--aws-client-qps float Queries per second limit for the AWS client used by the AWS ENI IPAM (default 20)
2120
--aws-instance-limit-mapping map Add or overwrite mappings of AWS instance limit in the form of {"AWS instance type": "Maximum Network Interfaces","IPv4 Addresses per Interface","IPv6 Addresses per Interface"}. cli example: --aws-instance-limit-mapping=a1.medium=2,4,4 --aws-instance-limit-mapping=a2.somecustomflavor=4,5,6 configmap example: {"a1.medium": "2,4,4", "a2.somecustomflavor": "4,5,6"} (default map[])
@@ -45,6 +44,7 @@ cilium-operator [flags]
4544
--kvstore string Key-value store type
4645
--kvstore-opt map Key-value store options (default map[])
4746
--nodes-gc-interval duration GC interval for nodes store in the kvstore (default 2m0s)
47+
--operator-api-serve-addr string Address to serve API requests (default "localhost:9234")
4848
--operator-prometheus-serve-addr string Address to serve Prometheus metrics (default ":6942")
4949
--synchronize-k8s-nodes Synchronize Kubernetes nodes to kvstore and perform CNP GC (default true)
5050
--synchronize-k8s-services Synchronize Kubernetes services to kvstore (default true)

Documentation/install/upgrade.rst

+5
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ Deprecated cilium-operator options
347347
endpoint GC can be done with ``cilium-endpoint-gc-interval=0``.
348348
This old option will be removed in Cilium 1.9
349349

350+
* ``api-server-port``: This option is being deprecated. The API Server address
351+
and port can be enabled with ``operator-api-serve-addr=127.0.0.1:9234``
352+
or ``operator-api-serve-addr=[::1]:9234`` for IPv6-only clusters.
353+
This old option will be removed in Cilium 1.9
354+
350355
Removed options
351356
~~~~~~~~~~~~~~~
352357

install/kubernetes/cilium/charts/config/templates/configmap.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,9 @@ data:
325325
enable-remote-node-identity: {{ .Values.global.remoteNodeIdentity | quote }}
326326

327327
synchronize-k8s-nodes: {{ .Values.global.synchronizeK8sNodes | quote }}
328+
329+
{{- if .Values.global.ipv4.enabled }}
330+
operator-api-serve-addr: '127.0.0.1:9234'
331+
{{- else }}
332+
operator-api-serve-addr: '[::1]:9234'
333+
{{- end }}

install/kubernetes/cilium/charts/operator/templates/deployment.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ spec:
9393
{{- end }}
9494
livenessProbe:
9595
httpGet:
96+
{{- if .Values.global.ipv4.enabled }}
97+
host: '127.0.0.1'
98+
{{- else }}
99+
host: '[::1]'
100+
{{- end }}
96101
path: /healthz
97102
port: 9234
98103
scheme: HTTP

install/kubernetes/quick-install.yaml

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
---
2+
# Source: cilium/charts/agent/templates/serviceaccount.yaml
3+
apiVersion: v1
4+
kind: ServiceAccount
5+
metadata:
6+
name: cilium
7+
namespace: kube-system
8+
---
9+
# Source: cilium/charts/operator/templates/serviceaccount.yaml
10+
apiVersion: v1
11+
kind: ServiceAccount
12+
metadata:
13+
name: cilium-operator
14+
namespace: kube-system
15+
---
216
# Source: cilium/charts/config/templates/configmap.yaml
317
apiVersion: v1
418
kind: ConfigMap
@@ -129,20 +143,7 @@ data:
129143
enable-remote-node-identity: "true"
130144

131145
synchronize-k8s-nodes: "true"
132-
---
133-
# Source: cilium/charts/agent/templates/serviceaccount.yaml
134-
apiVersion: v1
135-
kind: ServiceAccount
136-
metadata:
137-
name: cilium
138-
namespace: kube-system
139-
---
140-
# Source: cilium/charts/operator/templates/serviceaccount.yaml
141-
apiVersion: v1
142-
kind: ServiceAccount
143-
metadata:
144-
name: cilium-operator
145-
namespace: kube-system
146+
operator-api-serve-addr: '127.0.0.1:9234'
146147
---
147148
# Source: cilium/charts/agent/templates/clusterrole.yaml
148149
apiVersion: rbac.authorization.k8s.io/v1
@@ -603,6 +604,7 @@ spec:
603604
name: cilium-operator
604605
livenessProbe:
605606
httpGet:
607+
host: '127.0.0.1'
606608
path: /healthz
607609
port: 9234
608610
scheme: HTTP

operator/api.go

+38-10
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ import (
2424
)
2525

2626
// startServer starts an api server listening on the given address.
27-
func startServer(addr string, shutdownSignal <-chan struct{}, allSystemsGo <-chan struct{}) {
28-
log.Infof("Starting apiserver on address %s", addr)
29-
27+
func startServer(shutdownSignal <-chan struct{}, allSystemsGo <-chan struct{}, addrs ...string) {
3028
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
3129
select {
3230
// only start serving the real health check once all systems all up and running
@@ -37,16 +35,46 @@ func startServer(addr string, shutdownSignal <-chan struct{}, allSystemsGo <-cha
3735
}
3836
})
3937

40-
srv := &http.Server{Addr: addr}
38+
errs := make(chan error, 1)
39+
nServers := 0
4140

42-
go func() {
43-
<-shutdownSignal
44-
if err := srv.Shutdown(context.Background()); err != nil {
45-
log.WithError(err).Error("apiserver shutdown")
41+
// Since we are opening this on localhost only, we need to make sure
42+
// we can open for both v4 and v6 localhost. In case the user is running
43+
// v4-only or v6-only.
44+
for _, addr := range addrs {
45+
if addr == "" {
46+
continue
4647
}
47-
}()
48+
nServers++
49+
srv := &http.Server{Addr: addr}
50+
errCh := make(chan error, 1)
51+
52+
go func() {
53+
err := srv.ListenAndServe()
54+
if err != nil {
55+
errCh <- err
56+
errs <- err
57+
}
58+
}()
59+
go func() {
60+
select {
61+
case <-shutdownSignal:
62+
if err := srv.Shutdown(context.Background()); err != nil {
63+
log.WithError(err).Error("apiserver shutdown")
64+
}
65+
case err := <-errCh:
66+
log.Warnf("Unable to start status api: %s", err)
67+
}
68+
}()
69+
log.Infof("Starting apiserver on address %s", addr)
70+
}
4871

49-
log.Fatalf("Unable to start status api: %s", srv.ListenAndServe())
72+
for err := range errs {
73+
nServers--
74+
if nServers == 0 {
75+
log.Fatalf("Unable to start status api: %s", err)
76+
}
77+
}
5078
}
5179

5280
func healthHandlerOK(w http.ResponseWriter, r *http.Request) {

operator/flags.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func init() {
154154
flags.String(option.OperatorPrometheusServeAddr, ":6942", "Address to serve Prometheus metrics")
155155
option.BindEnv(option.OperatorPrometheusServeAddr)
156156

157+
flags.String(option.OperatorAPIServeAddr, "localhost:9234", "Address to serve API requests")
158+
option.BindEnv(option.OperatorAPIServeAddr)
159+
157160
flags.Bool(option.SyncK8sServices, true, "Synchronize Kubernetes services to kvstore")
158161
option.BindEnv(option.SyncK8sServices)
159162

@@ -166,8 +169,9 @@ func init() {
166169
flags.Bool(option.Version, false, "Print version information")
167170
option.BindEnv(option.Version)
168171

169-
// TODO: Urgent fix
172+
// Deprecated, remove in 1.9
170173
flags.Uint16Var(&apiServerPort, "api-server-port", 9234, "Port on which the operator should serve API requests")
174+
flags.MarkDeprecated("api-server-port", fmt.Sprintf("Please use %s instead", option.OperatorAPIServeAddr))
171175

172176
// Deprecated, remove in 1.9
173177
flags.StringVar(&metricsAddress, "metrics-address", ":6942", "Address to serve Prometheus metrics")

operator/main.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
},
5858
}
5959

60+
// Deprecated: remove in 1.9
6061
apiServerPort uint16
6162
shutdownSignal = make(chan struct{})
6263

@@ -104,12 +105,19 @@ func kvstoreEnabled() bool {
104105
option.Config.SyncK8sNodes
105106
}
106107

108+
func getAPIServerAddr() []string {
109+
if option.Config.OperatorAPIServeAddr == "" {
110+
return []string{fmt.Sprintf("127.0.0.1:%d", apiServerPort), fmt.Sprintf("[::1]:%d", apiServerPort)}
111+
}
112+
return []string{option.Config.OperatorAPIServeAddr}
113+
}
114+
107115
func runOperator(cmd *cobra.Command) {
108116
logging.SetupLogging([]string{}, map[string]string{}, "cilium-operator", viper.GetBool("debug"))
109117

110118
log.Infof("Cilium Operator %s", version.Version)
111119
k8sInitDone := make(chan struct{})
112-
go startServer(fmt.Sprintf(":%d", apiServerPort), shutdownSignal, k8sInitDone)
120+
go startServer(shutdownSignal, k8sInitDone, getAPIServerAddr()...)
113121

114122
if option.Config.EnableMetrics {
115123
registerMetrics()

pkg/option/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ const (
379379
// OperatorPrometheusServeAddr IP:Port on which to serve prometheus metrics (pass ":Port" to bind on all interfaces, "" is off)
380380
OperatorPrometheusServeAddr = "operator-prometheus-serve-addr"
381381

382+
// OperatorAPIServeAddr IP:Port on which to serve api requests in operator (pass ":Port" to bind on all interfaces, "" is off)
383+
OperatorAPIServeAddr = "operator-api-serve-addr"
384+
382385
// PrometheusServeAddrDeprecated IP:Port on which to serve prometheus metrics (pass ":Port" to bind on all interfaces, "" is off)
383386
PrometheusServeAddrDeprecated = "prometheus-serve-addr-deprecated"
384387

@@ -1175,6 +1178,7 @@ type DaemonConfig struct {
11751178
PProf bool
11761179
PrometheusServeAddr string
11771180
OperatorPrometheusServeAddr string
1181+
OperatorAPIServeAddr string
11781182
ToFQDNsMinTTL int
11791183

11801184
// ToFQDNsProxyPort is the user-configured global, shared, DNS listen port used
@@ -1922,6 +1926,7 @@ func (c *DaemonConfig) Populate() {
19221926
c.PrependIptablesChains = viper.GetBool(PrependIptablesChainsName)
19231927
c.PrometheusServeAddr = getPrometheusServerAddr()
19241928
c.OperatorPrometheusServeAddr = viper.GetString(OperatorPrometheusServeAddr)
1929+
c.OperatorAPIServeAddr = viper.GetString(OperatorAPIServeAddr)
19251930
c.ProxyConnectTimeout = viper.GetInt(ProxyConnectTimeout)
19261931
c.BlacklistConflictingRoutes = viper.GetBool(BlacklistConflictingRoutes)
19271932
c.ReadCNIConfiguration = viper.GetString(ReadCNIConfiguration)

0 commit comments

Comments
 (0)