Skip to content

Commit

Permalink
remove port pool operations
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed May 17, 2018
1 parent f8faa34 commit 38fc9d4
Show file tree
Hide file tree
Showing 34 changed files with 749 additions and 1,609 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ minikube-ci:
@MAESTRO_TEST_CI=true /bin/bash ./scripts/start-minikube-if-not-yet.sh

work:
@go run main.go worker
@go run main.go worker -v3

clean-int-tests:
@echo 'deleting maestro-test-* namespaces'
Expand All @@ -184,3 +184,9 @@ plugins-linux:

plugins:
@docker run -v $$(pwd)/:/go/src/github.com/topfreegames/maestro -ti golang bash -c "cd /go/src/github.com/topfreegames/maestro && go get github.com/golang/protobuf/protoc-gen-go google.golang.org/grpc golang.org/x/net/context && go build -o bin/grpc.so -buildmode=plugin plugins/grpc/forwarder.go"

.PHONY: mocks

mocks:
@mockgen github.com/topfreegames/maestro/models PortChooser | sed 's/mock_models/mocks/' > mocks/port_chooser.go
@echo 'port chooser mock on ./mocks/port_chooser.go'
13 changes: 9 additions & 4 deletions api/api_suite_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
package api_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
"time"

pgmocks "github.com/topfreegames/extensions/pg/mocks"

"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
pgmocks "github.com/topfreegames/extensions/pg/mocks"
"github.com/topfreegames/maestro/api"
"github.com/topfreegames/maestro/login"
"github.com/topfreegames/maestro/login/mocks"
Expand Down Expand Up @@ -80,7 +82,10 @@ var _ = BeforeSuite(func() {
mockCtrl = gomock.NewController(GinkgoT())
mockLogin = mocks.NewMockLogin(mockCtrl)
app.Login = mockLogin
})

err = models.InitAvailablePorts(app.RedisClient, models.FreePortsRedisKey(), 40000, 60000)
var _ = BeforeEach(func() {
portRange := models.NewPortRange(40000, 60000).String()
err := app.RedisClient.Set(models.GlobalPortsPoolKey, portRange, 0).Err()
Expect(err).NotTo(HaveOccurred())
})
15 changes: 8 additions & 7 deletions api/api_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
package api_test

import (
"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/spf13/viper"
"k8s.io/client-go/kubernetes/fake"

"testing"

clockmocks "github.com/topfreegames/extensions/clock/mocks"
pgmocks "github.com/topfreegames/extensions/pg/mocks"
redismocks "github.com/topfreegames/extensions/redis/mocks"
"github.com/topfreegames/maestro/api"
eventforwardermock "github.com/topfreegames/maestro/eventforwarder/mock"
mtesting "github.com/topfreegames/maestro/testing"

"github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/hooks/test"
"github.com/golang/mock/gomock"
"github.com/spf13/viper"
"github.com/topfreegames/maestro/api"
"github.com/topfreegames/maestro/login/mocks"
"github.com/topfreegames/maestro/models"
mtesting "github.com/topfreegames/maestro/testing"
"k8s.io/client-go/kubernetes/fake"
)

var (
Expand Down
35 changes: 1 addition & 34 deletions api/room_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/go-redis/redis"
goredis "github.com/go-redis/redis"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -72,7 +71,6 @@ forwarders:
Name: namespace,
Game: "game",
Image: "img",
Ports: []*models.Port{&models.Port{ContainerPort: 1234, Name: "port1", Protocol: "UDP"}},
}

pod, err := models.NewPod(name, nil, configYaml, mockClientset, mockRedisClient)
Expand Down Expand Up @@ -250,11 +248,6 @@ forwarders:
var app *api.App
game := "somegame"
BeforeEach(func() {
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult("5000", nil))
mockPipeline.EXPECT().Exec()

createNamespace(namespace, clientset)
err := createPod(roomName, namespace, clientset)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -466,11 +459,6 @@ forwarders:
var app *api.App
game := "somegame"
BeforeEach(func() {
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult("5000", nil))
mockPipeline.EXPECT().Exec()

createNamespace(namespace, clientset)
err := createPod(roomName, namespace, clientset)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -777,11 +765,6 @@ forwarders:
var app *api.App

BeforeEach(func() {
mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult("5000", nil))
mockPipeline.EXPECT().Exec()

createNamespace(namespace, clientset)
err := createPod("roomName", namespace, clientset)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -915,12 +898,7 @@ forwarders:
image = "pong/pong:v123"
name = "roomName"
namespace = "schedulerName"
ports = []*models.Port{
{
ContainerPort: 5050,
},
}
limits = &models.Resources{
limits = &models.Resources{
CPU: "2",
Memory: "128974848",
}
Expand All @@ -934,7 +912,6 @@ forwarders:
Name: namespace,
Game: game,
Image: image,
Ports: ports,
Limits: limits,
Requests: requests,
ShutdownTimeout: shutdownTimeout,
Expand All @@ -945,11 +922,6 @@ forwarders:
err := ns.Create(clientset)
Expect(err).NotTo(HaveOccurred())

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult("5000", nil))
mockPipeline.EXPECT().Exec()

pod, err := models.NewPod(name, nil, configYaml, mockClientset, mockRedisClient)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down Expand Up @@ -978,11 +950,6 @@ forwarders:
err := ns.Create(clientset)
Expect(err).NotTo(HaveOccurred())

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().SPop(models.FreePortsRedisKey()).
Return(goredis.NewStringResult("5000", nil))
mockPipeline.EXPECT().Exec()

pod, err := models.NewPod(name, nil, configYaml, mockClientset, mockRedisClient)
Expect(err).NotTo(HaveOccurred())
_, err = pod.Create(clientset)
Expand Down
9 changes: 5 additions & 4 deletions api/scheduler_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import (
"strings"
"time"

maestroErrors "github.com/topfreegames/maestro/errors"
yaml "gopkg.in/yaml.v2"

"github.com/Sirupsen/logrus"
"github.com/topfreegames/extensions/clock"
"github.com/topfreegames/extensions/redis"
yaml "gopkg.in/yaml.v2"

"github.com/topfreegames/maestro/controller"
maestroErrors "github.com/topfreegames/maestro/errors"
"github.com/topfreegames/maestro/eventforwarder"
"github.com/topfreegames/maestro/models"
)
Expand Down Expand Up @@ -63,7 +63,8 @@ func (g *SchedulerCreateHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques

timeoutSec := g.App.Config.GetInt("scaleUpTimeoutSeconds")
err := mr.WithSegment(models.SegmentController, func() error {
return controller.CreateScheduler(l, mr, g.App.DB, g.App.RedisClient, g.App.KubernetesClient, payload, timeoutSec)
return controller.CreateScheduler(l, mr, g.App.DB, g.App.RedisClient,
g.App.KubernetesClient, payload, timeoutSec)
})

if err != nil {
Expand Down

0 comments on commit 38fc9d4

Please sign in to comment.