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

creating log folders on InitContainer #206

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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