diff --git a/cmd/root.go b/cmd/root.go index ba03dee..edd2608 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -18,23 +18,26 @@ package cmd import ( "context" "fmt" - "github.com/Octops/gameserver-ingress-controller/internal/runtime" - "github.com/Octops/gameserver-ingress-controller/pkg/app" + "os" + homedir "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" - "os" + + "github.com/Octops/gameserver-ingress-controller/internal/runtime" + "github.com/Octops/gameserver-ingress-controller/pkg/app" ) var ( - cfgFile string - masterURL string - kubeconfig string - syncPeriod string - webhookPort int - healthProbeBindAddress string - metricsBindAddress string - verbose bool + cfgFile string + masterURL string + kubeconfig string + syncPeriod string + webhookPort int + healthProbeBindAddress string + metricsBindAddress string + verbose bool + maxConcurrentReconciles int ) // rootCmd represents the base command when called without any subcommands @@ -49,12 +52,13 @@ makes the traffic to be routed to the game server using an Ingress Controller.`, logger := runtime.NewLogger(verbose) app.StartController(ctx, logger, app.Config{ - Kubeconfig: kubeconfig, - SyncPeriod: syncPeriod, - Port: webhookPort, - HealthProbeBindAddress: healthProbeBindAddress, - MetricsBindAddress: metricsBindAddress, - Verbose: verbose, + Kubeconfig: kubeconfig, + SyncPeriod: syncPeriod, + Port: webhookPort, + HealthProbeBindAddress: healthProbeBindAddress, + MetricsBindAddress: metricsBindAddress, + Verbose: verbose, + MaxConcurrentReconciles: maxConcurrentReconciles, }) }, } @@ -79,6 +83,7 @@ func init() { rootCmd.Flags().StringVar(&healthProbeBindAddress, "health-probe-addrs", ":30235", "TCP address that the controller should bind to for serving health probes") rootCmd.Flags().StringVar(&metricsBindAddress, "metrics-addrs", ":9090", "TCP address that the controller should bind to for serving prometheus metrics") rootCmd.Flags().IntVar(&webhookPort, "webhook-port", 30234, "Port used by the controller for webhooks") + rootCmd.Flags().IntVar(&maxConcurrentReconciles, "max-concurrent-reconciles", 10, "Maximum number of concurrent reconciles which can be run simultaneously") rootCmd.Flags().BoolVar(&verbose, "verbose", false, "Produce verbose log") } diff --git a/pkg/app/controller.go b/pkg/app/controller.go index edd28e3..a434a63 100644 --- a/pkg/app/controller.go +++ b/pkg/app/controller.go @@ -1,27 +1,30 @@ package app import ( - agonesv1 "agones.dev/agones/pkg/apis/agones/v1" "context" "fmt" + "time" + + agonesv1 "agones.dev/agones/pkg/apis/agones/v1" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "github.com/Octops/gameserver-ingress-controller/pkg/controller" "github.com/Octops/gameserver-ingress-controller/pkg/handlers" "github.com/Octops/gameserver-ingress-controller/pkg/k8sutil" "github.com/Octops/gameserver-ingress-controller/pkg/manager" "github.com/Octops/gameserver-ingress-controller/pkg/record" "github.com/Octops/gameserver-ingress-controller/pkg/stores" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "time" ) type Config struct { - Kubeconfig string - SyncPeriod string - Port int - Verbose bool - HealthProbeBindAddress string - MetricsBindAddress string + Kubeconfig string + SyncPeriod string + Port int + Verbose bool + HealthProbeBindAddress string + MetricsBindAddress string + MaxConcurrentReconciles int } func StartController(ctx context.Context, logger *logrus.Entry, config Config) error { @@ -31,10 +34,11 @@ func StartController(ctx context.Context, logger *logrus.Entry, config Config) e } mgr, err := manager.NewManager(config.Kubeconfig, manager.Options{ - SyncPeriod: &duration, - Port: config.Port, - HealthProbeBindAddress: config.HealthProbeBindAddress, - MetricsBindAddress: config.MetricsBindAddress, + SyncPeriod: &duration, + Port: config.Port, + HealthProbeBindAddress: config.HealthProbeBindAddress, + MetricsBindAddress: config.MetricsBindAddress, + MaxConcurrentReconciles: config.MaxConcurrentReconciles, }) if err != nil { withFatal(logger, err, "failed to create controller manager") diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 2c59597..5c8a42c 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -1,18 +1,24 @@ package manager import ( - "github.com/Octops/gameserver-ingress-controller/pkg/k8sutil" + "time" + "github.com/pkg/errors" + "sigs.k8s.io/controller-runtime/pkg/cache" + ctrlconfig "sigs.k8s.io/controller-runtime/pkg/config" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/manager" - "time" + "sigs.k8s.io/controller-runtime/pkg/webhook" + + "github.com/Octops/gameserver-ingress-controller/pkg/k8sutil" ) type Options struct { - SyncPeriod *time.Duration - Port int - HealthProbeBindAddress string - MetricsBindAddress string + SyncPeriod *time.Duration + Port int + HealthProbeBindAddress string + MetricsBindAddress string + MaxConcurrentReconciles int } type Manager struct { @@ -26,10 +32,16 @@ func NewManager(kubeconfig string, options Options) (*Manager, error) { } mgr, err := manager.New(config, manager.Options{ - SyncPeriod: options.SyncPeriod, - Port: options.Port, + Cache: cache.Options{ + SyncPeriod: options.SyncPeriod, + }, + WebhookServer: webhook.NewServer(webhook.Options{Port: options.Port}), MetricsBindAddress: options.MetricsBindAddress, HealthProbeBindAddress: options.HealthProbeBindAddress, + Controller: ctrlconfig.Controller{ + MaxConcurrentReconciles: options.MaxConcurrentReconciles, + CacheSyncTimeout: time.Second * 30, + }, }) if err != nil { return nil, withError(err)