Skip to content
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
80 changes: 31 additions & 49 deletions src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::io;

use crate::{
config::config::{ConfigType, FileFormat, RoozCfg, SystemConfig},
constants,
model::{
types::AnyError,
volume::{RoozVolume, RoozVolumeRole},
volume::{RoozVolume, RoozVolumeRole, VolumeFile},
},
util::labels::Labels,
};
Expand All @@ -27,47 +26,47 @@ pub trait ConfigReader {
}

impl<'a> ConfigApi<'a> {
pub async fn store(
async fn store_config_file(
&self,
workspace_key: &str,
origin: &str,
body: &str,
config_type: &ConfigType,
content: &str,
labels: Option<Labels>,
) -> Result<(), AnyError> {
let config_vol = RoozVolume::config_data(
workspace_key,
"/etc/rooz",
Some(
[(ConfigType::Body.file_path().to_string(), body.to_string())]
.into_iter()
.collect(),
),
Some(Labels::from(&[Labels::config_origin(origin)])),
labels,
Some(RoozVolumeRole::WorkspaceConfig),
);
self.api
.volume
.ensure_mounts(&vec![config_vol], None, Some(constants::ROOT_UID))
.await?;
Ok(())
.write_files(
&config_vol,
&[VolumeFile::new(config_type.file_path(), content)],
None,
)
.await
}

pub async fn store_bases(&self, workspace_key: &str, body: &str) -> Result<(), AnyError> {
let config_vol = RoozVolume::config_data(
pub async fn store(
&self,
workspace_key: &str,
origin: &str,
body: &str,
) -> Result<(), AnyError> {
self.store_config_file(
workspace_key,
"/etc/rooz",
Some(
[(ConfigType::Bases.file_path().to_string(), body.to_string())]
.into_iter()
.collect(),
),
None,
Some(RoozVolumeRole::WorkspaceConfig),
);
self.api
.volume
.ensure_mounts(&vec![config_vol], None, Some(constants::ROOT_UID))
.await?;
Ok(())
&ConfigType::Body,
body,
Some(Labels::from(&[Labels::config_origin(origin)])),
)
.await
}

pub async fn store_bases(&self, workspace_key: &str, body: &str) -> Result<(), AnyError> {
self.store_config_file(workspace_key, &ConfigType::Bases, body, None)
.await
}

pub async fn read(
Expand Down Expand Up @@ -97,25 +96,8 @@ impl<'a> ConfigApi<'a> {
}

pub async fn store_runtime(&self, workspace_key: &str, data: &str) -> Result<(), AnyError> {
let config_vol = RoozVolume::config_data(
workspace_key,
"/etc/rooz",
Some(
[(
ConfigType::Runtime.file_path().to_string(),
data.to_string(),
)]
.into_iter()
.collect(),
),
None,
Some(RoozVolumeRole::WorkspaceConfig),
);
self.api
.volume
.ensure_mounts(&vec![config_vol], None, Some(constants::ROOT_UID))
.await?;
Ok(())
self.store_config_file(workspace_key, &ConfigType::Runtime, data, None)
.await
}

fn edit_error(&self, message: &str) -> () {
Expand Down
15 changes: 8 additions & 7 deletions src/api/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ impl<'a> WorkspaceApi<'a> {

let mounts: HashMap<String, MountSource> = s.mounts.clone();

let volumes_v2 = VolumeApi::create_volume_specs(
let volume_specs = VolumeApi::create_volume_specs(
workspace_key,
&config.data,
&config.all_mounts(),
false,
);

self.api.volume.ensure_volumes_v2(&volumes_v2).await?;
self.api.volume.ensure_volumes(&volume_specs).await?;

let mut mounts_v2 = Vec::new();
let mut container_mounts = Vec::new();

let mounts_all = mounts
.iter()
Expand All @@ -58,13 +58,14 @@ impl<'a> WorkspaceApi<'a> {
let mounts_config =
self.api
.volume
.mounts_with_sources(&volumes_v2, &mounts_all, false);
.mounts_with_sources(&volume_specs, &mounts_all, false);

//TODO: not setting home dir as it depends on the user. When using uid the user might not
// exist so it hard to make it work predictably. Consider marking as not supported by design
let real_mounts = VolumeApi::real_mounts_v2(mounts_config.clone(), None);
let real_mounts = VolumeApi::real_mounts(mounts_config.clone(), None);

mounts_v2.extend_from_slice(self.api.volume.mounts_v2(&real_mounts).await?.as_slice());
container_mounts
.extend_from_slice(self.api.volume.mounts(&real_mounts).await?.as_slice());

for (t, m) in real_mounts.clone() {
s.real_mounts.insert(t.clone(), m.clone());
Expand Down Expand Up @@ -116,7 +117,7 @@ impl<'a> WorkspaceApi<'a> {
} else {
Some(args.clone())
},
mounts: Some(mounts_v2),
mounts: Some(container_mounts),
ports: Some(ports),
work_dir: Some(s.work_dir.as_str()),
run_mode: RunMode::Sidecar,
Expand Down
11 changes: 6 additions & 5 deletions src/api/system_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::OnceLock;
use crate::{
api::Api,
config::config::SystemConfig,
constants,
model::{types::AnyError, volume::RoozVolume},
};

Expand All @@ -12,11 +13,11 @@ impl<'a> Api<'a> {
.container
.one_shot_output(
"read-sys-config",
"ls /tmp/sys/rooz.config > /dev/null 2>&1 && cat /tmp/sys/rooz.config || true"
.into(),
Some(vec![
RoozVolume::system_config_read("/tmp/sys").to_mount(None),
]),
format!(
"ls /tmp/sys/{f} > /dev/null 2>&1 && cat /tmp/sys/{f} || true",
f = constants::SYSTEM_CONFIG_FILE
),
Some(vec![RoozVolume::system_config("/tmp/sys").to_mount(None)]),
None,
None,
)
Expand Down
Loading