Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logging::for_container helper #721

Merged
merged 2 commits into from
Jan 19, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.

- Added `Option::as_ref_or_else` to `utils` ([#717]).
- Added `ListenerOperatorVolumeSourceBuilder::build_pvc` ([#719]).
- Added `Logging::for_container` ([#721]).

### Changed

Expand All @@ -16,6 +17,7 @@ All notable changes to this project will be documented in this file.

[#717]: https://github.com/stackabletech/operator-rs/pull/717
[#719]: https://github.com/stackabletech/operator-rs/pull/719
[#721]: https://github.com/stackabletech/operator-rs/pull/721

## [0.61.0] - 2024-01-15

Expand Down
16 changes: 14 additions & 2 deletions src/product_logging/spec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Logging structure used within Custom Resource Definitions

use std::collections::BTreeMap;
use std::fmt::Display;
use std::{borrow::Cow, collections::BTreeMap, fmt::Display};

use crate::config::{
fragment::{self, Fragment, FromFragment},
Expand Down Expand Up @@ -81,6 +80,19 @@ where
pub containers: BTreeMap<T, ContainerLogConfig>,
}

impl<T> Logging<T>
where
T: Clone + Display + Ord,
{
/// Get the logging configuration for `container`, falling back to the default.
pub fn for_container(&self, container: &T) -> Cow<ContainerLogConfig> {
self.containers
.get(container)
.map(Cow::Borrowed)
.unwrap_or_default()
}
}

/// Log configuration of the container
#[derive(Clone, Debug, Default, Eq, Fragment, JsonSchema, PartialEq)]
#[fragment(path_overrides(fragment = "crate::config::fragment"))]
Expand Down