Skip to content

Commit

Permalink
feat: Add support for shared values files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian May committed Apr 26, 2024
1 parent f48a71f commit 025b99b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 32 deletions.
24 changes: 23 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ use serde::{Deserialize, Serialize, Serializer};

use crate::utils::filename_to_string;


#[derive(Deserialize, Debug)]
pub enum ValuesFormat {
PlainText,
Vals,
Sops,
}

#[derive(Deserialize, Debug)]
pub struct ValuesFile {
pub path: PathBuf,
pub format: ValuesFormat,
}

/// A Env config file.
///
/// Retrieved from `./envs/$env/config.yaml`.
Expand Down Expand Up @@ -93,7 +107,7 @@ pub enum AnnouncePolicy {
/// A release config file.
///
/// Retrieved from `./envs/$env/$cluster/$release_dir/config.yaml`.
#[derive(Serialize, Deserialize, Debug)]
#[derive(Deserialize, Debug)]
pub struct ReleaseConfig {
#[serde(alias = "charts-version")]
pub charts_version: Option<String>,
Expand All @@ -106,6 +120,14 @@ pub struct ReleaseConfig {
pub release_chart: ChartReference,
pub depends: Option<Vec<ReleaseReference>>,
pub announce_policy: Option<AnnouncePolicy>,

/// These files are processed first have have lowest priority.
#[serde(default)]
pub base_values_files: Vec<ValuesFile>,

/// These files are processed last and have highest priority.
#[serde(default)]
pub override_values_files: Vec<ValuesFile>,
}

/// Parsed details concerning an Env.
Expand Down
15 changes: 1 addition & 14 deletions src/helm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use url::Url;

use crate::{
command::{CommandLine, CommandResult, CommandSuccess},
config::{AnnouncePolicy, ChartReference, ReleaseReference},
config::{AnnouncePolicy, ChartReference, ReleaseReference, ValuesFile, ValuesFormat},
output::{Message, MultiOutput},
HelmReposLock, Update,
};
Expand Down Expand Up @@ -60,19 +60,6 @@ fn aws_path() -> OsString {
/// A unique identifier for an installation.
pub type InstallationId = u16;

#[derive(Debug)]
pub enum ValuesFormat {
PlainText,
Vals,
Sops,
}

#[derive(Debug)]
pub struct ValuesFile {
pub path: PathBuf,
pub format: ValuesFormat,
}

/// All the information required for an helm release to be processed.
#[derive(Debug)]
pub struct Installation {
Expand Down
36 changes: 19 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use tracing_subscriber::{Layer, Registry};
mod command;

mod helm;
use helm::{HelmChart, Installation, ValuesFile, ValuesFormat};
use helm::{HelmChart, Installation};
use helm::{HelmRepo, InstallationId};

mod depends;
Expand All @@ -45,7 +45,7 @@ mod output;
use output::{Message, MultiOutput, Output, Sender};

mod config;
use config::Overrides;
use config::{Overrides, ValuesFile, ValuesFormat};
use config::Release;
use config::{ChartReference, Cluster, Env};

Expand Down Expand Up @@ -587,11 +587,20 @@ fn create_installation(
cluster: &Cluster,
release: Release,
id: InstallationId,
// helm_repos: &HelmRepos,
) -> Installation {
let depends = release.config.depends.unwrap_or_default();

let mut values_files: Vec<ValuesFile> = vec![];

for base_values_file in release.config.base_values_files {
let path = release.dir.join(&base_values_file.path);
let values_file = ValuesFile {
path,
format: base_values_file.format,
};
values_files.push(values_file);
}

let values_file = release.dir.join("values.yaml");
if values_file.is_file() {
values_files.push(ValuesFile {
Expand All @@ -607,20 +616,13 @@ fn create_installation(
});
}

let encrypted_file = release.dir.join("secrets.sops.yaml");
if encrypted_file.is_file() {
values_files.push(ValuesFile {
path: encrypted_file,
format: ValuesFormat::Sops,
});
}

let encrypted_file = release.dir.join("secrets.vals.yaml");
if encrypted_file.is_file() {
values_files.push(ValuesFile {
path: encrypted_file,
format: ValuesFormat::Vals,
});
for override_values_file in release.config.override_values_files {
let path = release.dir.join(&override_values_file.path);
let values_file = ValuesFile {
path,
format: override_values_file.format,
};
values_files.push(values_file);
}

// Turn legacy config into new config
Expand Down

0 comments on commit 025b99b

Please sign in to comment.