Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PortRegistry V2 #183

Merged
merged 3 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
- name: build Docker images
run: make builddockerlocal
- name: GameServer API service unit tests
run: cd cmd/gameserverapi && GIN_MODE=release go test
run: cd cmd/gameserverapi && GIN_MODE=release go test -race
- name: initcontainer unit tests
run: cd cmd/initcontainer && go test
run: cd cmd/initcontainer && go test -race
- name: nodeagent unit tests
run: cd cmd/nodeagent && go test
run: cd cmd/nodeagent && go test -race
- name: operator unit tests
run: IMAGE_NAME_SAMPLE=thundernetes-netcore IMAGE_NAME_INIT_CONTAINER=thundernetes-initcontainer TAG=$(git rev-list HEAD --max-count=1 --abbrev-commit) make -C pkg/operator test
- name: install kind binaries
Expand Down
14 changes: 12 additions & 2 deletions cmd/nodeagent/nodeagentmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ var _ = Describe("nodeagent tests", func() {
if !ok {
return false
}
<<<<<<< HEAD
return tempgs.(*GameServerDetails).IsActive && tempgs.(*GameServerDetails).PreviousGameState == GameStateStandingBy
=======
tempgs.(*GameServerDetails).Mutex.RLock()
gsd := *tempgs.(*GameServerDetails)
tempgs.(*GameServerDetails).Mutex.RUnlock()
return gsd.WasActivated && gsd.PreviousGameState == GameStateStandingBy
>>>>>>> PortRegistry V2
}).Should(BeTrue())

// heartbeat from the game is still StandingBy
Expand Down Expand Up @@ -196,7 +203,7 @@ var _ = Describe("nodeagent tests", func() {
// update GameServer CR to active
gs.Object["status"].(map[string]interface{})["state"] = "Active"
gs.Object["status"].(map[string]interface{})["health"] = "Healthy"
gs.Object["status"].(map[string]interface{})["sessiocCookie"] = "cookie123"
gs.Object["status"].(map[string]interface{})["sessionCookie"] = "cookie123"
_, err = dynamicClient.Resource(gameserverGVR).Namespace(testGameServerNamespace).Update(context.Background(), gs, metav1.UpdateOptions{})
Expect(err).ToNot(HaveOccurred())

Expand All @@ -206,7 +213,10 @@ var _ = Describe("nodeagent tests", func() {
if !ok {
return false
}
return tempgs.(*GameServerDetails).IsActive && tempgs.(*GameServerDetails).PreviousGameState == GameStateStandingBy
tempgs.(*GameServerDetails).Mutex.RLock()
gsd := *tempgs.(*GameServerDetails)
tempgs.(*GameServerDetails).Mutex.RUnlock()
return gsd.IsActive && tempgs.(*GameServerDetails).PreviousGameState == GameStateStandingBy
}).Should(BeTrue())

// heartbeat from the game is still StandingBy
Expand Down
2 changes: 1 addition & 1 deletion docs/howtos/configureportrange.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ nav_order: 7

# Configure Thundernetes port range

By default, Thundernetes will allocate ports in the range 10000-12000 to your GameServers. These ports are allocated to the entire set of VMs in the cluster, meaning that the max number of GameServers is 2000. If you need more or just a different port range, you can configure it via changing the `MIN_PORT` and the `MAX_PORT` environment variables in the controller deployment YAML file.
By default, Thundernetes will allocate ports in the range 10000-12000 to your GameServers. These ports are allocated to the entire set of VMs in the cluster and are open for each and every VM. If you need more or just a different port range, you can configure it via changing the `MIN_PORT` and the `MAX_PORT` environment variables in the controller deployment YAML file. However, do not modify the port range when there game servers running on the cluster, since this will probably corrupt the port registry, especially if the new and the old range are different.
2 changes: 1 addition & 1 deletion pkg/operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ vet: ## Run go vet against code.
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" THUNDERNETES_SAMPLE_IMAGE=$(IMAGE_NAME_SAMPLE):$(NETCORE_SAMPLE_TAG) THUNDERNETES_INIT_CONTAINER_IMAGE=$(IMAGE_NAME_INIT_CONTAINER):$(IMAGE_TAG) go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" THUNDERNETES_SAMPLE_IMAGE=$(IMAGE_NAME_SAMPLE):$(NETCORE_SAMPLE_TAG) THUNDERNETES_INIT_CONTAINER_IMAGE=$(IMAGE_NAME_INIT_CONTAINER):$(IMAGE_TAG) go test -race ./... -v -coverprofile cover.out

##@ Build

Expand Down
10 changes: 7 additions & 3 deletions pkg/operator/controllers/gameserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ func (r *GameServerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
if containsString(gs.GetFinalizers(), finalizerName) {
patch := client.MergeFrom(gs.DeepCopy())
// our finalizer is present, so lets handle any external dependency
r.unassignPorts(&gs)
err := r.unassignPorts(&gs)
if err != nil {
// we're logging the error but no more actions
log.Error(err, "unable to unassign ports. PortRegistry might be corrupt", "GameServer", gs.Name)
}
// remove our finalizer from the list and update it.
controllerutil.RemoveFinalizer(&gs, finalizerName)
if err := r.Patch(ctx, &gs, patch); err != nil {
Expand Down Expand Up @@ -223,7 +227,7 @@ func (r *GameServerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

// unassignPorts will remove any ports that are used by this GameServer from the port registry
func (r *GameServerReconciler) unassignPorts(gs *mpsv1alpha1.GameServer) {
func (r *GameServerReconciler) unassignPorts(gs *mpsv1alpha1.GameServer) error {
hostPorts := make([]int32, 0)
for i := 0; i < len(gs.Spec.Template.Spec.Containers); i++ {
container := gs.Spec.Template.Spec.Containers[i]
Expand All @@ -233,7 +237,7 @@ func (r *GameServerReconciler) unassignPorts(gs *mpsv1alpha1.GameServer) {
}
}
}
r.PortRegistry.DeregisterServerPorts(hostPorts)
return r.PortRegistry.DeregisterServerPorts(hostPorts)
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
Loading