Skip to content

Commit 4ec1567

Browse files
committed
Import listener-operator CRDs (#469)
## Description These are taken from stackabletech/listener-operator#1, but imported since all operators are likely to depend on, at least, `Listener` for discovery. The expectation is that these will be removed from listener-operator once this PR is merged. Co-authored-by: Teo Klestrup Röijezon <teo.roijezon@stackable.de>
1 parent 7f9354a commit 4ec1567

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- listener-operator CRDs ([#469]).
10+
11+
[#469]: https://github.com/stackabletech/operator-rs/pull/469
12+
713
## [0.25.0] - 2022-08-23
814

915
### Added

src/commons/listener.rs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//! This modules provides resource types used to interact with [listener-operator](https://docs.stackable.tech/listener-operator/stable/index.html)
2+
3+
use std::collections::BTreeMap;
4+
5+
use kube::CustomResource;
6+
use schemars::JsonSchema;
7+
use serde::{Deserialize, Serialize};
8+
9+
#[cfg(doc)]
10+
use k8s_openapi::api::core::v1::{Node, Pod, Service};
11+
12+
/// Defines a policy for how [`Listener`]s should be exposed.
13+
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema)]
14+
#[kube(
15+
group = "listeners.stackable.tech",
16+
version = "v1alpha1",
17+
kind = "ListenerClass"
18+
)]
19+
#[serde(rename_all = "camelCase")]
20+
pub struct ListenerClassSpec {
21+
pub service_type: ServiceType,
22+
/// Annotations that should be added to the [`Service`] object.
23+
#[serde(default)]
24+
pub service_annotations: BTreeMap<String, String>,
25+
}
26+
27+
/// The method used to access the services.
28+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq, Eq)]
29+
pub enum ServiceType {
30+
/// Reserve a port on each node.
31+
NodePort,
32+
/// Provision a dedicated load balancer.
33+
LoadBalancer,
34+
}
35+
36+
/// Exposes a set of pods to the outside world.
37+
///
38+
/// Essentially a Stackable extension of a Kubernetes [`Service`]. Compared to [`Service`], [`Listener`] changes two things:
39+
/// 1. It uses a cluster-level policy object ([`ListenerClass`]) to define how exactly the exposure works
40+
/// 2. It has a consistent API for reading back the exposed address(es) of the service
41+
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, JsonSchema, Default)]
42+
#[kube(
43+
group = "listeners.stackable.tech",
44+
version = "v1alpha1",
45+
kind = "Listener",
46+
namespaced,
47+
status = "ListenerStatus"
48+
)]
49+
#[serde(rename_all = "camelCase")]
50+
pub struct ListenerSpec {
51+
/// The name of the [`ListenerClass`].
52+
pub class_name: Option<String>,
53+
/// Labels that the [`Pod`]s must share in order to be exposed.
54+
pub pod_selector: Option<BTreeMap<String, String>>,
55+
/// Ports that should be exposed.
56+
pub ports: Option<Vec<ListenerPort>>,
57+
}
58+
59+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
60+
#[serde(rename_all = "camelCase")]
61+
pub struct ListenerPort {
62+
/// The name of the port.
63+
///
64+
/// The name of each port *must* be unique within a single [`Listener`].
65+
pub name: String,
66+
/// The port number.
67+
pub port: i32,
68+
/// The layer-4 protocol (`TCP` or `UDP`).
69+
pub protocol: Option<String>,
70+
}
71+
72+
/// Informs users about how to reach the [`Listener`].
73+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
74+
#[serde(rename_all = "camelCase")]
75+
pub struct ListenerStatus {
76+
/// The backing Kubernetes [`Service`].
77+
pub service_name: Option<String>,
78+
/// All addresses that the [`Listener`] is currently reachable from.
79+
pub ingress_addresses: Option<Vec<ListenerIngress>>,
80+
/// Port mappings for accessing the [`Listener`] on each [`Node`] that the [`Pod`]s are currently running on.
81+
///
82+
/// This is only intended for internal use by listener-operator itself. This will be left unset if using a [`ListenerClass`] that does
83+
/// not require [`Node`]-local access.
84+
pub node_ports: Option<BTreeMap<String, i32>>,
85+
}
86+
87+
/// One address that a [`Listener`] is accessible from.
88+
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
89+
#[serde(rename_all = "camelCase")]
90+
pub struct ListenerIngress {
91+
/// The hostname or IP address to the [`Listener`].
92+
pub address: String,
93+
/// Port mapping table.
94+
pub ports: BTreeMap<String, i32>,
95+
}

src/commons/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub mod authentication;
44
pub mod ldap;
5+
pub mod listener;
56
pub mod opa;
67
pub mod resources;
78
pub mod s3;

0 commit comments

Comments
 (0)