Skip to content

Commit 59a74c4

Browse files
authored
Update client-go to support Kubernetes 1.18.0 (agones-dev#1998)
* Update vendored client-go to support Kubernets 1.18.0 client-go and related libraries moved to version v0.18.15 This does not include a regeneration of Agones CRD clients. * Updated CRD clients to support Kubernetes 1.18.0 This includes the breaking change that client-go now required a context.Context as well as an Option struct on all API requests. * Updates to e2e tests to comply with client-go changes e2e tests have now been refactored to match the new client-go API surface. * Context handling to align with client-go 0.18.x This commit does two things: 1. Switch from using a `stop` channel to a context.Context throughout the codebase. 2. Use this new Context to accommodate the new client-go API surface and generated clients. The vast majority of this commit is implementing the new api surface, but areas to highlight for functionality changes: - /pkg/util/ folder, especially the workerqueue implementation - /cmd/sdk-server as the new context.Context simplified the timeout functionality. Work on agones-dev#1971 * CI failure fixes: - Allocation tests need to be serial, so they can refresh the client/server certificate. - Just in case, implement retry on creating the secret. - Fixes for flaky TestGameServerReadyAllocateReady - Fix bug in sdkserver local timeout.
1 parent d38f9cd commit 59a74c4

786 files changed

Lines changed: 25641 additions & 12989 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/allocator/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,18 @@ func newServiceHandler(kubeClient kubernetes.Interface, agonesClient versioned.I
241241
remoteAllocationTimeout,
242242
totalRemoteAllocationTimeout)
243243

244-
stop := signals.NewStopChannel()
244+
ctx := signals.NewSigKillContext()
245245
h := serviceHandler{
246246
allocationCallback: func(gsa *allocationv1.GameServerAllocation) (k8sruntime.Object, error) {
247-
return allocator.Allocate(gsa, stop)
247+
return allocator.Allocate(ctx, gsa)
248248
},
249249
mTLSDisabled: mTLSDisabled,
250250
tlsDisabled: tlsDisabled,
251251
}
252252

253-
kubeInformerFactory.Start(stop)
254-
agonesInformerFactory.Start(stop)
255-
if err := allocator.Start(stop); err != nil {
253+
kubeInformerFactory.Start(ctx.Done())
254+
agonesInformerFactory.Start(ctx.Done())
255+
if err := allocator.Start(ctx); err != nil {
256256
logger.WithError(err).Fatal("starting allocator failed.")
257257
}
258258

cmd/controller/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package main
1717

1818
import (
19+
"context"
1920
"io"
2021
"net/http"
2122
"os"
@@ -216,20 +217,20 @@ func main() {
216217
rs = append(rs,
217218
httpsServer, gsCounter, gsController, gsSetController, fleetController, fasController, gasController, server)
218219

219-
stop := signals.NewStopChannel()
220+
ctx := signals.NewSigKillContext()
220221

221-
kubeInformerFactory.Start(stop)
222-
agonesInformerFactory.Start(stop)
222+
kubeInformerFactory.Start(ctx.Done())
223+
agonesInformerFactory.Start(ctx.Done())
223224

224225
for _, r := range rs {
225226
go func(rr runner) {
226-
if runErr := rr.Run(ctlConf.NumWorkers, stop); runErr != nil {
227+
if runErr := rr.Run(ctx, ctlConf.NumWorkers); runErr != nil {
227228
logger.WithError(runErr).Fatalf("could not start runner: %T", rr)
228229
}
229230
}(r)
230231
}
231232

232-
<-stop
233+
<-ctx.Done()
233234
logger.Info("Shut down agones controllers")
234235
}
235236

@@ -403,14 +404,14 @@ func (c *config) validate() []error {
403404
}
404405

405406
type runner interface {
406-
Run(workers int, stop <-chan struct{}) error
407+
Run(ctx context.Context, workers int) error
407408
}
408409

409410
type httpServer struct {
410411
http.ServeMux
411412
}
412413

413-
func (h *httpServer) Run(workers int, stop <-chan struct{}) error {
414+
func (h *httpServer) Run(_ context.Context, _ int) error {
414415
logger.Info("Starting http server...")
415416
srv := &http.Server{
416417
Addr: ":8080",

cmd/ping/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func main() {
4949
logger.WithField("version", pkg.Version).WithField("featureGates", runtime.EncodeFeatures()).
5050
WithField("ctlConf", ctlConf).Info("starting ping...")
5151

52-
stop := signals.NewStopChannel()
52+
ctx := signals.NewSigKillContext()
5353

54-
udpSrv := serveUDP(ctlConf, stop)
54+
udpSrv := serveUDP(ctx, ctlConf)
5555
defer udpSrv.close()
5656

5757
h := healthcheck.NewHandler()
@@ -60,13 +60,13 @@ func main() {
6060
cancel := serveHTTP(ctlConf, h)
6161
defer cancel()
6262

63-
<-stop
63+
<-ctx.Done()
6464
logger.Info("shutting down...")
6565
}
6666

67-
func serveUDP(ctlConf config, stop <-chan struct{}) *udpServer {
67+
func serveUDP(ctx context.Context, ctlConf config) *udpServer {
6868
s := newUDPServer(ctlConf.UDPRateLimit)
69-
s.run(stop)
69+
s.run(ctx)
7070
return s
7171
}
7272

cmd/ping/udp.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package main
1616

1717
import (
1818
"bytes"
19+
"context"
1920
"math"
2021
"net"
2122
"sync"
@@ -67,7 +68,7 @@ func newUDPServer(rateLimit rate.Limit) *udpServer {
6768
}
6869

6970
// run runs the udp server. Non blocking operation
70-
func (u *udpServer) run(stop <-chan struct{}) {
71+
func (u *udpServer) run(ctx context.Context) {
7172
u.healthy()
7273

7374
logger.Info("starting UDP server")
@@ -79,10 +80,10 @@ func (u *udpServer) run(stop <-chan struct{}) {
7980

8081
go func() {
8182
defer u.unhealthy()
82-
wait.Until(u.cleanUp, time.Minute, stop)
83+
wait.Until(u.cleanUp, time.Minute, ctx.Done())
8384
}()
8485

85-
u.readWriteLoop(stop)
86+
u.readWriteLoop(ctx)
8687
}
8788

8889
// cleans up visitors, if they are more than a
@@ -99,12 +100,12 @@ func (u *udpServer) cleanUp() {
99100

100101
// readWriteLoop reads the UDP packet in, and then echos the data back
101102
// in a rate limited way
102-
func (u *udpServer) readWriteLoop(stop <-chan struct{}) {
103+
func (u *udpServer) readWriteLoop(ctx context.Context) {
103104
go func() {
104105
defer u.unhealthy()
105106
for {
106107
select {
107-
case <-stop:
108+
case <-ctx.Done():
108109
return
109110
default:
110111
b := make([]byte, 1024)

cmd/ping/udp_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
package main
1616

1717
import (
18+
"context"
1819
"net"
1920
"testing"
2021
"time"
2122

22-
"k8s.io/apimachinery/pkg/util/wait"
23-
2423
"github.com/stretchr/testify/assert"
2524
"k8s.io/apimachinery/pkg/util/clock"
25+
"k8s.io/apimachinery/pkg/util/wait"
2626
)
2727

2828
type mockAddr struct {
@@ -106,12 +106,12 @@ func TestUDPServerHealth(t *testing.T) {
106106

107107
assert.Error(t, u.Health())
108108

109-
stop := make(chan struct{})
110-
u.run(stop)
109+
ctx, cancel := context.WithCancel(context.Background())
111110

112-
assert.Nil(t, u.Health())
111+
u.run(ctx)
112+
assert.NoError(t, u.Health())
113113

114-
close(stop)
114+
cancel()
115115

116116
err = wait.PollImmediate(time.Second, 5*time.Second, func() (done bool, err error) {
117117
return u.Health() != nil, nil

cmd/sdk-server/main.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package main
1717

1818
import (
19+
"context"
1920
"fmt"
2021
"net"
2122
"net/http"
@@ -37,7 +38,6 @@ import (
3738
"github.com/spf13/pflag"
3839
"github.com/spf13/viper"
3940
"github.com/tmc/grpc-websocket-proxy/wsproxy"
40-
"golang.org/x/net/context"
4141
"google.golang.org/grpc"
4242
"k8s.io/client-go/kubernetes"
4343
"k8s.io/client-go/rest"
@@ -77,8 +77,7 @@ func main() {
7777
time.Sleep(time.Duration(ctlConf.Delay) * time.Second)
7878
}
7979

80-
stop := signals.NewStopChannel()
81-
timedStop := make(chan struct{})
80+
ctx := signals.NewSigKillContext()
8281
grpcServer := grpc.NewServer()
8382
// don't graceful stop, because if we get a kill signal
8483
// then the gameserver is being shut down, and we no longer
@@ -91,8 +90,6 @@ func main() {
9190
Handler: wsproxy.WebsocketProxy(mux),
9291
}
9392
defer httpServer.Close() // nolint: errcheck
94-
ctx, cancel := context.WithCancel(context.Background())
95-
defer cancel()
9693

9794
switch {
9895
case ctlConf.IsLocal:
@@ -103,10 +100,8 @@ func main() {
103100
defer cancel()
104101

105102
if ctlConf.Timeout != 0 {
106-
go func() {
107-
time.Sleep(time.Duration(ctlConf.Timeout) * time.Second)
108-
close(timedStop)
109-
}()
103+
ctx, cancel = context.WithTimeout(ctx, time.Duration(ctlConf.Timeout)*time.Second)
104+
defer cancel()
110105
}
111106
case ctlConf.Test != "":
112107
cancel, err := registerTestSdkServer(grpcServer, ctlConf)
@@ -116,10 +111,8 @@ func main() {
116111
defer cancel()
117112

118113
if ctlConf.Timeout != 0 {
119-
go func() {
120-
time.Sleep(time.Duration(ctlConf.Timeout) * time.Second)
121-
close(timedStop)
122-
}()
114+
ctx, cancel = context.WithTimeout(ctx, time.Duration(ctlConf.Timeout)*time.Second)
115+
defer cancel()
123116
}
124117
default:
125118
var config *rest.Config
@@ -148,7 +141,7 @@ func main() {
148141
}
149142

150143
go func() {
151-
err := s.Run(ctx.Done())
144+
err := s.Run(ctx)
152145
if err != nil {
153146
logger.WithError(err).Fatalf("Could not run sidecar")
154147
}
@@ -162,11 +155,7 @@ func main() {
162155
go runGrpc(grpcServer, grpcEndpoint)
163156
go runGateway(ctx, grpcEndpoint, mux, httpServer)
164157

165-
select {
166-
case <-stop:
167-
case <-timedStop:
168-
}
169-
158+
<-ctx.Done()
170159
logger.Info("shutting down sdk server")
171160
}
172161

cmd/sdk-server/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
package main
1616

1717
import (
18+
"context"
1819
"testing"
1920

2021
"github.com/stretchr/testify/assert"
21-
"golang.org/x/net/context"
2222
"google.golang.org/grpc"
2323
)
2424

examples/simple-game-server/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ WINDOWS_DOCKER_PUSH_ARGS = # When pushing set to --push.
3030

3131
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
3232
project_path := $(dir $(mkfile_path))
33-
server_tag = $(REGISTRY)/simple-game-server:0.1
33+
server_tag = $(REGISTRY)/simple-game-server:0.2
3434
ifdef WITH_WINDOWS
3535
server_tag_linux_amd64 = $(server_tag)-linux_amd64
3636
else

examples/simple-game-server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ func main() {
112112

113113
// doSignal shutsdown on SIGTERM/SIGKILL
114114
func doSignal() {
115-
stop := signals.NewStopChannel()
116-
<-stop
115+
ctx := signals.NewSigKillContext()
116+
<-ctx.Done()
117117
log.Println("Exit signal received. Shutting down.")
118118
os.Exit(0)
119119
}

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/fsnotify/fsnotify v1.4.7
1313
github.com/go-openapi/spec v0.19.3
1414
github.com/golang/protobuf v1.3.2
15-
github.com/googleapis/gnostic v0.1.0 // indirect
15+
github.com/gorilla/websocket v1.4.0
1616
github.com/grpc-ecosystem/grpc-gateway v1.11.3
1717
github.com/hashicorp/golang-lru v0.5.1
1818
github.com/heptiolabs/healthcheck v0.0.0-20171201210846-da5fdee475fb
@@ -31,16 +31,16 @@ require (
3131
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
3232
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72
3333
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03
34-
google.golang.org/grpc v1.23.1
34+
google.golang.org/grpc v1.26.0
3535
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
3636
gopkg.in/fsnotify.v1 v1.4.7
3737
gopkg.in/natefinch/lumberjack.v2 v2.0.0
38-
k8s.io/api v0.17.14
39-
k8s.io/apiextensions-apiserver v0.17.14
40-
k8s.io/apimachinery v0.17.14
41-
k8s.io/client-go v0.17.14
38+
k8s.io/api v0.18.15
39+
k8s.io/apiextensions-apiserver v0.18.15
40+
k8s.io/apimachinery v0.18.15
41+
k8s.io/client-go v0.18.15
4242
k8s.io/kube-openapi v0.0.0-20200410163147-594e756bea31 // indirect
43-
k8s.io/utils v0.0.0-20200124190032-861946025e34
43+
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
4444
)
4545

46-
replace google.golang.org/grpc v1.23.1 => google.golang.org/grpc v1.20.1 // apiserver updated grpc, but we aren't using that, so it's fine.
46+
replace google.golang.org/grpc v1.26.0 => google.golang.org/grpc v1.20.1 // apiserver updated grpc, but we aren't using that, so it's fine.

0 commit comments

Comments
 (0)