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

Configurable Allocation API Port #419

Merged
merged 28 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2a6cbae
Modified Files to allow for port as env variable
nottagg Sep 23, 2022
9eae5ff
Separated listening ports into int and str
nottagg Sep 26, 2022
563e001
Modified Files to allow for port as env variable
nottagg Sep 23, 2022
96c33a1
Separated listening ports into int and str
nottagg Sep 26, 2022
4b800a7
Merge branch 'AllocationAPIPorts' of https://github.com/nottagg/thund…
nottagg Sep 26, 2022
6e10601
Merge branch 'PlayFab:main' into AllocationAPIPorts
nottagg Sep 26, 2022
73b5a1e
Rebuild Installfiles and adjusted default port
nottagg Sep 26, 2022
9e8cd55
Merge branch 'AllocationAPIPorts' of https://github.com/nottagg/thund…
nottagg Sep 26, 2022
70d0ef8
Changes to get e2e tests to have variable port
nottagg Sep 27, 2022
678c983
Merge branch 'PlayFab:main' into AllocationAPIPorts
nottagg Sep 27, 2022
d1bea18
Set default back to 5000
nottagg Sep 27, 2022
4a0fb7f
Fix typo
nottagg Sep 27, 2022
63aeaba
Merge branch 'main' into AllocationAPIPorts
nottagg Sep 30, 2022
bf2aa64
Changed name of vars, replaced shell cmds
nottagg Oct 3, 2022
8667ca5
Merge branch 'AllocationAPIPorts' of https://github.com/nottagg/thund…
nottagg Oct 3, 2022
a947b34
Remove dynamic port from unit tests and makefile
nottagg Oct 4, 2022
f4b54e2
Merge branch 'main' into AllocationAPIPorts
nottagg Oct 4, 2022
6bc5fcc
Fix camel case, make const for test
nottagg Oct 4, 2022
bc250e1
Adjust e2e test for new alloc api utility
nottagg Oct 7, 2022
273bd52
md for Changing port
nottagg Oct 7, 2022
186ae19
Merge branch 'PlayFab:main' into AllocationAPIPorts
nottagg Oct 7, 2022
4447aa4
Added fmt
nottagg Oct 7, 2022
0b279f6
Commiting modified installfile
nottagg Oct 7, 2022
55779a8
Move allocation port to suite_test
nottagg Oct 10, 2022
184c478
Updated Doc
nottagg Oct 10, 2022
360f2ff
Made api port come from suite_test
nottagg Oct 10, 2022
8b24c02
Fixed controller suite_test
nottagg Oct 10, 2022
8d7c44b
Adjusted controller and doc
nottagg Oct 10, 2022
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

NS ?= ghcr.io/playfab/

export LISTENING_PORT=5000
nottagg marked this conversation as resolved.
Show resolved Hide resolved
export IMAGE_NAME_OPERATOR=thundernetes-operator
export IMAGE_NAME_NODE_AGENT=thundernetes-nodeagent
export IMAGE_NAME_NODE_AGENT_WIN=thundernetes-nodeagent-win
Expand Down Expand Up @@ -97,6 +98,8 @@ create-install-files:
IMAGE_NAME_NODE_AGENT=$(NS)$(IMAGE_NAME_NODE_AGENT) \
IMAGE_NAME_NODE_AGENT_WIN=$(NS)$(IMAGE_NAME_NODE_AGENT_WIN) \
LOG_LEVEL=info \
STR_LISTENING_PORT=\"$(LISTENING_PORT)\" \
INT_LISTENING_PORT=$(LISTENING_PORT) \
make -C pkg/operator create-install-files

create-install-files-dev:
Expand All @@ -108,6 +111,8 @@ create-install-files-dev:
IMAGE_NAME_NODE_AGENT=$(NS)$(IMAGE_NAME_NODE_AGENT) \
IMAGE_NAME_NODE_AGENT_WIN=$(NS)$(IMAGE_NAME_NODE_AGENT_WIN) \
LOG_LEVEL=debug \
STR_LISTENING_PORT=\"$(LISTENING_PORT)\" \
INT_LISTENING_PORT=$(LISTENING_PORT) \
make -C pkg/operator create-install-files

clean:
Expand Down
33 changes: 23 additions & 10 deletions cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ type AllocationResult struct {
}

var (
ip string
certFile string
keyFile string
tlsSet bool
ar *AllocationResult
ip string
certFile string
keyFile string
tlsSet bool
listeningPort string
ar *AllocationResult
)

func main() {
Expand All @@ -40,15 +41,16 @@ func main() {
} else if strings.Compare(args[1], "allocate") == 0 {
fmt.Println("Beginning the allocate process")

//pulls ip and port into output
cmd := exec.Command("kubectl", "get", "svc", "-n", "thundernetes-system", "thundernetes-controller-manager",
"-o", "jsonpath='{.status.loadBalancer.ingress[0].ip}'")
"-o", "jsonpath={.status.loadBalancer.ingress[0].ip},{.spec.ports[0].port}")

output, err := cmd.CombinedOutput()

//if there's an error it's likely because no path
if err != nil {
log.Println("Is required to have kubectl on your $PATH")
log.Fatal(string(output))

}

if len(args) < 5 { // if no more arguments are provided
Expand All @@ -61,7 +63,18 @@ func main() {
tlsSet = true
}

if len(output) < 3 { // basically if we don't have a valid IP
//Read output until comma for ip
var s strings.Builder
for i := 0; i < len(output); i++ {
if output[i] == ',' {
ip = s.String()
s.Reset()
}
s.WriteString(string(output[i]))
}
listeningPort = s.String()

if len(ip) < 3 { // basically if we don't have a valid IP
if tlsSet == true {
ip = "https://127.0.0.1"
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
Expand Down Expand Up @@ -137,7 +150,7 @@ func allocateTls(ip string, buildID string, sessionID string, cert tls.Certifica
})

postBodyBytes := bytes.NewBuffer(postBody)
resp, err := client.Post(ip+":5000/api/v1/allocate", "application/json", postBodyBytes)
resp, err := client.Post(ip+":"+listeningPort+"/api/v1/allocate", "application/json", postBodyBytes)

//Handle Error
if err != nil {
Expand Down Expand Up @@ -182,7 +195,7 @@ func allocateNoTls(ip string, buildID string, sessionID string) (*AllocationResu
})

postBodyBytes := bytes.NewBuffer(postBody)
resp, err := client.Post(ip+":5000/api/v1/allocate", "application/json", postBodyBytes)
resp, err := client.Post(ip+":"+listeningPort+"/api/v1/allocate", "application/json", postBodyBytes)

//Handle Error
if err != nil {
Expand Down
16 changes: 15 additions & 1 deletion cmd/e2e/utilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os/exec"
"strings"
"time"

Expand All @@ -28,6 +30,7 @@ import (
)

var connectedPlayers = []string{"Amie", "Ken", "Dimitris"} // this should the same as in the netcore sample
var listeningPort string

const (
testNamespace = "e2e"
Expand Down Expand Up @@ -269,14 +272,25 @@ func allocate(buildID, sessionID string, cert tls.Certificate) error {
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}

//Block of code to make port grabbing dynamic
nottagg marked this conversation as resolved.
Show resolved Hide resolved
cmd := exec.Command("kubectl", "get", "svc", "-n", "thundernetes-system", "thundernetes-controller-manager",
"-o", "jsonpath={.spec.ports[0].port}")
output, err := cmd.CombinedOutput()
if err != nil {
log.Println("Port could not be found to run e2e test")
log.Fatal(err)
}
listeningPort := string(output)
//Trim the quotes that are pulled

postBody, _ := json.Marshal(map[string]interface{}{
"buildID": buildID,
"sessionID": sessionID,
"sessionCookie": "randomCookie",
"initialPlayers": []string{"player1", "player2"},
})
postBodyBytes := bytes.NewBuffer(postBody)
resp, err := client.Post("https://localhost:5000/api/v1/allocate", "application/json", postBodyBytes)
resp, err := client.Post("https://localhost:"+listeningPort+"/api/v1/allocate", "application/json", postBodyBytes)
//Handle Error
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export FAKE_TLS_PUBLIC=/tmp/${RANDOM}.pem
openssl req -x509 -newkey rsa:4096 -nodes -keyout ${FAKE_TLS_PRIVATE} -out ${FAKE_TLS_PUBLIC} -days 365 -subj '/CN=localhost'

echo "-----Compiling, building and deploying the operator to local Kubernetes cluster-----"
IMG=${IMAGE_NAME_OPERATOR}:${IMAGE_TAG} API_SERVICE_SECURITY=usetls make -C "${DIR}"/../pkg/operator deploye2e
IMG=${IMAGE_NAME_OPERATOR}:${IMAGE_TAG} API_SERVICE_SECURITY=usetls INT_LISTENING_PORT=${LISTENING_PORT} STR_LISTENING_PORT=\"${LISTENING_PORT}\" make -C "${DIR}"/../pkg/operator deploye2e

echo "-----Deploying GameServer API-----"
cd cmd/gameserverapi/deployment/default
Expand Down
Loading