Skip to content

Commit 62bbfba

Browse files
authored
Merge pull request #122 from IBM/update-event-writer
feat: merge event-writer to main
2 parents e3efed8 + 93f5a7a commit 62bbfba

File tree

14 files changed

+776
-291
lines changed

14 files changed

+776
-291
lines changed

Cargo.lock

+352-250
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/core-dump-handler/README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ The agent pod has the following environment variables and these are all set by t
190190
191191
Given the amount of time compression there is an option to disable it.
192192
193+
* COMP_CORE_EVENTS - Enable the creation of a core event file Default: false
194+
195+
Generates a file in a dedicated folder to be picked up by an external process.
196+
197+
* COMP_CORE_EVENT_DIR - The folder where the core dump event is saved.
198+
193199
* CRIO_ENDPOINT - The CRIO endpoint to use.
194200
195201
"unix:///run/containerd/containerd.sock" (Default): This is the default for most containerd nodes
@@ -261,7 +267,8 @@ Composer
261267
* ignoreCrio: Maps to the COMP_IGNORE_CRIO enviroment variable (Default false)
262268
* crioImageCmd: Maps to the COMP_CRIO_IMAGE_CMD enviroment variable (Default "img")
263269
* timeout: Maps to the COMP_TIMEOUT environment variable ("Default 600)
264-
* compression: Maps to the COMP_COMPRESSION environment varable (Default "true")
270+
* compression: Maps to the COMP_COMPRESSION environment variable (Default "true")
271+
* coreEvents: Maps to the COMP_CORE_EVENTS envrironment variable (Default "false")
265272
* filenameTemplate: Maps to COMP_FILENAME_TEMPLATE environment variable
266273
(Default {{uuid}}-dump-{{timestamp}}-{{hostname}}-{{exe_name}}-{{pid}}-{{signal}})
267274
@@ -292,8 +299,10 @@ Composer
292299
293300
Daemonset
294301
* hostDirectory: Maps to the HOST_DIR environment variable (Default "/var/mnt/core-dump-handler")
302+
* coreDirectory: Maps to the CORE_DIR environment variable (Default "/var/mnt/core-dump-handler/cores")
303+
* eventDirectory: Maps to the EVENT_DIR environment variable (Default "/var/mnt/core-dump-handler/events")
295304
* suidDumpable: Maps to the SUID_DUMPABLE environment variable (Default 2)
296-
* vendor: Maps to the VENDOR enviroment variable (Default default)
305+
* vendor: Maps to the VENDOR enviroment variable (Default default)
297306
* interval: Maps to the INTERVAL enviroment variable (Default 60000)
298307
* schedule: Maps to the SCHEDULE enviroment variable (Default "")
299308
* useINotify: Maps to the USE_INOTIFY environment variable (Default false)

charts/core-dump-handler/templates/daemonset.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ spec:
3030
- name: core-volume
3131
mountPath: {{ .Values.daemonset.coreDirectory }}
3232
mountPropagation: Bidirectional
33+
{{- if .Values.composer.events }}
34+
- name: event-volume
35+
mountPath: {{ .Values.daemonset.eventDirectory }}
36+
mountPropagation: Bidirectional
37+
{{- end }}
3338
{{- if .Values.daemonset.mountContainerRuntimeEndpoint }}
3439
- mountPath: {{ .Values.daemonset.hostContainerRuntimeEndpoint }}
3540
name: container-runtime
@@ -51,6 +56,10 @@ spec:
5156
value: {{ .Values.composer.timeout | quote }}
5257
- name: COMP_COMPRESSION
5358
value: {{ .Values.composer.compression | quote }}
59+
- name: COMP_CORE_EVENTS
60+
value: {{ .Values.composer.coreEvents }}
61+
- name: COMP_CORE_EVENT_DIR
62+
value: {{ .Values.daemonset.eventDirectory }}
5463
- name: DEPLOY_CRIO_CONFIG
5564
value: {{ .Values.daemonset.deployCrioConfig | quote }}
5665
- name: CRIO_ENDPOINT
@@ -59,6 +68,8 @@ spec:
5968
value: {{ .Values.daemonset.hostDirectory }}
6069
- name: CORE_DIR
6170
value: {{ .Values.daemonset.coreDirectory }}
71+
- name: EVENT_DIR
72+
value: {{ .Values.daemonset.eventDirectory }}
6273
- name: SUID_DUMPABLE
6374
value: {{ .Values.daemonset.suidDumpable | quote }}
6475
- name: DEPLOY_CRIO_EXE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{ if .Values.composer.coreEvents }}
2+
apiVersion: v1
3+
kind: PersistentVolume
4+
metadata:
5+
name: event-volume
6+
labels:
7+
type: local
8+
spec:
9+
storageClassName: {{ .Values.storageClass }}
10+
claimRef:
11+
name: event-storage-pvc
12+
namespace: {{ .Release.Namespace }}
13+
capacity:
14+
storage: {{ .Values.eventStorage }}
15+
accessModes:
16+
- ReadWriteOnce
17+
persistentVolumeReclaimPolicy: Retain
18+
hostPath:
19+
path: {{ .Values.daemonset.eventDirectory }}
20+
{{ end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{ if .Values.composer.coreEvents }}
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: event-storage-pvc
6+
spec:
7+
accessModes:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: {{ .Values.eventStorage }}
12+
storageClassName: {{ .Values.storageClass }}
13+
{{ end }}

charts/core-dump-handler/values.schema.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
},
123123
"compression": {
124124
"type": "boolean"
125+
},
126+
"coreEvents": {
127+
"type": "boolean"
125128
}
126129
},
127130
"required": [
@@ -131,7 +134,8 @@
131134
"logLength",
132135
"filenameTemplate",
133136
"timeout",
134-
"compression"
137+
"compression",
138+
"coreEvents"
135139
],
136140
"title": "Composer"
137141
},
@@ -207,6 +211,9 @@
207211
"coreDirectory": {
208212
"type": "string"
209213
},
214+
"eventDirectory": {
215+
"type": "string"
216+
},
210217
"suidDumpable": {
211218
"type": "integer"
212219
},
@@ -262,6 +269,7 @@
262269
"extraEnvVars",
263270
"hostDirectory",
264271
"coreDirectory",
272+
"eventDirectory",
265273
"includeCrioExe",
266274
"label",
267275
"manageStoreSecret",

charts/core-dump-handler/values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fullnameOverride: ""
1818
# Size of the Persistent volume to create
1919
hostStorage: 1Gi
2020
coreStorage: 10Gi
21+
eventStorage: 1Gi
2122
storageClass: hostclass
2223

2324
composer:
@@ -29,12 +30,14 @@ composer:
2930
podSelectorLabel: ""
3031
timeout: 600
3132
compression: true
33+
coreEvents: false
3234

3335
daemonset:
3436
name: "core-dump-handler"
3537
label: "core-dump-ds"
3638
hostDirectory: "/var/mnt/core-dump-handler"
3739
coreDirectory: "/var/mnt/core-dump-handler/cores"
40+
eventDirectory: "/var/mnt/core-dump-handler/events"
3841
crioEndpoint: "unix:///run/containerd/containerd.sock"
3942
mountContainerRuntimeEndpoint: false
4043
hostContainerRuntimeEndpoint: "/run/containerd/containerd.sock"

core-dump-agent/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "core-dump-agent"
3-
version = "8.8.0"
3+
version = "8.9.0"
44
authors = ["Anthony Whalley <[email protected]>"]
55
edition = "2021"
66
resolver = "2"

core-dump-agent/src/main.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,23 @@ fn create_env_file(host_location: &str) -> Result<(), std::io::Error> {
479479
let log_length = env::var("LOG_LENGTH").unwrap_or_else(|_| "500".to_string());
480480
let pod_selector_label = env::var("COMP_POD_SELECTOR_LABEL").unwrap_or_default();
481481
let timeout = env::var("COMP_TIMEOUT").unwrap_or_else(|_| "600".to_string());
482+
482483
let compression = env::var("COMP_COMPRESSION")
483484
.unwrap_or_else(|_| "true".to_string())
484485
.to_lowercase();
486+
487+
let core_events = env::var("COMP_CORE_EVENTS")
488+
.unwrap_or_else(|_| "false".to_string())
489+
.to_lowercase();
490+
491+
let event_directory = env::var("COMP_CORE_EVENT_DIR")
492+
.unwrap_or_else(|_| format!("{}/{}", host_location, "events"))
493+
.to_lowercase();
485494
info!("Creating {} file with LOG_LEVEL={}", destination, loglevel);
486495
let mut env_file = File::create(destination)?;
487496
let text = format!(
488-
"LOG_LEVEL={}\nIGNORE_CRIO={}\nCRIO_IMAGE_CMD={}\nUSE_CRIO_CONF={}\nFILENAME_TEMPLATE={}\nLOG_LENGTH={}\nPOD_SELECTOR_LABEL={}\nTIMEOUT={}\nCOMPRESSION={}\n",
489-
loglevel, ignore_crio, crio_image, use_crio_config, filename_template, log_length, pod_selector_label, timeout, compression
497+
"LOG_LEVEL={}\nIGNORE_CRIO={}\nCRIO_IMAGE_CMD={}\nUSE_CRIO_CONF={}\nFILENAME_TEMPLATE={}\nLOG_LENGTH={}\nPOD_SELECTOR_LABEL={}\nTIMEOUT={}\nCOMPRESSION={}\nCORE_EVENTS={}\nEVENT_DIRECTORY={}\n",
498+
loglevel, ignore_crio, crio_image, use_crio_config, filename_template, log_length, pod_selector_label, timeout, compression, core_events, event_directory
490499
);
491500
info!("Writing composer .env \n{}", text);
492501
env_file.write_all(text.as_bytes())?;

core-dump-agent/tests/basic.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ fn basic() -> Result<(), std::io::Error> {
9595
"FILENAME_TEMPLATE={uuid}-dump-{timestamp}-{hostname}-{exe_name}-{pid}-{signal}"
9696
));
9797
assert!(env_content.contains("LOG_LENGTH=500"));
98-
assert_eq!(env_content.lines().count(), 9);
98+
assert!(env_content.contains("EVENTS=false"));
99+
assert!(env_content.contains("EVENT_DIRECTORY=/"));
100+
assert_eq!(env_content.lines().count(), 11);
99101
//TODO: [No9] Test uploading of a corefile
100102
//TODO: [No9] Test remove option
101103
//TODO: [No9] Test sweep option

core-dump-composer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "core-dump-composer"
3-
version = "8.8.0"
3+
version = "8.9.0"
44
authors = ["Anthony Whalley <[email protected]>"]
55
edition = "2021"
66

core-dump-composer/src/config.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ pub struct CoreConfig {
2121
pub pod_selector_label: String,
2222
pub use_crio_config: bool,
2323
pub ignore_crio: bool,
24+
pub core_events: bool,
2425
pub timeout: u32,
2526
pub compression: bool,
27+
pub event_location: PathBuf,
2628
pub image_command: ImageCommand,
2729
pub bin_path: String,
2830
pub os_hostname: String,
@@ -58,12 +60,6 @@ impl CoreConfig {
5860
let directory = matches.value_of("directory").unwrap_or("").to_string();
5961
let hostname = matches.value_of("hostname").unwrap_or("").to_string();
6062
let pathname = matches.value_of("pathname").unwrap_or("").to_string();
61-
// let timeout = matches
62-
// .value_of("timeout")
63-
// .unwrap_or("600")
64-
// .parse::<u64>()
65-
// .unwrap();
66-
// let disable_compression = matches.contains_id("disable-compression");
6763

6864
let uuid = Uuid::new_v4();
6965

@@ -119,6 +115,11 @@ impl CoreConfig {
119115
.unwrap_or_else(|_| "600".to_string())
120116
.parse::<u32>()
121117
.unwrap();
118+
let core_events = env::var("CORE_EVENTS")
119+
.unwrap_or_else(|_| "false".to_string())
120+
.to_lowercase()
121+
.parse::<bool>()
122+
.unwrap();
122123
let os_hostname = hostname::get()
123124
.unwrap_or_else(|_| OsString::from_str("unknown").unwrap_or_default())
124125
.into_string()
@@ -138,7 +139,9 @@ impl CoreConfig {
138139
ImageCommand::from_str(&image_command_string).unwrap_or(ImageCommand::Img);
139140
let filename_template =
140141
env::var("FILENAME_TEMPLATE").unwrap_or_else(|_| String::from(DEFAULT_TEMPLATE));
141-
142+
let event_location = PathBuf::from(
143+
env::var("EVENT_DIRECTORY").unwrap_or_else(|_| format!("{}/events", base_path_str)),
144+
);
142145
Ok(CoreConfig {
143146
log_level,
144147
pod_selector_label,
@@ -154,6 +157,8 @@ impl CoreConfig {
154157
log_length,
155158
params,
156159
compression,
160+
core_events,
161+
event_location,
157162
timeout,
158163
})
159164
}

0 commit comments

Comments
 (0)