Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to Use Host Network and Configure Ports #3895

Merged
merged 22 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const (
defaultResync = 30 * time.Second
podNamespace = "pod-namespace"
leaderElectionFlag = "leader-election"
httpPort = "http-port"
)

var (
Expand Down Expand Up @@ -171,7 +172,9 @@ func main() {
agonesInformerFactory := externalversions.NewSharedInformerFactory(agonesClient, defaultResync)
kubeInformerFactory := informers.NewSharedInformerFactory(kubeClient, defaultResync)

server := &httpServer{}
server := &httpServer{
Port: ctlConf.HTTPPort,
}
var rs []runner
var health healthcheck.Handler

Expand Down Expand Up @@ -272,6 +275,7 @@ func parseEnvFlags() config {
viper.SetDefault(allocationBatchWaitTime, 500*time.Millisecond)
viper.SetDefault(podNamespace, "agones-system")
viper.SetDefault(leaderElectionFlag, false)
viper.SetDefault(httpPort, "8080")

viper.SetDefault(projectIDFlag, "")
viper.SetDefault(numWorkersFlag, 64)
Expand Down Expand Up @@ -307,6 +311,7 @@ func parseEnvFlags() config {
pflag.String(logLevelFlag, viper.GetString(logLevelFlag), "Agones Log level")
pflag.Duration(allocationBatchWaitTime, viper.GetDuration(allocationBatchWaitTime), "Flag to configure the waiting period between allocations batches")
pflag.String(podNamespace, viper.GetString(podNamespace), "namespace of current pod")
pflag.String(httpPort, viper.GetString(httpPort), "Port for the HTTP server. Defaults to 8080, can also use HTTP_PORT env variable")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is for webhooks, you only need this in extensions.

pflag.Bool(leaderElectionFlag, viper.GetBool(leaderElectionFlag), "Flag to enable/disable leader election for controller pod")
cloudproduct.BindFlags()
runtime.FeaturesBindFlags()
Expand Down Expand Up @@ -340,6 +345,7 @@ func parseEnvFlags() config {
runtime.Must(viper.BindEnv(allocationBatchWaitTime))
runtime.Must(viper.BindEnv(podNamespace))
runtime.Must(viper.BindEnv(leaderElectionFlag))
runtime.Must(viper.BindEnv(httpPort))
runtime.Must(viper.BindPFlags(pflag.CommandLine))
runtime.Must(cloudproduct.BindEnv())
runtime.Must(runtime.FeaturesBindEnv())
Expand Down Expand Up @@ -401,6 +407,7 @@ func parseEnvFlags() config {
AllocationBatchWaitTime: viper.GetDuration(allocationBatchWaitTime),
PodNamespace: viper.GetString(podNamespace),
LeaderElection: viper.GetBool(leaderElectionFlag),
HTTPPort: viper.GetString(httpPort),
}
}

Expand Down Expand Up @@ -454,6 +461,7 @@ type config struct {
AllocationBatchWaitTime time.Duration
PodNamespace string
LeaderElection bool
HTTPPort string
}

// validate ensures the ctlConfig data is valid.
Expand Down Expand Up @@ -549,6 +557,7 @@ type runner interface {

type httpServer struct {
http.ServeMux
Port string
}

func whenLeader(ctx context.Context, cancel context.CancelFunc, logger *logrus.Entry, doLeaderElection bool, kubeClient *kubernetes.Clientset, namespace string, start func(_ context.Context)) {
Expand Down Expand Up @@ -604,7 +613,7 @@ func whenLeader(ctx context.Context, cancel context.CancelFunc, logger *logrus.E
func (h *httpServer) Run(_ context.Context, _ int) error {
logger.Info("Starting http server...")
srv := &http.Server{
Addr: ":8080",
Addr: ":" + h.Port,
Handler: h,
}
defer srv.Close() // nolint: errcheck
Expand All @@ -613,7 +622,7 @@ func (h *httpServer) Run(_ context.Context, _ int) error {
if err == http.ErrServerClosed {
logger.WithError(err).Info("http server closed")
} else {
wrappedErr := errors.Wrap(err, "Could not listen on :8080")
wrappedErr := errors.Wrap(err, "Could not listen on :"+h.Port)
runtime.HandleError(logger.WithError(wrappedErr), wrappedErr)
}
}
Expand Down
23 changes: 19 additions & 4 deletions cmd/extensions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const (
apiServerSustainedQPSFlag = "api-server-qps"
apiServerBurstQPSFlag = "api-server-qps-burst"
readinessShutdownDuration = "readiness-shutdown-duration"
httpPort = "http-port"
webhookPort = "webhook-port"
)

var (
Expand Down Expand Up @@ -138,7 +140,7 @@ func main() {
logger.WithError(err).Fatal("Could not initialize cloud product")
}
// https server and the items that share the Mux for routing
httpsServer := https.NewServer(ctlConf.CertFile, ctlConf.KeyFile)
httpsServer := https.NewServer(ctlConf.CertFile, ctlConf.KeyFile, ctlConf.WebhookPort)
cancelTLS, err := httpsServer.WatchForCertificateChanges()
if err != nil {
logger.WithError(err).Fatal("Got an error while watching certificate changes")
Expand All @@ -150,7 +152,9 @@ func main() {
agonesInformerFactory := externalversions.NewSharedInformerFactory(agonesClient, defaultResync)
kubeInformerFactory := informers.NewSharedInformerFactory(kubeClient, defaultResync)

server := &httpServer{}
server := &httpServer{
Port: ctlConf.HTTPPort,
}
var health healthcheck.Handler

// Stackdriver metrics
Expand Down Expand Up @@ -249,6 +253,8 @@ func parseEnvFlags() config {
viper.SetDefault(logDirFlag, "")
viper.SetDefault(logLevelFlag, "Info")
viper.SetDefault(logSizeLimitMBFlag, 10000) // 10 GB, will be split into 100 MB chunks
viper.SetDefault(httpPort, "8080")
viper.SetDefault(webhookPort, "8081")

pflag.String(keyFileFlag, viper.GetString(keyFileFlag), "Optional. Path to the key file")
pflag.String(certFileFlag, viper.GetString(certFileFlag), "Optional. Path to the crt file")
Expand All @@ -262,6 +268,8 @@ func parseEnvFlags() config {
pflag.Int32(numWorkersFlag, 64, "Number of controller workers per resource type")
pflag.Int32(apiServerSustainedQPSFlag, 100, "Maximum sustained queries per second to send to the API server")
pflag.Int32(apiServerBurstQPSFlag, 200, "Maximum burst queries per second to send to the API server")
pflag.String(httpPort, viper.GetString(httpPort), "Port for the HTTP server. Defaults to 8080, can also use HTTP_PORT env variable")
pflag.String(webhookPort, viper.GetString(webhookPort), "Port for the Webhook. Defaults to 8081, can also use WEBHOOK_PORT env variable")
pflag.String(logDirFlag, viper.GetString(logDirFlag), "If set, store logs in a given directory.")
pflag.Int32(logSizeLimitMBFlag, 1000, "Log file size limit in MB")
pflag.String(logLevelFlag, viper.GetString(logLevelFlag), "Agones Log level")
Expand All @@ -288,6 +296,8 @@ func parseEnvFlags() config {
runtime.Must(viper.BindEnv(logLevelFlag))
runtime.Must(viper.BindEnv(logDirFlag))
runtime.Must(viper.BindEnv(logSizeLimitMBFlag))
runtime.Must(viper.BindEnv(httpPort))
runtime.Must(viper.BindEnv(webhookPort))
runtime.Must(viper.BindEnv(allocationBatchWaitTime))
runtime.Must(viper.BindPFlags(pflag.CommandLine))
runtime.Must(viper.BindEnv(readinessShutdownDuration))
Expand All @@ -311,6 +321,8 @@ func parseEnvFlags() config {
LogDir: viper.GetString(logDirFlag),
LogLevel: viper.GetString(logLevelFlag),
LogSizeLimitMB: int(viper.GetInt32(logSizeLimitMBFlag)),
HTTPPort: viper.GetString(httpPort),
WebhookPort: viper.GetString(webhookPort),
AllocationBatchWaitTime: viper.GetDuration(allocationBatchWaitTime),
ReadinessShutdownDuration: viper.GetDuration(readinessShutdownDuration),
}
Expand All @@ -333,6 +345,8 @@ type config struct {
LogDir string
LogLevel string
LogSizeLimitMB int
HTTPPort string
WebhookPort string
AllocationBatchWaitTime time.Duration
ReadinessShutdownDuration time.Duration
}
Expand All @@ -343,12 +357,13 @@ type runner interface {

type httpServer struct {
http.ServeMux
Port string
}

func (h *httpServer) Run(_ context.Context, _ int) error {
logger.Info("Starting http server...")
srv := &http.Server{
Addr: ":8080",
Addr: ":" + h.Port,
Handler: h,
}
defer srv.Close() // nolint: errcheck
Expand All @@ -357,7 +372,7 @@ func (h *httpServer) Run(_ context.Context, _ int) error {
if err == http.ErrServerClosed {
logger.WithError(err).Info("http server closed")
} else {
wrappedErr := errors.Wrap(err, "Could not listen on :8080")
wrappedErr := errors.Wrap(err, "Could not listen on :"+h.Port)
runtime.HandleError(logger.WithError(wrappedErr), wrappedErr)
}
}
Expand Down
12 changes: 8 additions & 4 deletions install/helm/agones/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
{{- end }}
{{- if and (.Values.agones.metrics.prometheusServiceDiscovery) (.Values.agones.metrics.prometheusEnabled) }}
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/port: {{ .Values.agones.controller.http.port | quote }}
prometheus.io/path: "/metrics"
{{- end }}
{{- if .Values.agones.controller.annotations }}
Expand Down Expand Up @@ -99,6 +99,10 @@ spec:
priorityClassName: {{ .Values.agones.priorityClassName }}
{{- end }}
serviceAccountName: {{ .Values.agones.serviceaccount.controller.name }}
{{- if .Values.agones.controller.hostNetwork }}
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
{{- end }}
containers:
- name: agones-controller
image: "{{ .Values.agones.image.registry }}/{{ .Values.agones.image.controller.name}}:{{ default .Values.agones.image.tag .Values.agones.image.controller.tag }}"
Expand Down Expand Up @@ -180,11 +184,11 @@ spec:
- name: LEADER_ELECTION
value: "true"
{{- end }}
- name: HTTP_PORT
value: {{ .Values.agones.controller.http.port | quote }}
ports:
- name: webhooks
containerPort: 8081
- name: http
containerPort: 8080
containerPort: {{ .Values.agones.controller.http.port }}
livenessProbe:
httpGet:
path: /live
Expand Down
18 changes: 13 additions & 5 deletions install/helm/agones/templates/extensions-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
{{- end }}
{{- if and (.Values.agones.metrics.prometheusServiceDiscovery) (.Values.agones.metrics.prometheusEnabled) }}
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/port: {{ .Values.agones.extensions.http.port | quote }}
prometheus.io/path: "/metrics"
{{- end }}
{{- if .Values.agones.extensions.annotations }}
Expand Down Expand Up @@ -93,6 +93,10 @@ spec:
{{- end }}
serviceAccountName: {{ .Values.agones.serviceaccount.controller.name }}
terminationGracePeriodSeconds: {{ mul .Values.agones.extensions.readiness.periodSeconds .Values.agones.extensions.readiness.failureThreshold 3 }}
{{- if .Values.agones.extensions.hostNetwork }}
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
{{- end }}
containers:
- name: agones-extensions
image: "{{ .Values.agones.image.registry }}/{{ .Values.agones.image.extensions.name}}:{{ default .Values.agones.image.tag .Values.agones.image.extensions.tag }}"
Expand All @@ -107,7 +111,7 @@ spec:
- name: STACKDRIVER_EXPORTER
value: {{ .Values.agones.metrics.stackdriverEnabled | quote }}
- name: STACKDRIVER_LABELS
value: {{ .Values.agones.metrics.stackdriverLabels | quote }}
value: {{ .Values.agones.metrics.stackdriverLabels | quote }}
- name: GCP_PROJECT_ID
value: {{ .Values.agones.metrics.stackdriverProjectID | quote }}
- name: NUM_WORKERS
Expand Down Expand Up @@ -142,11 +146,15 @@ spec:
value: "agones-extensions"
- name: READINESS_SHUTDOWN_DURATION
value: {{ mul .Values.agones.extensions.readiness.periodSeconds .Values.agones.extensions.readiness.failureThreshold 2 }}s
- name: WEBHOOK_PORT
value: {{ .Values.agones.extensions.webhooks.port | quote }}
- name: HTTP_PORT
value: {{ .Values.agones.extensions.http.port | quote }}
ports:
- name: webhooks
containerPort: 8081
containerPort: {{ .Values.agones.extensions.webhooks.port }}
- name: http
containerPort: 8080
containerPort: {{ .Values.agones.extensions.http.port }}
livenessProbe:
httpGet:
path: /live
Expand All @@ -158,7 +166,7 @@ spec:
readinessProbe:
httpGet:
path: /ready
port: 8080
port: {{ .Values.agones.extensions.http.port }}
initialDelaySeconds: {{ .Values.agones.extensions.readiness.initialDelaySeconds }}
periodSeconds: {{ .Values.agones.extensions.readiness.periodSeconds }}
failureThreshold: {{ .Values.agones.extensions.readiness.failureThreshold }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ spec:
agones.dev/role: extensions
ports:
- name: metrics
port: {{ .Values.agones.controller.http.port }}
port: {{ .Values.agones.extensions.http.port }}
targetPort: http
4 changes: 2 additions & 2 deletions install/helm/agones/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ spec:
agones.dev/role: extensions
ports:
- name: webhooks
port: 443
port: {{ .Values.agones.extensions.webhooks.port }}
targetPort: webhooks
- name: web
port: {{ .Values.agones.controller.http.port }}
port: {{ .Values.agones.extensions.http.port }}
targetPort: http
20 changes: 20 additions & 0 deletions install/helm/agones/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ agones:
# memory: 256Mi
nodeSelector: {}
annotations: {}
# Determines if the Agones controller should operate in hostNetwork mode.
#
# This setting is necessary for certain managed Kubernetes clusters (e.g., AWS EKS) that use custom
# CNI plugins (such as Calico or Cilium) because the AWS-managed control plane cannot communicate
# with pod IP CIDRs.
#
# Note: The default port may conflicts with others on the host network. Therefore, if
# running in hostNetwork mode, you should change `http.port` to an available port.
hostNetwork: false
tolerations:
- key: "agones.dev/agones-system"
operator: "Equal"
Expand Down Expand Up @@ -100,6 +109,15 @@ agones:
# memory: 256Mi
nodeSelector: {}
annotations: {}
# Determines if the Agones extensions should operate in hostNetwork mode.
#
# This setting is necessary for certain managed Kubernetes clusters (e.g., AWS EKS) that use custom
# CNI plugins (such as Calico or Cilium) because the AWS-managed control plane cannot communicate
# with pod IP CIDRs.
#
# Note: The default port may conflicts with others on the host network. Therefore, if
# running in hostNetwork mode, you should change `http.port` and `webhooks.port` to an available port.
hostNetwork: false
tolerations:
- key: "agones.dev/agones-system"
operator: "Equal"
Expand All @@ -125,6 +143,8 @@ agones:
numWorkers: 100
apiServerQPS: 400
apiServerQPSBurst: 500
webhooks:
port: 8081
http:
port: 8080
healthCheck:
Expand Down
12 changes: 8 additions & 4 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16932,7 +16932,7 @@ spec:
agones.dev/role: extensions
ports:
- name: webhooks
port: 443
port: 8081
targetPort: webhooks
- name: web
port: 8080
Expand Down Expand Up @@ -17126,9 +17126,9 @@ spec:
value: "agones-controller"
- name: LEADER_ELECTION
value: "true"
- name: HTTP_PORT
value: "8080"
ports:
- name: webhooks
containerPort: 8081
- name: http
containerPort: 8080
livenessProbe:
Expand Down Expand Up @@ -17237,7 +17237,7 @@ spec:
- name: STACKDRIVER_EXPORTER
value: "false"
- name: STACKDRIVER_LABELS
value: ""
value: ""
- name: GCP_PROJECT_ID
value: ""
- name: NUM_WORKERS
Expand Down Expand Up @@ -17270,6 +17270,10 @@ spec:
value: "agones-extensions"
- name: READINESS_SHUTDOWN_DURATION
value: 18s
- name: WEBHOOK_PORT
value: "8081"
- name: HTTP_PORT
value: "8080"
ports:
- name: webhooks
containerPort: 8081
Expand Down
Loading
Loading