From bd0e48b300cf84c32f35abc593c7f8edf1aa842a Mon Sep 17 00:00:00 2001 From: Kriti Date: Mon, 22 Aug 2022 13:46:44 -0700 Subject: [PATCH 1/2] Add two new configs to set that the splunk is running in container env --- inventory/environ.py | 2 ++ roles/splunk_common/tasks/main.yml | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/inventory/environ.py b/inventory/environ.py index 3e6b81cb..e15a73b5 100755 --- a/inventory/environ.py +++ b/inventory/environ.py @@ -162,6 +162,8 @@ def getSplunkPaths(vars_scope): splunk_vars = vars_scope["splunk"] splunk_vars["opt"] = os.environ.get("SPLUNK_OPT", splunk_vars.get("opt")) splunk_vars["home"] = os.environ.get("SPLUNK_HOME", splunk_vars.get("home")) + splunk_vars["containerEnv"] = os.environ.get("SPLUNK_CONTAINER_ENV", splunk_vars.get("containerEnv")) + splunk_vars["cgroup"] = os.environ.get("SPLUNK_CGROUP_PATH", splunk_vars.get("cgroup")) # Not sure if we should expose this - exec is fixed relative to SPLUNK_HOME splunk_vars["exec"] = os.environ.get("SPLUNK_EXEC", splunk_vars.get("exec")) # Not sure if we should expose this - pid is fixed relative to SPLUNK_HOME diff --git a/roles/splunk_common/tasks/main.yml b/roles/splunk_common/tasks/main.yml index a212069d..d0a235e9 100644 --- a/roles/splunk_common/tasks/main.yml +++ b/roles/splunk_common/tasks/main.yml @@ -130,4 +130,29 @@ - include_tasks: add_splunk_license.yml - include_tasks: disable_popups.yml - when: "'disable_popups' in splunk and splunk.disable_popups | bool" \ No newline at end of file + when: "'disable_popups' in splunk and splunk.disable_popups | bool" + +# set containerEnv to true in limits.conf +- name: set_container_true + ini_file: + dest: "{{ splunk.home }}/etc/system/local/limits.conf" + section: default + option: "containerEnv" + value: "{{ splunk.containerEnv }}" + owner: "{{ splunk.user }}" + group: "{{ splunk.group }}" + when: + - splunk.containerEnv is defined + - splunk.containerEnv | bool + +# set cgroup path, if defined, in limits.conf +- name: set_cgroup_path + ini_file: + dest: "{{ splunk.home }}/etc/system/local/limits.conf" + section: default + option: "cgroup" + value: "{{ splunk.cgroup }}" + owner: "{{ splunk.user }}" + group: "{{ splunk.group }}" + when: + - splunk.cgroup is defined \ No newline at end of file From 0b6a16355975cc1e09cdf4adfcd69c803a1239c2 Mon Sep 17 00:00:00 2001 From: Kriti Date: Mon, 22 Aug 2022 22:07:51 -0700 Subject: [PATCH 2/2] Create new function --- inventory/environ.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/inventory/environ.py b/inventory/environ.py index e15a73b5..e3dd1e81 100755 --- a/inventory/environ.py +++ b/inventory/environ.py @@ -113,6 +113,7 @@ def getDefaultVars(): getASan(defaultVars) getDisablePopups(defaultVars) getHEC(defaultVars) + getContainerEnv(defaultVars) getSecrets(defaultVars) getSplunkPaths(defaultVars) getIndexerClustering(defaultVars) @@ -162,8 +163,6 @@ def getSplunkPaths(vars_scope): splunk_vars = vars_scope["splunk"] splunk_vars["opt"] = os.environ.get("SPLUNK_OPT", splunk_vars.get("opt")) splunk_vars["home"] = os.environ.get("SPLUNK_HOME", splunk_vars.get("home")) - splunk_vars["containerEnv"] = os.environ.get("SPLUNK_CONTAINER_ENV", splunk_vars.get("containerEnv")) - splunk_vars["cgroup"] = os.environ.get("SPLUNK_CGROUP_PATH", splunk_vars.get("cgroup")) # Not sure if we should expose this - exec is fixed relative to SPLUNK_HOME splunk_vars["exec"] = os.environ.get("SPLUNK_EXEC", splunk_vars.get("exec")) # Not sure if we should expose this - pid is fixed relative to SPLUNK_HOME @@ -525,6 +524,13 @@ def getHEC(vars_scope): else: vars_scope["splunk"]["hec"]["ssl"] = bool(vars_scope["splunk"]["hec"].get("ssl")) +def getContainerEnv(vars_scope): + """ + Get the configured max cpu, vcpu, and system memory + """ + vars_scope["splunk"]["containerEnv"] = os.environ.get("SPLUNK_CONTAINER_ENV", vars_scope["splunk"].get("containerEnv")) + vars_scope["splunk"]["cgroup"] = os.environ.get("SPLUNK_CGROUP_PATH", vars_scope["splunk"].get("cgroup")) + def getDSP(vars_scope): """ Configure DSP settings