Skip to content

Commit

Permalink
creating log folders (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Apr 6, 2022
1 parent e1546de commit aa620f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 29 additions & 5 deletions cmd/initcontainer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func main() {

setLogLevel()

getRestEnvVariables()
getGsdkEnvVariables()

err := createGsdkFolders()
handleError(err)

gamePorts, gamePortConfiguration, err := parsePorts()
if err != nil {
Expand Down Expand Up @@ -176,17 +179,17 @@ func checkEnvOrFatal(envName string, envValue string) {
func getGameServerNameNamespaceFromEnv() {
sessionHostId = os.Getenv("PF_GAMESERVER_NAME")
if sessionHostId == "" {
panic("PF_GAMESERVER_NAME is empty")
handleError(errors.New("PF_GAMESERVER_NAME is empty"))
}

crdNamespace = os.Getenv("PF_GAMESERVER_NAMESPACE")
if crdNamespace == "" {
panic("PF_GAMESERVER_NAMESPACE is empty")
handleError(errors.New("PF_GAMESERVER_NAMESPACE is empty"))
}
}

// getRestEnvVariables gets the rest environment variables
func getRestEnvVariables() {
// getGsdkEnvVariables gets the GSDK environment variables
func getGsdkEnvVariables() {
heartbeatEndpointPort = os.Getenv("HEARTBEAT_ENDPOINT_PORT")
checkEnvOrFatal("HEARTBEAT_ENDPOINT_PORT", heartbeatEndpointPort)

Expand Down Expand Up @@ -224,3 +227,24 @@ func setLogLevel() {

log.SetLevel(logLevel)
}

// createFolderIfNotExists creates the folder if it does not exist
func createFolderIfNotExists(path string) error {
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(path, os.ModePerm)
if err != nil {
return err
}
}
return nil
}

// createGsdkFolders creates the folders for the GSDK related methods
func createGsdkFolders() error {
// for the time being, we create only the server log folder
err := createFolderIfNotExists(serverLogPath)
if err != nil {
return err
}
return nil
}
4 changes: 4 additions & 0 deletions pkg/operator/controllers/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ func getGameServerEnvVariables(gs *mpsv1alpha1.GameServer) []corev1.EnvVar {
Name: "PF_TITLE_ID",
Value: gs.Spec.TitleID,
},
{
Name: "PF_SERVER_LOG_DIRECTORY",
Value: LogDirectory,
},
}

return envList
Expand Down

0 comments on commit aa620f5

Please sign in to comment.