Skip to content

Commit

Permalink
Merge pull request #58 from Octops/add-max-concurrent-arg
Browse files Browse the repository at this point in the history
Expose max-concurrent-reconciles flag
  • Loading branch information
danieloliveira079 authored Sep 30, 2023
2 parents 075eec1 + 109d294 commit 53a482c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OCTOPS_BIN := bin/octops-controller

IMAGE_REPO=octops/gameserver-ingress-controller
DOCKER_IMAGE_TAG ?= octops/gameserver-ingress-controller:${VERSION}
RELEASE_TAG=0.2.7
RELEASE_TAG=0.2.8

default: clean build

Expand Down
41 changes: 23 additions & 18 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
})
},
}
Expand All @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion deploy/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
spec:
serviceAccountName: octops-ingress-controller
containers:
- image: octops/gameserver-ingress-controller:0.2.7 # Latest release
- image: octops/gameserver-ingress-controller:0.2.8 # Latest release
name: controller
ports:
- containerPort: 30235
Expand Down
32 changes: 18 additions & 14 deletions pkg/app/controller.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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")
Expand Down
28 changes: 20 additions & 8 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 53a482c

Please sign in to comment.