Skip to content

Commit

Permalink
splitting GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Aug 6, 2022
1 parent be6550c commit f650e3a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is a basic workflow to help you get started with Actions

name: End to end tests

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: "false"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
go-version: 1.18.x
- name: build Docker images
run: make builddockerlocal
- name: install kind binaries
run: make installkind
- name: create kind cluster
run: make createkindcluster
- name: run end-to-end tests
run: make e2elocal
- name: Setup tmate session # instructions on https://github.com/marketplace/actions/debugging-with-tmate
if: ${{ failure() && github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
uses: mxschmitt/action-tmate@v3
24 changes: 3 additions & 21 deletions .github/workflows/main.yml → .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# This is a basic workflow to help you get started with Actions

name: CI
name: Unit tests

# Controls when the workflow will run
on:
Expand All @@ -12,12 +10,7 @@ on:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: "false"


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand Down Expand Up @@ -59,15 +52,4 @@ jobs:
- name: latency server server unit tests
run: cd cmd/latencyserver && 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: build Docker images
run: make builddockerlocal
- name: install kind binaries
run: make installkind
- name: create kind cluster
run: make createkindcluster
- name: run end-to-end tests
run: make e2elocal
- name: Setup tmate session # instructions on https://github.com/marketplace/actions/debugging-with-tmate
if: ${{ failure() && github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
uses: mxschmitt/action-tmate@v3
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
20 changes: 10 additions & 10 deletions pkg/operator/controllers/allocation_api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (s *AllocationApiServer) Start(ctx context.Context) error {
}

// setupIndexers sets up the necessary indexers for the GameServer objects
// specifically, these indexers will allow us to get gameservers by status.sessionID and by spec.BuildID
func (s *AllocationApiServer) setupIndexers(mgr ctrl.Manager) error {
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &mpsv1alpha1.GameServer{}, statusSessionId, func(rawObj client.Object) []string {
gs := rawObj.(*mpsv1alpha1.GameServer)
Expand All @@ -155,7 +156,7 @@ func (s *AllocationApiServer) setupIndexers(mgr ctrl.Manager) error {
return nil
}

// SetupWithManager sets up the allocation api controller with the manager
// SetupWithManager sets up the allocation API controller with the manager
func (s *AllocationApiServer) SetupWithManager(mgr ctrl.Manager) error {
err := s.setupIndexers(mgr)
if err != nil {
Expand All @@ -180,11 +181,11 @@ func (s *AllocationApiServer) Reconcile(ctx context.Context, req ctrl.Request) (
var gs mpsv1alpha1.GameServer
if err := s.Client.Get(ctx, req.NamespacedName, &gs); err != nil {
if apierrors.IsNotFound(err) {
log.Info("Unable to fetch GameServer, it was deleted - deleting from queue")
log.Info("Unable to fetch GameServer, it was deleted - deleting from queue", "namespace", req.Namespace, "name", req.Name)
s.gameServerQueue.RemoveFromQueue(req.Namespace, req.Name)
return ctrl.Result{}, nil
}
log.Error(err, "unable to fetch GameServer")
log.Error(err, "unable to fetch GameServer", "namespace", req.Namespace, "name", req.Name)
return ctrl.Result{}, err
}
// we only put a GameServer to the queue if it has reached the StandingBy state
Expand Down Expand Up @@ -239,14 +240,13 @@ func (s *AllocationApiServer) handleAllocationRequest(w http.ResponseWriter, r *
if err != nil {
if apierrors.IsNotFound(err) {
notFoundError(w, s.logger, err, "not found")
return
} else {
internalServerError(w, s.logger, err, "error listing")
return
}
return
}
if len(gameServerBuilds.Items) == 0 {
notFoundError(w, s.logger, errors.New("build not found"), fmt.Sprintf("Build with ID %s not found", args.BuildID))
notFoundError(w, s.logger, errors.New("GameServerBuild not found"), fmt.Sprintf("GameServerBuild with ID %s not found", args.BuildID))
return
}

Expand Down Expand Up @@ -283,7 +283,7 @@ func (s *AllocationApiServer) handleAllocationRequest(w http.ResponseWriter, r *
// allocation using the heap
for i := 0; i < allocationTries; i++ {
if i > 0 {
s.logger.Info("allocation retrying", "buildID", args.BuildID, "retry count", i, "sessionID", args.SessionID)
s.logger.Info("retrying allocation", "buildID", args.BuildID, "retry count", i, "sessionID", args.SessionID)
}
gs := s.gameServerQueue.PopFromQueue(args.BuildID)
if gs == nil {
Expand Down Expand Up @@ -315,11 +315,11 @@ func (s *AllocationApiServer) handleAllocationRequest(w http.ResponseWriter, r *
err = s.Client.Status().Patch(ctx, &gs2, patch)
if err != nil {
if apierrors.IsConflict(err) {
s.logger.Info("error conflict patching game server", "error", err, "sessionID", args.SessionID, "buildID", args.BuildID, "retry", i)
s.logger.Info("conflict error patching game server", "error", err, "sessionID", args.SessionID, "buildID", args.BuildID, "retry", i)
} else if apierrors.IsNotFound(err) {
s.logger.Info("error not found patching game server", "error", err, "sessionID", args.SessionID, "buildID", args.BuildID, "retry", i)
} else {
s.logger.Error(err, "error patching game server", "sessionID", args.SessionID, "buildID", args.BuildID, "retry", i)
s.logger.Error(err, "uknown error patching game server", "sessionID", args.SessionID, "buildID", args.BuildID, "retry", i)
}
// in case of any error, trigger a reconciliation for this GameServer object
// so it's re-added to the queue
Expand Down Expand Up @@ -349,7 +349,7 @@ func (s *AllocationApiServer) handleAllocationRequest(w http.ResponseWriter, r *
// if we reach this point, it means that we have tried multiple times and failed
// we return the last error, if possible
if err == nil {
err = errors.New("unknown error")
err = errors.New("unknown error, exceeded the maximum number of retries")
}
s.logger.Info("Error allocating", "sessionID", args.SessionID, "buildID", args.BuildID, "error", err)
internalServerError(w, s.logger, err, "error allocating")
Expand Down
19 changes: 11 additions & 8 deletions pkg/operator/controllers/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ const (

LabelBuildID = "BuildID"
LabelBuildName = "BuildName"
LabelOwningGameServer = "OwningGameServer"
LabelOwningOperator = "OwningOperator"
LabelOwningGameServer = "mps.playfab.com/OwningGameServer"
LabelOwningOperator = "mps.playfab.com/OwningOperator"
LabelNodeName = "NodeName"

GsdkConfigFile = DataVolumeMountPath + "/Config/gsdkConfig.json"
LogDirectory = DataVolumeMountPath + "/GameLogs/"
CertificatesDirectory = DataVolumeMountPath + "/GameCertificates"
GsdkConfigFile = DataVolumeMountPath + "/Config/gsdkConfig.json"
GsdkConfigFileWin = DataVolumeMountPathWin + "\\Config\\gsdkConfig.json"

LogDirectory = DataVolumeMountPath + "/GameLogs/"
LogDirectoryWin = DataVolumeMountPathWin + "\\GameLogs\\"

CertificatesDirectory = DataVolumeMountPath + "/GameCertificates"
CertificatesDirectoryWin = DataVolumeMountPathWin + "\\GameCertificates"

GameSharedContentDirectory = DataVolumeMountPath + "/GameSharedContent"
GsdkConfigFileWin = DataVolumeMountPathWin + "\\Config\\gsdkConfig.json"
LogDirectoryWin = DataVolumeMountPathWin + "\\GameLogs\\"
CertificatesDirectoryWin = DataVolumeMountPathWin + "\\GameCertificates"
GameSharedContentDirectoryWin = DataVolumeMountPathWin + "\\GameSharedContent"

DaemonSetPort int32 = 56001
Expand Down

0 comments on commit f650e3a

Please sign in to comment.