@@ -50,33 +50,30 @@ var _ sdk.SDKServer = &SDKServer{}
5050// SDKServer is a gRPC server, that is meant to be a sidecar
5151// for a GameServer that will update the game server status on SDK requests
5252type SDKServer struct {
53- logger * logrus.Entry
54- gameServerName string
55- namespace string
56- informerFactory externalversions.SharedInformerFactory
57- gameServerGetter typedv1alpha1.GameServersGetter
58- gameServerLister v1alpha1.GameServerLister
59- gameServerSynced cache.InformerSynced
60- server * http.Server
61- clock clock.Clock
62- healthDisabled bool
63- healthTimeout time.Duration
64- healthFailureThreshold int64
65- healthMutex sync.RWMutex
66- healthLastUpdated time.Time
67- healthFailureCount int64
68- workerqueue * workerqueue.WorkerQueue
69- streamMutex sync.RWMutex
70- connectedStreams []sdk.SDK_WatchGameServerServer
71- stop <- chan struct {}
72- recorder record.EventRecorder
53+ logger * logrus.Entry
54+ gameServerName string
55+ namespace string
56+ informerFactory externalversions.SharedInformerFactory
57+ gameServerGetter typedv1alpha1.GameServersGetter
58+ gameServerLister v1alpha1.GameServerLister
59+ gameServerSynced cache.InformerSynced
60+ server * http.Server
61+ clock clock.Clock
62+ health stablev1alpha1.Health
63+ healthTimeout time.Duration
64+ healthMutex sync.RWMutex
65+ healthLastUpdated time.Time
66+ healthFailureCount int32
67+ workerqueue * workerqueue.WorkerQueue
68+ streamMutex sync.RWMutex
69+ connectedStreams []sdk.SDK_WatchGameServerServer
70+ stop <- chan struct {}
71+ recorder record.EventRecorder
7372}
7473
7574// NewSDKServer creates a SDKServer that sets up an
7675// InClusterConfig for Kubernetes
77- func NewSDKServer (gameServerName , namespace string ,
78- healthDisabled bool , healthTimeout time.Duration , healthFailureThreshold int64 , healthInitialDelay time.Duration ,
79- kubeClient kubernetes.Interface ,
76+ func NewSDKServer (gameServerName , namespace string , kubeClient kubernetes.Interface ,
8077 agonesClient versioned.Interface ) (* SDKServer , error ) {
8178 mux := http .NewServeMux ()
8279
@@ -97,13 +94,10 @@ func NewSDKServer(gameServerName, namespace string,
9794 Addr : ":8080" ,
9895 Handler : mux ,
9996 },
100- clock : clock.RealClock {},
101- healthDisabled : healthDisabled ,
102- healthFailureThreshold : healthFailureThreshold ,
103- healthTimeout : healthTimeout ,
104- healthMutex : sync.RWMutex {},
105- healthFailureCount : 0 ,
106- streamMutex : sync.RWMutex {},
97+ clock : clock.RealClock {},
98+ healthMutex : sync.RWMutex {},
99+ healthFailureCount : 0 ,
100+ streamMutex : sync.RWMutex {},
107101 }
108102
109103 s .informerFactory = factory
@@ -140,7 +134,6 @@ func NewSDKServer(gameServerName, namespace string,
140134 }
141135 })
142136
143- s .initHealthLastUpdated (healthInitialDelay )
144137 s .workerqueue = workerqueue .NewWorkerQueue (
145138 func (key string ) error {
146139 return s .updateState (stablev1alpha1 .State (key ))
@@ -161,7 +154,28 @@ func (s *SDKServer) initHealthLastUpdated(healthInitialDelay time.Duration) {
161154
162155// Run processes the rate limited queue.
163156// Will block until stop is closed
164- func (s * SDKServer ) Run (stop <- chan struct {}) {
157+ func (s * SDKServer ) Run (stop <- chan struct {}) error {
158+ s .informerFactory .Start (stop )
159+ cache .WaitForCacheSync (stop , s .gameServerSynced )
160+
161+ gs , err := s .gameServerLister .GameServers (s .namespace ).Get (s .gameServerName )
162+ if err != nil {
163+ return errors .Wrapf (err , "error retrieving gameserver %s/%s" , s .namespace , s .gameServerName )
164+ }
165+
166+ // grab configuration details
167+ s .health = gs .Spec .Health
168+ s .logger .WithField ("health" , s .health ).Info ("setting health configuration" )
169+ s .healthTimeout = time .Duration (gs .Spec .Health .PeriodSeconds ) * time .Second
170+ s .initHealthLastUpdated (time .Duration (gs .Spec .Health .InitialDelaySeconds ) * time .Second )
171+
172+ // start health checking running
173+ if ! s .health .Disabled {
174+ s .logger .Info ("Starting GameServer health checking" )
175+ go wait .Until (s .runHealth , s .healthTimeout , stop )
176+ }
177+
178+ // then start the http endpoints
165179 s .logger .Info ("Starting SDKServer http health check..." )
166180 go func () {
167181 if err := s .server .ListenAndServe (); err != nil {
@@ -175,16 +189,10 @@ func (s *SDKServer) Run(stop <-chan struct{}) {
175189 }()
176190 defer s .server .Close () // nolint: errcheck
177191
178- if ! s .healthDisabled {
179- s .logger .Info ("Starting GameServer health checking" )
180- go wait .Until (s .runHealth , s .healthTimeout , stop )
181- }
182-
183- s .informerFactory .Start (stop )
184- cache .WaitForCacheSync (stop , s .gameServerSynced )
185192 // need this for streaming gRPC commands
186193 s .stop = stop
187194 s .workerqueue .Run (1 , stop )
195+ return nil
188196}
189197
190198// updateState sets the GameServer Status's state to the state
@@ -371,11 +379,11 @@ func (s *SDKServer) checkHealth() {
371379// currently healthy or not based on the configured
372380// failure count vs failure threshold
373381func (s * SDKServer ) healthy () bool {
374- if s .healthDisabled {
382+ if s .health . Disabled {
375383 return true
376384 }
377385
378386 s .healthMutex .RLock ()
379387 defer s .healthMutex .RUnlock ()
380- return s .healthFailureCount < s .healthFailureThreshold
388+ return s .healthFailureCount < s .health . FailureThreshold
381389}
0 commit comments