Skip to content

Commit 63da978

Browse files
nightkrfhennigsiegfriedweber
authored
Add PodListeners (#644)
* Add PodListeners * Add pod listener scope * Add address type to ListenerIngress * Add docs for PodListeners * Mention who is responsible for creating the PodListeners * Add list-op CRD summary docs * Update src/commons/listener.rs Co-authored-by: Felix Hennig <fhennig@users.noreply.github.com> * Changelog * Derive additional traits * Explicitly pluralize `PodListeners` as `podlisteners` * Fix changelog --------- Co-authored-by: Felix Hennig <fhennig@users.noreply.github.com> Co-authored-by: Siegfried Weber <mail@siegfriedweber.net>
1 parent d2b8b80 commit 63da978

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ All notable changes to this project will be documented in this file.
66

77
### Added
88

9+
- `PodListeners` CRD ([#644]).
910
- Add support for tls pkcs12 password to secret operator volume builder ([#645]).
1011

1112
### Changed
1213

14+
- Derive `Eq` and `Copy` where applicable for listener CRDs ([#644]).
1315
- Bump `kube` to `0.86.0` and Kubernetes version to `1.28` ([#648]).
1416

17+
[#644]: https://github.com/stackabletech/operator-rs/pull/644
1518
[#645]: https://github.com/stackabletech/operator-rs/pull/645
1619
[#648]: https://github.com/stackabletech/operator-rs/pull/648
1720

src/commons/listener.rs

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
//! This modules provides resource types used to interact with [listener-operator](https://docs.stackable.tech/listener-operator/stable/index.html)
2+
//!
3+
//! # Custom Resources
4+
//!
5+
//! ## [`Listener`]
6+
//!
7+
//! Exposes a set of pods, either internally to the cluster or to the outside world. The mechanism for how it is exposed
8+
//! is managed by the [`ListenerClass`].
9+
//!
10+
//! It can be either created manually by the application administrator (for applications that expose a single load-balanced endpoint),
11+
//! or automatically when mounting a [listener volume](`ListenerOperatorVolumeSourceBuilder`) (for applications that expose a separate endpoint
12+
//! per replica).
13+
//!
14+
//! All exposed pods *must* have a mounted [listener volume](`ListenerOperatorVolumeSourceBuilder`), regardless of whether the [`Listener`] is created automatically.
15+
//!
16+
//! ## [`ListenerClass`]
17+
//!
18+
//! Declares a policy for how [`Listener`]s are exposed to users.
19+
//!
20+
//! It is created by the cluster administrator.
21+
//!
22+
//! ## [`PodListeners`]
23+
//!
24+
//! Informs users and other operators about the state of all [`Listener`]s associated with a [`Pod`].
25+
//!
26+
//! It is created by the Stackable Secret Operator, and always named `pod-{pod.metadata.uid}`.
227
328
use std::collections::BTreeMap;
429

@@ -7,10 +32,15 @@ use schemars::JsonSchema;
732
use serde::{Deserialize, Serialize};
833

934
#[cfg(doc)]
10-
use k8s_openapi::api::core::v1::{Node, Pod, Service, Volume};
35+
use k8s_openapi::api::core::v1::{
36+
Node, PersistentVolume, PersistentVolumeClaim, Pod, Service, Volume,
37+
};
38+
39+
#[cfg(doc)]
40+
use crate::builder::ListenerOperatorVolumeSourceBuilder;
1141

1242
/// Defines a policy for how [`Listener`]s should be exposed.
13-
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
43+
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
1444
#[kube(
1545
group = "listeners.stackable.tech",
1646
version = "v1alpha1",
@@ -25,7 +55,7 @@ pub struct ListenerClassSpec {
2555
}
2656

2757
/// The method used to access the services.
28-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
58+
#[derive(Serialize, Deserialize, Clone, Copy, Debug, JsonSchema, PartialEq, Eq)]
2959
pub enum ServiceType {
3060
/// Reserve a port on each node.
3161
NodePort,
@@ -37,11 +67,13 @@ pub enum ServiceType {
3767

3868
/// Exposes a set of pods to the outside world.
3969
///
40-
/// Essentially a Stackable extension of a Kubernetes [`Service`]. Compared to [`Service`], [`Listener`] changes two things:
70+
/// Essentially a Stackable extension of a Kubernetes [`Service`]. Compared to [`Service`], [`Listener`] changes three things:
4171
/// 1. It uses a cluster-level policy object ([`ListenerClass`]) to define how exactly the exposure works
4272
/// 2. It has a consistent API for reading back the exposed address(es) of the service
4373
/// 3. The [`Pod`] must mount a [`Volume`] referring to the `Listener`, which also allows us to control stickiness
44-
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
74+
#[derive(
75+
CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq, Eq,
76+
)]
4577
#[kube(
4678
group = "listeners.stackable.tech",
4779
version = "v1alpha1",
@@ -69,7 +101,7 @@ impl ListenerSpec {
69101
}
70102
}
71103

72-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
104+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
73105
#[serde(rename_all = "camelCase")]
74106
pub struct ListenerPort {
75107
/// The name of the port.
@@ -83,7 +115,7 @@ pub struct ListenerPort {
83115
}
84116

85117
/// Informs users about how to reach the [`Listener`].
86-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
118+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
87119
#[serde(rename_all = "camelCase")]
88120
pub struct ListenerStatus {
89121
/// The backing Kubernetes [`Service`].
@@ -98,11 +130,64 @@ pub struct ListenerStatus {
98130
}
99131

100132
/// One address that a [`Listener`] is accessible from.
101-
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
133+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
102134
#[serde(rename_all = "camelCase")]
103135
pub struct ListenerIngress {
104136
/// The hostname or IP address to the [`Listener`].
105137
pub address: String,
138+
/// The type of address (`Hostname` or `IP`).
139+
pub address_type: AddressType,
106140
/// Port mapping table.
107141
pub ports: BTreeMap<String, i32>,
108142
}
143+
144+
#[derive(Serialize, Deserialize, Clone, Copy, Debug, JsonSchema, PartialEq, Eq)]
145+
#[serde(rename_all = "PascalCase")]
146+
pub enum AddressType {
147+
Hostname,
148+
#[serde(rename = "IP")]
149+
Ip,
150+
}
151+
152+
/// Informs users about [`Listener`]s that are bound by a given [`Pod`].
153+
///
154+
/// This is not expected to be created or modified by users. It will be created by
155+
/// the Stackable Listener Operator when mounting the listener volume, and is always
156+
/// named `pod-{pod.metadata.uid}`.
157+
#[derive(
158+
CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default, PartialEq, Eq,
159+
)]
160+
#[kube(
161+
group = "listeners.stackable.tech",
162+
version = "v1alpha1",
163+
kind = "PodListeners",
164+
namespaced,
165+
plural = "podlisteners"
166+
)]
167+
#[serde(rename_all = "camelCase")]
168+
pub struct PodListenersSpec {
169+
/// All listeners currently bound by the [`Pod`].
170+
///
171+
/// Indexed by [`Volume`] name (not [`PersistentVolume`] or [`PersistentVolumeClaim`]).
172+
pub listeners: BTreeMap<String, PodListener>,
173+
}
174+
175+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
176+
#[serde(rename_all = "camelCase")]
177+
pub struct PodListener {
178+
/// `Node` if this address only allows access to [`Pod`]s hosted on a specific Kubernetes [`Node`], otherwise `Cluster`.
179+
pub scope: PodListenerScope,
180+
/// Addresses allowing access to this [`Pod`].
181+
///
182+
/// Compared to [`ListenerStatus::ingress_addresses`], this list is restricted to addresses that can access this [`Pod`].
183+
///
184+
/// This field is intended to be equivalent to the files mounted into the listener volume.
185+
pub ingress_addresses: Option<Vec<ListenerIngress>>,
186+
}
187+
188+
#[derive(Serialize, Deserialize, Clone, Copy, Debug, JsonSchema, PartialEq, Eq)]
189+
#[serde(rename_all = "PascalCase")]
190+
pub enum PodListenerScope {
191+
Node,
192+
Cluster,
193+
}

0 commit comments

Comments
 (0)