_palworld.tpl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {{- define "palworld.workload" -}}
  2. workload:
  3. palworld:
  4. enabled: true
  5. primary: true
  6. type: Deployment
  7. podSpec:
  8. hostNetwork: {{ .Values.palworldNetwork.hostNetwork }}
  9. securityContext:
  10. fsGroup: {{ .Values.palworldID.group }}
  11. containers:
  12. palworld:
  13. enabled: true
  14. primary: true
  15. imageSelector: image
  16. securityContext:
  17. runAsUser: 0
  18. runAsGroup: 0
  19. runAsNonRoot: false
  20. readOnlyRootFilesystem: false
  21. capabilities:
  22. add:
  23. - CHOWN
  24. - DAC_OVERRIDE
  25. - FOWNER
  26. - SETGID
  27. - SETUID
  28. - SYS_RESOURCE
  29. - KILL
  30. env:
  31. STEAMCMD_DIR: /serverdata/steamcmd
  32. {{- $srvDir := "/serverdata/serverfiles" }}
  33. SERVER_DIR: {{ $srvDir }}
  34. # This var does not seem to be used from the container script
  35. # But is documented in the README, we currently update the password
  36. # with the initContainer, keeping this here to avoid inconsistencies
  37. # in case the container script is updated
  38. SRV_ADMIN_PWD: {{ .Values.palworldConfig.adminPassword }}
  39. GAME_PARAMS: {{ join " " .Values.palworldConfig.gameParams }}
  40. GAME_PARAMS_EXTRA: {{ join " " .Values.palworldConfig.gameParamsExtra }}
  41. UPDATE_PUBLIC_IP: {{ .Values.palworldConfig.updatePublicIP }}
  42. VALIDATE: {{ .Values.palworldConfig.validate }}
  43. USERNAME: {{ .Values.palworldConfig.username }}
  44. PASSWORD: {{ .Values.palworldConfig.password }}
  45. BACKUP: {{ .Values.palworldConfig.backup.enabled | default false }}
  46. BACKUP_INTERVAL: {{ .Values.palworldConfig.backup.interval | default 120 }}
  47. BACKUPS_TO_KEEP: {{ .Values.palworldConfig.backup.keep | default 3 }}
  48. fixedEnv:
  49. PUID: {{ .Values.palworldID.user }}
  50. {{ with .Values.palworldConfig.additionalEnvs }}
  51. envList:
  52. {{ range $env := . }}
  53. - name: {{ $env.name }}
  54. value: {{ $env.value }}
  55. {{ end }}
  56. {{ end }}
  57. probes:
  58. liveness:
  59. enabled: true
  60. type: tcp
  61. port: {{ .Values.palworldNetwork.rconPort }}
  62. readiness:
  63. enabled: true
  64. type: tcp
  65. port: {{ .Values.palworldNetwork.rconPort }}
  66. startup:
  67. enabled: true
  68. type: tcp
  69. port: {{ .Values.palworldNetwork.rconPort }}
  70. initContainers:
  71. 01-config:
  72. enabled: true
  73. type: init
  74. imageSelector: image
  75. securityContext:
  76. runAsUser: 0
  77. runAsGroup: 0
  78. runAsNonRoot: false
  79. readOnlyRootFilesystem: false
  80. capabilities:
  81. add:
  82. - CHOWN
  83. - DAC_OVERRIDE
  84. - FOWNER
  85. command: /bin/bash
  86. args:
  87. - -c
  88. - |
  89. config={{ $srvDir }}/Pal/Saved/Config/LinuxServer
  90. cfgFile=${config}/PalWorldSettings.ini
  91. if [ ! -d ${config} ]; then
  92. echo "Config directory not found, creating..."
  93. mkdir -p ${config}
  94. fi
  95. if [ ! -f ${cfgFile} ]; then
  96. echo "Config file not found, fetching..."
  97. # -- Fetch the config file if it doesn't exist, just like the container does
  98. wget -qO ${cfgFile} https://github.com/ich777/docker-steamcmd-server/raw/palworld/config/PalWorldSettings.ini
  99. fi
  100. set_ini_value() {
  101. local key="${1}"
  102. local value="${2}"
  103. local quote="${3:-false}"
  104. local print="${4:-true}"
  105. # -- Escape special characters for sed
  106. escaped_value=$(printf '%s\n' "$value" | sed 's/[&/\]/\\&/g')
  107. if [ "$quote" = true ]; then
  108. escaped_value="\"${escaped_value}\""
  109. fi
  110. echo "Setting ${key}..."
  111. # Check if the key already exists
  112. if grep -q "^OptionSettings=\(.*${key}=.*\)$" "${cfgFile}"; then
  113. # Key exists, update its value using the original logic
  114. sed -i "s|\(${key}=\)[^,]*|\1${escaped_value}|g" "${cfgFile}"
  115. else
  116. # Key doesn't exist, append it right after "OptionSettings=("
  117. sed -i "s|^\(OptionSettings=(\)|\1${key}=${escaped_value}, |" "${cfgFile}"
  118. fi
  119. if [ "$print" = true ]; then
  120. echo "Set to $(grep -Po "(?<=${key}=)[^,]*" "${cfgFile}")"
  121. fi
  122. }
  123. set_ini_value "RCONEnabled" True
  124. set_ini_value "RCONPort" {{ .Values.palworldNetwork.rconPort }}
  125. set_ini_value "PublicPort" {{ .Values.palworldNetwork.serverPort }}
  126. set_ini_value "ServerName" {{ .Values.palworldConfig.server.name | quote }} true
  127. set_ini_value "ServerDescription" {{ .Values.palworldConfig.server.description | quote }} true
  128. set_ini_value "ServerPassword" {{ .Values.palworldConfig.server.password | squote }} true false
  129. set_ini_value "AdminPassword" {{ .Values.palworldConfig.adminPassword | squote }} true false
  130. set_ini_value "AllowConnectPlatform" {{ .Values.palworldConfig.allowPlatform }} false
  131. {{- range $item := .Values.palworldConfig.iniKeys }}
  132. {{- $k := $item.key -}}
  133. {{- $v := $item.value | toString -}}
  134. {{- $numRegex := "^[0-9]+([.][0-9]+)?$" -}}
  135. {{- $boolRegex := "^(true|false)$" -}}
  136. {{- if (mustRegexMatch $numRegex $v) }}
  137. echo "Key [{{ $k }}] is a number, setting without quotes..."
  138. set_ini_value "{{ $k }}" {{ $v }}
  139. {{- else if (mustRegexMatch $boolRegex ($v | lower)) }}
  140. echo "Key [{{ $k }}] is a boolean, setting without quotes..."
  141. set_ini_value "{{ $k }}" {{ (toString $v) | camelcase }}
  142. {{- else }}
  143. echo "Key [{{ $k }}] is a string, setting with quotes..."
  144. set_ini_value "{{ $k }}" {{ $v | quote }} true
  145. {{- end }}
  146. {{- end }}
  147. echo "Done!"
  148. {{- end -}}