Skip to content

Commit

Permalink
improvements after running on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Feb 6, 2022
1 parent 99edd24 commit 13c6d2b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
5 changes: 4 additions & 1 deletion cmd/e2e/gameserverapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (
port = 5001
host = "localhost"
contentType = "application/json"
timeout = time.Second * 10
duration = time.Second * 10
interval = time.Millisecond * 250
)

var imgName string
Expand Down Expand Up @@ -142,7 +145,7 @@ var _ = Describe("GameServerAPI tests", func() {
r, err = client.Get(fmt.Sprintf("%s/gameservers/%s/%s", url, testNamespace, gsName))
Expect(err).ToNot(HaveOccurred())
return r.StatusCode
}).Should(Equal(http.StatusNotFound))
}, timeout, interval).Should(Equal(http.StatusNotFound))

// make sure controller creates an extra GameServer
Eventually(func() int {
Expand Down
2 changes: 1 addition & 1 deletion cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
)

const (
loopTimesConst int = 10
loopTimesConst int = 15
delayInSecondsForLoopTest int = 1
LabelBuildID = "BuildID"
invalidStatusCode string = "invalid status code"
Expand Down
21 changes: 17 additions & 4 deletions cmd/gameserverapi/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ metadata:
name: thundernetes-gameserverapi
namespace: thundernetes-system
labels:
control-plane: thundernetes-gameserverapi
app: thundernetes-gameserverapi
spec:
selector:
matchLabels:
control-plane: thundernetes-gameserverapi
app: thundernetes-gameserverapi
replicas: 1
template:
metadata:
labels:
control-plane: thundernetes-gameserverapi
app: thundernetes-gameserverapi
spec:
containers:
- image: thundernetes-gameserverapi:${IMAGE_TAG}
Expand All @@ -29,16 +29,29 @@ spec:
ports:
- containerPort: 5001
hostPort: 5001
livenessProbe:
httpGet:
path: /healthz
port: 5001
initialDelaySeconds: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /healthz
port: 5001
initialDelaySeconds: 3
periodSeconds: 10
serviceAccountName: thundernetes-controller-manager
terminationGracePeriodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: thundernetes-gameserverapi
namespace: thundernetes-system
spec:
selector:
control-plane: thundernetes-gameserverapi
app: thundernetes-gameserverapi
ports:
- protocol: TCP
port: 5001
Expand Down
9 changes: 8 additions & 1 deletion cmd/gameserverapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func setupRouter() *gin.Engine {
r.PATCH(fmt.Sprintf("%s/gameserverbuilds/:namespace/:buildName", urlprefix), patchGameServerBuild)
r.GET(fmt.Sprintf("%s/gameserverbuilds/:namespace/:buildName/gameserverdetails", urlprefix), listGameServerDetailsForBuild)
r.GET(fmt.Sprintf("%s/gameserverdetails/:namespace/:gameServerDetailName", urlprefix), getGameServerDetail)
r.GET("/healthz", healthz)
return r
}

Expand Down Expand Up @@ -212,9 +213,11 @@ func patchGameServerBuild(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "standingBy > max"})
return
}

patch := client.MergeFrom(gsb.DeepCopy())
gsb.Spec.Max = int(newMax)
gsb.Spec.StandingBy = int(newStandingBy)
err = kubeClient.Update(ctx, &gsb)
err = kubeClient.Patch(ctx, &gsb, patch)
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand Down Expand Up @@ -277,3 +280,7 @@ func getGameServerDetail(c *gin.Context) {
c.JSON(http.StatusOK, gsd)
}
}

func healthz(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
}
23 changes: 11 additions & 12 deletions e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ openssl req -x509 -newkey rsa:4096 -nodes -keyout ${TLS_PRIVATE} -out ${TLS_PUBL
kubectl create namespace thundernetes-system
kubectl create secret tls tls-secret -n thundernetes-system --cert=${TLS_PUBLIC} --key=${TLS_PRIVATE}

echo "-----Compiling, building and deploying to local Kubernetes cluster-----"
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 deploy

echo "-----Deploying GameServer API-----"
IMAGE_TAG=${IMAGE_TAG} envsubst < cmd/gameserverapi/deploy.yaml | kubectl apply -f -

echo "-----Waiting for Controller deployment-----"
kubectl wait --for=condition=available --timeout=300s deployment/thundernetes-controller-manager -n thundernetes-system

echo "-----Running Go tests-----"
pushd cmd/e2e
go mod tidy && go run $(ls -1 *.go | grep -v _test.go) ${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG}
echo "-----Waiting for GameServer API deployment-----"
kubectl wait --for=condition=ready --timeout=300s pod -n thundernetes-system -l app=thundernetes-gameserverapi

echo "-----Deploying GameServer API-----"
popd # go back to the root directory
pushd cmd/gameserverapi
IMAGE_TAG=${IMAGE_TAG} envsubst < deploy.yaml | kubectl apply -f -
echo "-----Running end to end tests-----"
cd cmd/e2e
go mod tidy && go run $(ls -1 *.go | grep -v _test.go) ${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG}

echo "-----Waiting for GameServer API deployment-----"
kubectl wait --for=condition=available --timeout=300s deployment/thundernetes-gameserverapi -n thundernetes-system
echo "-----Running GameServer API tests-----"
# create the gameserverapi namespace for the GameServer API tests
kubectl create namespace gameserverapi
popd # go back to the root directory
cd cmd/e2e && IMG=${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG} go test ./...
IMG=${IMAGE_NAME_NETCORE_SAMPLE}:${IMAGE_TAG} go test -count=1 ./...

0 comments on commit 13c6d2b

Please sign in to comment.