Skip to content

Commit 867b4a7

Browse files
committed
Parameterise changes
Signed-off-by: Anthony Whalley <[email protected]>
1 parent 0f688bd commit 867b4a7

File tree

9 files changed

+52
-26
lines changed

9 files changed

+52
-26
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ spec:
4747
value: {{ .Values.composer.crioImageCmd }}
4848
- name: COMP_POD_SELECTOR_LABEL
4949
value: {{ .Values.composer.podSelectorLabel }}
50+
- name: COMP_TIMEOUT
51+
value: {{ .Values.composer.timeout | quote }}
52+
- name: COMP_COMPRESSION
53+
value: {{ .Values.composer.compression | quote }}
5054
- name: DEPLOY_CRIO_CONFIG
5155
value: {{ .Values.daemonset.deployCrioConfig | quote }}
5256
- name: CRIO_ENDPOINT

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,23 @@
115115
},
116116
"podSelectorLabel": {
117117
"type": "string"
118+
},
119+
"timeout": {
120+
"type": "integer",
121+
"minimum": 120
122+
},
123+
"compression": {
124+
"type": "boolean"
118125
}
119126
},
120127
"required": [
121128
"crioImageCmd",
122129
"ignoreCrio",
123130
"logLevel",
124131
"logLength",
125-
"filenameTemplate"
132+
"filenameTemplate",
133+
"timeout",
134+
"compression"
126135
],
127136
"title": "Composer"
128137
},
@@ -183,7 +192,7 @@
183192
"hostContainerRuntimeEndpoint"
184193
]
185194
}
186-
}
195+
}
187196
],
188197
"properties": {
189198
"name": {
@@ -316,4 +325,4 @@
316325
"title": "ServiceAccount"
317326
}
318327
}
319-
}
328+
}

charts/core-dump-handler/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ composer:
2727
filenameTemplate: "{uuid}-dump-{timestamp}-{hostname}-{exe_name}-{pid}-{signal}"
2828
logLength: 500
2929
podSelectorLabel: ""
30+
timeout: 600
31+
compression: true
3032

3133
daemonset:
3234
name: "core-dump-handler"

core-dump-agent/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,15 @@ fn create_env_file(host_location: &str) -> Result<(), std::io::Error> {
473473
});
474474
let log_length = env::var("LOG_LENGTH").unwrap_or_else(|_| "500".to_string());
475475
let pod_selector_label = env::var("COMP_POD_SELECTOR_LABEL").unwrap_or_default();
476+
let timeout = env::var("COMP_TIMEOUT").unwrap_or_else(|_| "600".to_string());
477+
let compression = env::var("COMP_COMPRESSION")
478+
.unwrap_or_else(|_| "true".to_string())
479+
.to_lowercase();
476480
info!("Creating {} file with LOG_LEVEL={}", destination, loglevel);
477481
let mut env_file = File::create(destination)?;
478482
let text = format!(
479-
"LOG_LEVEL={}\nIGNORE_CRIO={}\nCRIO_IMAGE_CMD={}\nUSE_CRIO_CONF={}\nFILENAME_TEMPLATE={}\nLOG_LENGTH={}\nPOD_SELECTOR_LABEL={}\n",
480-
loglevel, ignore_crio, crio_image, use_crio_config, filename_template, log_length, pod_selector_label
483+
"LOG_LEVEL={}\nIGNORE_CRIO={}\nCRIO_IMAGE_CMD={}\nUSE_CRIO_CONF={}\nFILENAME_TEMPLATE={}\nLOG_LENGTH={}\nPOD_SELECTOR_LABEL={}\nTIMEOUT={}\nCOMPRESSION={}\n",
484+
loglevel, ignore_crio, crio_image, use_crio_config, filename_template, log_length, pod_selector_label, timeout, compression
481485
);
482486
info!("Writing composer .env \n{}", text);
483487
env_file.write_all(text.as_bytes())?;

core-dump-agent/tests/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ 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(), 7);
98+
assert_eq!(env_content.lines().count(), 9);
9999
//TODO: [No9] Test uploading of a corefile
100100
//TODO: [No9] Test remove option
101101
//TODO: [No9] Test sweep option

core-dump-composer/src/config.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ pub struct CoreConfig {
2121
pub pod_selector_label: String,
2222
pub use_crio_config: bool,
2323
pub ignore_crio: bool,
24+
pub timeout: u32,
25+
pub compression: bool,
2426
pub image_command: ImageCommand,
2527
pub bin_path: String,
2628
pub os_hostname: String,
2729
pub filename_template: String,
2830
pub params: CoreParams,
29-
pub disable_compression: bool,
3031
}
3132

3233
#[derive(Serialize)]
@@ -39,7 +40,6 @@ pub struct CoreParams {
3940
pub directory: String,
4041
pub hostname: String,
4142
pub pathname: String,
42-
pub timeout: u64,
4343
pub namespace: Option<String>,
4444
pub podname: Option<String>,
4545
pub uuid: Uuid,
@@ -58,12 +58,12 @@ impl CoreConfig {
5858
let directory = matches.value_of("directory").unwrap_or("").to_string();
5959
let hostname = matches.value_of("hostname").unwrap_or("").to_string();
6060
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");
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");
6767

6868
let uuid = Uuid::new_v4();
6969

@@ -76,7 +76,6 @@ impl CoreConfig {
7676
directory,
7777
hostname,
7878
pathname,
79-
timeout,
8079
namespace: None,
8180
podname: None,
8281
uuid,
@@ -112,6 +111,14 @@ impl CoreConfig {
112111
.unwrap_or_else(|_| "false".to_string().to_lowercase())
113112
.parse::<bool>()
114113
.unwrap();
114+
let compression = env::var("COMPRESSION")
115+
.unwrap_or_else(|_| "true".to_string().to_lowercase())
116+
.parse::<bool>()
117+
.unwrap();
118+
let timeout = env::var("TIMEOUT")
119+
.unwrap_or_else(|_| "600".to_string())
120+
.parse::<u32>()
121+
.unwrap();
115122
let os_hostname = hostname::get()
116123
.unwrap_or_else(|_| OsString::from_str("unknown").unwrap_or_default())
117124
.into_string()
@@ -146,7 +153,8 @@ impl CoreConfig {
146153
filename_template,
147154
log_length,
148155
params,
149-
disable_compression,
156+
compression,
157+
timeout,
150158
})
151159
}
152160

core-dump-composer/src/main.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ mod logging;
2121
fn main() -> Result<(), anyhow::Error> {
2222
let (send, recv) = channel();
2323
let cc = config::CoreConfig::new()?;
24-
let timeout = cc.params.timeout;
25-
24+
let recv_time: u64 = cc.timeout as u64;
2625
thread::spawn(move || {
2726
let result = handle(cc);
2827
send.send(result).unwrap();
2928
});
3029

31-
let result = recv.recv_timeout(Duration::from_secs(timeout));
30+
let result = recv.recv_timeout(Duration::from_secs(recv_time));
3231

3332
match result {
3433
Ok(inner_result) => inner_result,
@@ -111,10 +110,10 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
111110
cc.set_podname(podname.to_string());
112111

113112
// Create the base zip file that we are going to put everything into
114-
let compression_method = if cc.disable_compression {
115-
zip::CompressionMethod::Stored
116-
} else {
113+
let compression_method = if cc.compression {
117114
zip::CompressionMethod::Deflated
115+
} else {
116+
zip::CompressionMethod::Stored
118117
};
119118
let options = FileOptions::default()
120119
.compression_method(compression_method)

core-dump-composer/tests/timeout.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn timeout_scenario() -> Result<(), std::io::Error> {
4444
.unwrap();
4545

4646
let cdc = Command::new("../target/debug/core-dump-composer")
47+
.env("TIMEOUT", "1")
4748
.arg("-c")
4849
.arg("1000000000")
4950
.arg("-e")
@@ -60,8 +61,6 @@ fn timeout_scenario() -> Result<(), std::io::Error> {
6061
.arg("1588462466")
6162
.arg("-h")
6263
.arg("crashing-app-699c49b4ff-86wrh")
63-
.arg("--timeout")
64-
.arg("1")
6564
.stdin(cat)
6665
.output()
6766
.expect("Couldn't execute");

0 commit comments

Comments
 (0)