Skip to content

Commit

Permalink
minor refactoring (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios authored Oct 11, 2022
1 parent d68782b commit 94f2c4b
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 423 deletions.
9 changes: 0 additions & 9 deletions cmd/allocator/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions cmd/allocator/build-plugin.sh

This file was deleted.

228 changes: 0 additions & 228 deletions cmd/allocator/main.go

This file was deleted.

23 changes: 3 additions & 20 deletions cmd/e2e/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package main

import (
"context"
"os"
"strconv"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
)

var (
Expand All @@ -19,7 +14,7 @@ var (
keyFile string
fakeCertFile string
fakeKeyFile string
allocationApiSvcPort string
allocationApiSvcPort int32
)

func TestEndToEnd(t *testing.T) {
Expand All @@ -40,18 +35,6 @@ var _ = BeforeSuite(func() {
Expect(fakeCertFile).ToNot(BeEmpty())
fakeKeyFile = os.Getenv("FAKE_TLS_PRIVATE")
Expect(fakeKeyFile).ToNot(BeEmpty())
allocationApiSvcPort = GetAllocationApiSvcPort()
Expect(allocationApiSvcPort).ToNot(BeEmpty())
allocationApiSvcPort = getAllocationApiSvcPort()
Expect(allocationApiSvcPort).ToNot(BeZero())
})

// Function to pull allocation api svc port from the controller
func GetAllocationApiSvcPort() string {
kubeConfig := ctrl.GetConfigOrDie()
kubeClient, err := createKubeClient(kubeConfig)
Expect(err).ToNot(HaveOccurred())
ctx := context.Background()
svc := corev1.Service{}
err = kubeClient.Get(ctx, types.NamespacedName{Namespace: "thundernetes-system", Name: "thundernetes-controller-manager"}, &svc)
Expect(err).ToNot(HaveOccurred())
return strconv.Itoa(int(svc.Spec.Ports[0].Port))
}
15 changes: 14 additions & 1 deletion cmd/e2e/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -276,7 +277,7 @@ func allocate(buildID, sessionID string, cert tls.Certificate) error {
"initialPlayers": []string{"player1", "player2"},
})
postBodyBytes := bytes.NewBuffer(postBody)
resp, err := client.Post("https://localhost:"+allocationApiSvcPort+"/api/v1/allocate", "application/json", postBodyBytes)
resp, err := client.Post(fmt.Sprintf("https://localhost:%d/api/v1/allocate", allocationApiSvcPort), "application/json", postBodyBytes)
//Handle Error
if err != nil {
return err
Expand Down Expand Up @@ -555,3 +556,15 @@ func createTestBuild(buildName, buildID, img string) *mpsv1alpha1.GameServerBuil
},
}
}

// getAllocationApiSvcPort returns the allocation API service port
func getAllocationApiSvcPort() int32 {
kubeConfig := ctrl.GetConfigOrDie()
kubeClient, err := createKubeClient(kubeConfig)
Expect(err).ToNot(HaveOccurred())
ctx := context.Background()
svc := corev1.Service{}
err = kubeClient.Get(ctx, types.NamespacedName{Namespace: "thundernetes-system", Name: "thundernetes-controller-manager"}, &svc)
Expect(err).ToNot(HaveOccurred())
return svc.Spec.Ports[0].Port
}
12 changes: 8 additions & 4 deletions docs/troubleshooting/defaultportinuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ nav_order: 5
By default, Thundernetes's Allocation API listens on port 5000 which is opened with the kind config set-up [here](../quickstart/installing-kind.md). This port can already be in use by another service thus causing Thundernetes to fail.

## Kind Changes
The first step (if using kind) is changing the `kind-config.yaml` to use the port desired. For example:

The first step (if using kind) is changing the `kind-config.yaml` to use the desired port. For example:

{% include code-block-start.md %}
kind: Cluster
Expand All @@ -34,17 +35,20 @@ nodes:
{% include code-block-end.md %}

## YAML Changes
The necessary YAML changes are found within the `manager.yaml` file. A find and replace of `5000` with `{DESIRED_PORT}` will change where the Allocation API listens. In total, there are 5 instances.

The necessary YAML changes are found within the `manager.yaml` file. A find and replace of `5000` with `{DESIRED_PORT}` will change where the Allocation API listens.

Once this file is modified, you can generate new installfiles with `make create-install-files` and verify your changes in `operator.yaml`

### Development - End to end tests
End to end tests also run and listen on port 5000. Once you complete the above yaml change, you also need to modify `e2e/kind-config.yaml` to listen on your desired port. The other needed change is modifying allocationApiSvcPort in `pkg/operator/controllers/sute_test.go`

End to end tests also run and listen on port 5000. Once you complete the above yaml change, you also need to modify `e2e/kind-config.yaml` to listen on your desired port. The other needed change is modifying allocationApiSvcPort in `pkg/operator/controllers/suite_test.go`

## Verify changes

Once these changes are made and thundernetes is running, you can verify the port within the logs using the following:
Once these changes are made and Thundernetes is running, you can verify the port within the logs using the following:
`kubectl -n thundernetes-system logs {thundernetes-controller-manager} | grep addr`

Resulting in the following output:

`2022-10-07T17:01:07Z INFO allocation-api serving allocation API service {"addr": ":5005", "port": 5005}`
Loading

0 comments on commit 94f2c4b

Please sign in to comment.