Skip to content

Commit a995a48

Browse files
authored
Merge branch 'main' into feat/stackable-telemetry-options
2 parents 53be0d1 + e5bfee5 commit a995a48

File tree

15 files changed

+204
-23
lines changed

15 files changed

+204
-23
lines changed

.github/workflows/publish-docs.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: Publish Crate Docs
3+
4+
# Once the `preview` input is available, this can also run on PR when docs are
5+
# changed.
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- .github/workflows/publish-docs.yml
13+
- crates/**
14+
15+
env:
16+
RUST_TOOLCHAIN_VERSION: "1.82.0"
17+
18+
jobs:
19+
build-docs:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout Repository
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
25+
- uses: dtolnay/rust-toolchain@master
26+
with:
27+
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
28+
29+
- name: Build Crate Docs
30+
run: cargo doc --no-deps --all-features
31+
32+
- name: Add Redirect
33+
run: echo '<meta http-equiv="refresh" content="0;url=stackable_operator/index.html">' > target/doc/index.html
34+
35+
- name: Upload Documentation Artifacts
36+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa #v3.0.1
37+
with:
38+
path: target/doc
39+
40+
publish-docs:
41+
runs-on: ubuntu-latest
42+
needs: build-docs
43+
permissions:
44+
pages: write
45+
id-token: write
46+
environment:
47+
name: github-pages
48+
url: ${{ steps.deploy.outputs.page_url }}
49+
steps:
50+
- name: Deploy to Github Pages
51+
id: deploy
52+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ darling = "0.20.10"
2121
delegate = "0.13.0"
2222
dockerfile-parser = "0.9.0"
2323
ecdsa = { version = "0.16.9", features = ["digest", "pem"] }
24-
educe = { version = "0.6.0", default-features = false, features = ["Clone", "Debug", "Default", "PartialEq"] }
24+
educe = { version = "0.6.0", default-features = false, features = ["Clone", "Debug", "Default", "PartialEq", "Eq"] }
2525
either = "1.13.0"
2626
futures = "0.3.30"
2727
futures-util = "0.3.30"

crates/stackable-operator/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
## [0.86.0] - 2025-01-30
8+
9+
### Added
10+
11+
- Add generic `TtlCache` structure as well as a `UserInformationCache` type ([#943]).
12+
13+
[#943]: https://github.com/stackabletech/operator-rs/pull/943
14+
15+
## [0.85.0] - 2025-01-28
16+
17+
### Changed
18+
19+
- Change constant used for product image selection so that it defaults to OCI ([#945]).
20+
21+
[#945]: https://github.com/stackabletech/operator-rs/pull/945
22+
723
## [0.84.1] - 2025-01-22
824

925
### Fixed

crates/stackable-operator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "stackable-operator"
33
description = "Stackable Operator Framework"
4-
version = "0.84.1"
4+
version = "0.86.0"
55
authors.workspace = true
66
license.workspace = true
77
edition.workspace = true

crates/stackable-operator/fixtures/helm/input-additional.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Partly taken from https://github.com/stackabletech/zookeeper-operator/blob/main/deploy/helm/zookeeper-operator/values.yaml
22
---
33
image:
4-
repository: docker.stackable.tech/stackable/zookeeper-operator
4+
repository: oci.stackable.tech/sdp/zookeeper-operator
55
pullPolicy: IfNotPresent
66
pullSecrets: []
77
nameOverride: ''

crates/stackable-operator/fixtures/helm/input-required.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Partly taken from https://github.com/stackabletech/zookeeper-operator/blob/main/deploy/helm/zookeeper-operator/values.yaml
22
---
33
image:
4-
repository: docker.stackable.tech/stackable/zookeeper-operator
4+
repository: oci.stackable.tech/sdp/zookeeper-operator
55
pullPolicy: IfNotPresent
66
pullSecrets: []
77
nameOverride: ''

crates/stackable-operator/fixtures/helm/output.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
image:
3-
repository: docker.stackable.tech/stackable/zookeeper-operator
3+
repository: oci.stackable.tech/sdp/zookeeper-operator
44
pullPolicy: IfNotPresent
55
pullSecrets: []
66
nameOverride: ''
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
use std::marker::PhantomData;
2+
3+
use educe::Educe;
4+
use schemars::JsonSchema;
5+
use serde::{Deserialize, Serialize};
6+
7+
use crate::time::Duration;
8+
9+
/// [`TtlCache`] with sensible defaults for a user information cache
10+
pub type UserInformationCache = TtlCache<UserInformationCacheDefaults>;
11+
12+
/// Default tunings for [`UserInformationCache`].
13+
#[derive(JsonSchema)]
14+
pub struct UserInformationCacheDefaults;
15+
16+
impl TtlCacheDefaults for UserInformationCacheDefaults {
17+
fn entry_time_to_live() -> Duration {
18+
Duration::from_secs(30)
19+
}
20+
21+
fn max_entries() -> u32 {
22+
10_000
23+
}
24+
}
25+
26+
/// Structure to configure a TTL cache in a product.
27+
#[derive(Deserialize, Educe, JsonSchema, Serialize)]
28+
#[serde(
29+
rename_all = "camelCase",
30+
bound(deserialize = "D: TtlCacheDefaults", serialize = "D: TtlCacheDefaults")
31+
)]
32+
#[schemars(
33+
description = "Least Recently Used (LRU) cache with per-entry time-to-live (TTL) value.",
34+
// We don't care about the fields, but we also use JsonSchema to derive the name for the composite type
35+
bound(serialize = "D: TtlCacheDefaults + JsonSchema")
36+
)]
37+
#[educe(
38+
Clone(bound = false),
39+
Debug(bound = false),
40+
PartialEq(bound = false),
41+
Eq
42+
)]
43+
pub struct TtlCache<D> {
44+
/// Time to live per entry
45+
#[serde(default = "D::entry_time_to_live")]
46+
pub entry_time_to_live: Duration,
47+
48+
/// Maximum number of entries in the cache; If this threshold is reached then the least
49+
/// recently used item is removed.
50+
#[serde(default = "D::max_entries")]
51+
pub max_entries: u32,
52+
53+
#[serde(skip)]
54+
pub _defaults: PhantomData<D>,
55+
}
56+
57+
impl<D: TtlCacheDefaults> Default for TtlCache<D> {
58+
fn default() -> Self {
59+
Self {
60+
entry_time_to_live: D::entry_time_to_live(),
61+
max_entries: D::max_entries(),
62+
_defaults: PhantomData,
63+
}
64+
}
65+
}
66+
67+
/// A set of default values for [`TtlCache`].
68+
///
69+
/// This is extracted to a separate trait in order to be able to provide different
70+
/// default tunings for different use cases.
71+
pub trait TtlCacheDefaults {
72+
/// The default TTL the entries should have.
73+
fn entry_time_to_live() -> Duration;
74+
/// The default for the maximum number of entries
75+
fn max_entries() -> u32;
76+
}
77+
78+
#[cfg(test)]
79+
mod tests {
80+
use super::*;
81+
82+
type MyCache = TtlCache<UserInformationCacheDefaults>;
83+
84+
#[test]
85+
fn test_defaults() {
86+
let my_cache: MyCache = Default::default();
87+
assert_eq!(my_cache.entry_time_to_live, Duration::from_secs(30));
88+
assert_eq!(my_cache.max_entries, 10_000);
89+
}
90+
91+
#[test]
92+
fn test_deserialization_defaults() {
93+
let my_cache: MyCache = serde_json::from_str("{}").unwrap();
94+
95+
assert_eq!(my_cache.entry_time_to_live, Duration::from_secs(30));
96+
assert_eq!(my_cache.max_entries, 10_000);
97+
}
98+
99+
#[test]
100+
fn test_deserialization() {
101+
let my_cache: MyCache = serde_yaml::from_str("entryTimeToLive: 13h\n").unwrap();
102+
103+
assert_eq!(
104+
my_cache.entry_time_to_live,
105+
Duration::from_hours_unchecked(13)
106+
);
107+
// As the field is not specified we default
108+
assert_eq!(my_cache.max_entries, 10_000);
109+
}
110+
}

crates/stackable-operator/src/commons/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub mod affinity;
44
pub mod authentication;
5+
pub mod cache;
56
pub mod cluster_operation;
67
pub mod listener;
78
pub mod networking;

0 commit comments

Comments
 (0)