forked from github-mirrorer/quake-kube
Add Agones Healthcheck and Ready state
This commit is contained in:
@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ import (
|
|||||||
quakeserver "github.com/criticalstack/quake-kube/internal/quake/server"
|
quakeserver "github.com/criticalstack/quake-kube/internal/quake/server"
|
||||||
httputil "github.com/criticalstack/quake-kube/internal/util/net/http"
|
httputil "github.com/criticalstack/quake-kube/internal/util/net/http"
|
||||||
"github.com/criticalstack/quake-kube/public"
|
"github.com/criticalstack/quake-kube/public"
|
||||||
|
|
||||||
|
sdk "agones.dev/agones/sdks/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var opts struct {
|
var opts struct {
|
||||||
@ -24,6 +27,7 @@ var opts struct {
|
|||||||
AssetsDir string
|
AssetsDir string
|
||||||
ConfigFile string
|
ConfigFile string
|
||||||
WatchInterval time.Duration
|
WatchInterval time.Duration
|
||||||
|
WithAgones bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommand() *cobra.Command {
|
func NewCommand() *cobra.Command {
|
||||||
@ -52,6 +56,37 @@ func NewCommand() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.WithAgones {
|
||||||
|
log.Println("starting Agones SDK client")
|
||||||
|
s, err := sdk.NewSDK()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Agones SDK could not be initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.Ready(); err != nil {
|
||||||
|
log.Println("failed to make the server Ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
tick := time.Tick(2 * time.Second)
|
||||||
|
maxAttempts := 0
|
||||||
|
for {
|
||||||
|
if err := s.Health(); err != nil {
|
||||||
|
if maxAttempts > 5 {
|
||||||
|
log.Fatalf("Could not send health ping: %v", err)
|
||||||
|
}
|
||||||
|
maxAttempts++
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Print("Stopped health pings")
|
||||||
|
return
|
||||||
|
case <-tick:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
s := quakeserver.Server{
|
s := quakeserver.Server{
|
||||||
Dir: opts.AssetsDir,
|
Dir: opts.AssetsDir,
|
||||||
@ -88,5 +123,6 @@ func NewCommand() *cobra.Command {
|
|||||||
cmd.Flags().StringVar(&opts.ClientAddr, "client-addr", "0.0.0.0:8080", "client address <host>:<port>")
|
cmd.Flags().StringVar(&opts.ClientAddr, "client-addr", "0.0.0.0:8080", "client address <host>:<port>")
|
||||||
cmd.Flags().StringVar(&opts.ServerAddr, "server-addr", "0.0.0.0:27960", "dedicated server <host>:<port>")
|
cmd.Flags().StringVar(&opts.ServerAddr, "server-addr", "0.0.0.0:27960", "dedicated server <host>:<port>")
|
||||||
cmd.Flags().DurationVar(&opts.WatchInterval, "watch-interval", 15*time.Second, "dedicated server <host>:<port>")
|
cmd.Flags().DurationVar(&opts.WatchInterval, "watch-interval", 15*time.Second, "dedicated server <host>:<port>")
|
||||||
|
cmd.Flags().BoolVar(&opts.WithAgones, "with-agones", false, "use Agones SDK integration")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user