Skip to content

Commit 75e52c2

Browse files
committed
fix examples
1 parent f4b00b7 commit 75e52c2

File tree

7 files changed

+169
-39
lines changed

7 files changed

+169
-39
lines changed

examples/README-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Several resources are needed in this store. These can be loaded like this:
5050

5151
```text
5252
kubectl exec minio-mc-0 -- sh -c 'mc alias set test-minio http://test-minio:9000/'
53-
kubectl cp examples/ny-tlc-report-1.1.0-3.5.7.jar minio-mc-0:/tmp
53+
kubectl cp tests/templates/kuttl/spark-ny-public-s3/ny-tlc-report-1.1.0-3.5.7.jar minio-mc-0:/tmp
5454
kubectl cp apps/ny_tlc_report.py minio-mc-0:/tmp
5555
kubectl cp examples/yellow_tripdata_2021-07.csv minio-mc-0:/tmp
5656
kubectl exec minio-mc-0 -- mc cp /tmp/ny-tlc-report-1.1.0-3.5.7.jar test-minio/my-bucket

kind/assert-pvc-jars.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ spec:
1313
claimName: pvc-ksv
1414
containers:
1515
- name: assert-pvc-jars
16-
image: oci.stackable.tech/sdp/tools:0.2.0-stackable0.4.0
16+
image: oci.stackable.tech/sdp/tools:1.0.0-stackable0.0.0-dev
1717
env:
1818
- name: DEST_DIR
1919
value: "/dependencies/jars"

kind/kind-pvc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec:
2424
claimName: pvc-ksv
2525
containers:
2626
- name: aws-deps
27-
image: oci.stackable.tech/sdp/tools:0.2.0-stackable0.4.0
27+
image: oci.stackable.tech/sdp/tools:1.0.0-stackable0.0.0-dev
2828
env:
2929
- name: DEST_DIR
3030
value: "/dependencies/jars"

kind/minio.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ spec:
2929
spec:
3030
containers:
3131
- name: minio-mc
32-
image: bitnamilegacy/minio:2022-debian-10
32+
image: docker.io/bitnamilegacy/minio:2024-debian-12
3333
stdin: true
3434
tty: true

rust/operator-binary/src/history/history_controller.rs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use stackable_operator::{
3939
core::{DeserializeGuard, error_boundary},
4040
runtime::{controller::Action, reflector::ObjectRef},
4141
},
42-
kvp::{Labels, ObjectLabels},
42+
kvp::Labels,
4343
logging::controller::ReconcilerError,
4444
product_logging::{
4545
framework::{LoggingError, calculate_log_volume_size_limit, vector_container},
@@ -57,20 +57,24 @@ use crate::{
5757
Ctx,
5858
crd::{
5959
constants::{
60-
ACCESS_KEY_ID, HISTORY_APP_NAME, HISTORY_CONTROLLER_NAME, HISTORY_ROLE_NAME,
61-
HISTORY_UI_PORT, JVM_SECURITY_PROPERTIES_FILE, LISTENER_VOLUME_DIR,
62-
LISTENER_VOLUME_NAME, MAX_SPARK_LOG_FILES_SIZE, METRICS_PORT, OPERATOR_NAME,
63-
SECRET_ACCESS_KEY, SPARK_DEFAULTS_FILE_NAME, SPARK_ENV_SH_FILE_NAME,
64-
SPARK_IMAGE_BASE_NAME, STACKABLE_TRUST_STORE, VOLUME_MOUNT_NAME_CONFIG,
65-
VOLUME_MOUNT_NAME_LOG, VOLUME_MOUNT_NAME_LOG_CONFIG, VOLUME_MOUNT_PATH_CONFIG,
66-
VOLUME_MOUNT_PATH_LOG, VOLUME_MOUNT_PATH_LOG_CONFIG,
60+
ACCESS_KEY_ID, HISTORY_APP_NAME, HISTORY_CONTROLLER_NAME, HISTORY_UI_PORT,
61+
JVM_SECURITY_PROPERTIES_FILE, LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME,
62+
MAX_SPARK_LOG_FILES_SIZE, METRICS_PORT, OPERATOR_NAME, SECRET_ACCESS_KEY,
63+
SPARK_DEFAULTS_FILE_NAME, SPARK_ENV_SH_FILE_NAME, SPARK_IMAGE_BASE_NAME,
64+
STACKABLE_TRUST_STORE, VOLUME_MOUNT_NAME_CONFIG, VOLUME_MOUNT_NAME_LOG,
65+
VOLUME_MOUNT_NAME_LOG_CONFIG, VOLUME_MOUNT_PATH_CONFIG, VOLUME_MOUNT_PATH_LOG,
66+
VOLUME_MOUNT_PATH_LOG_CONFIG,
6767
},
6868
history::{self, HistoryConfig, SparkHistoryServerContainer, v1alpha1},
6969
listener_ext,
7070
logdir::ResolvedLogDir,
7171
tlscerts, to_spark_env_sh_string,
7272
},
73-
history::operations::pdb::add_pdbs,
73+
history::{
74+
operations::pdb::add_pdbs,
75+
recommended_labels,
76+
service::{self, build_rolegroup_metrics_service},
77+
},
7478
product_logging::{self},
7579
};
7680

@@ -96,9 +100,6 @@ pub enum Error {
96100
#[snafu(display("missing secret lifetime"))]
97101
MissingSecretLifetime,
98102

99-
#[snafu(display("object has no namespace"))]
100-
ObjectHasNoNamespace,
101-
102103
#[snafu(display("invalid config map {name}"))]
103104
InvalidConfigMap {
104105
source: stackable_operator::builder::configmap::Error,
@@ -125,6 +126,11 @@ pub enum Error {
125126
source: stackable_operator::cluster_resources::Error,
126127
},
127128

129+
#[snafu(display("failed to update history server metrics service"))]
130+
ApplyMetricsService {
131+
source: stackable_operator::cluster_resources::Error,
132+
},
133+
128134
#[snafu(display("failed to apply role ServiceAccount"))]
129135
ApplyServiceAccount {
130136
source: stackable_operator::cluster_resources::Error,
@@ -233,6 +239,9 @@ pub enum Error {
233239
ResolveProductImage {
234240
source: product_image_selection::Error,
235241
},
242+
243+
#[snafu(display("failed to resolve product image"))]
244+
BuildMetricsService { source: service::Error },
236245
}
237246

238247
impl ReconcilerError for Error {
@@ -320,10 +329,10 @@ pub async fn reconcile(
320329
&rgr,
321330
&log_dir,
322331
)?;
323-
cluster_resources
324-
.add(client, config_map)
325-
.await
326-
.context(ApplyConfigMapSnafu)?;
332+
333+
let metrics_service =
334+
build_rolegroup_metrics_service(shs, &resolved_product_image, &rgr)
335+
.context(BuildMetricsServiceSnafu)?;
327336

328337
let sts = build_stateful_set(
329338
shs,
@@ -333,6 +342,15 @@ pub async fn reconcile(
333342
&merged_config,
334343
&service_account,
335344
)?;
345+
346+
cluster_resources
347+
.add(client, config_map)
348+
.await
349+
.context(ApplyConfigMapSnafu)?;
350+
cluster_resources
351+
.add(client, metrics_service)
352+
.await
353+
.context(ApplyMetricsServiceSnafu)?;
336354
cluster_resources
337355
.add(client, sts)
338356
.await
@@ -380,7 +398,7 @@ fn build_group_listener(
380398
let listener_name = group_listener_name(shs, role);
381399

382400
let recommended_object_labels =
383-
labels(shs, &resolved_product_image.app_version_label_value, "none");
401+
recommended_labels(shs, &resolved_product_image.app_version_label_value, "none");
384402

385403
let listener_ports = [listener::v1alpha1::ListenerPort {
386404
name: "http".to_string(),
@@ -445,7 +463,7 @@ fn build_config_map(
445463
.name(&cm_name)
446464
.ownerreference_from_resource(shs, None, Some(true))
447465
.context(ObjectMissingMetadataForOwnerRefSnafu)?
448-
.with_recommended_labels(labels(
466+
.with_recommended_labels(recommended_labels(
449467
shs,
450468
app_version_label_value,
451469
&rolegroupref.role_group,
@@ -511,7 +529,7 @@ fn build_stateful_set(
511529
rolegroupref.object_name()
512530
};
513531

514-
let recommended_object_labels = labels(
532+
let recommended_object_labels = recommended_labels(
515533
shs,
516534
&resolved_product_image.app_version_label_value,
517535
rolegroupref.role_group.as_ref(),
@@ -732,22 +750,6 @@ fn command_args(logdir: &ResolvedLogDir) -> Vec<String> {
732750
vec![command.join("\n")]
733751
}
734752

735-
fn labels<'a, T>(
736-
shs: &'a T,
737-
app_version_label_value: &'a str,
738-
role_group: &'a str,
739-
) -> ObjectLabels<'a, T> {
740-
ObjectLabels {
741-
owner: shs,
742-
app_name: HISTORY_APP_NAME,
743-
app_version: app_version_label_value,
744-
operator_name: OPERATOR_NAME,
745-
controller_name: HISTORY_CONTROLLER_NAME,
746-
role: HISTORY_ROLE_NAME,
747-
role_group,
748-
}
749-
}
750-
751753
/// Return the Spark properties for the cleaner role group (if any).
752754
/// There should be only one role group with "cleaner=true" and this
753755
/// group should have a replica count of 0 or 1.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
use stackable_operator::kvp::ObjectLabels;
2+
3+
use crate::crd::constants::{
4+
HISTORY_APP_NAME, HISTORY_CONTROLLER_NAME, HISTORY_ROLE_NAME, OPERATOR_NAME,
5+
};
6+
17
pub mod config;
28
pub mod history_controller;
39
pub mod operations;
10+
pub mod service;
11+
12+
pub(crate) fn recommended_labels<'a, T>(
13+
shs: &'a T,
14+
app_version_label_value: &'a str,
15+
role_group: &'a str,
16+
) -> ObjectLabels<'a, T> {
17+
ObjectLabels {
18+
owner: shs,
19+
app_name: HISTORY_APP_NAME,
20+
app_version: app_version_label_value,
21+
operator_name: OPERATOR_NAME,
22+
controller_name: HISTORY_CONTROLLER_NAME,
23+
role: HISTORY_ROLE_NAME,
24+
role_group,
25+
}
26+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
use snafu::{ResultExt, Snafu};
2+
use stackable_operator::{
3+
builder::meta::ObjectMetaBuilder,
4+
commons::product_image_selection::ResolvedProductImage,
5+
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
6+
kvp::{Annotations, Labels},
7+
role_utils::RoleGroupRef,
8+
};
9+
10+
use crate::{
11+
crd::{
12+
constants::{HISTORY_APP_NAME, METRICS_PORT},
13+
history::v1alpha1,
14+
},
15+
history::recommended_labels,
16+
};
17+
18+
#[derive(Snafu, Debug)]
19+
pub enum Error {
20+
#[snafu(display("failed to build Labels"))]
21+
LabelBuild {
22+
source: stackable_operator::kvp::LabelError,
23+
},
24+
25+
#[snafu(display("failed to build Metadata"))]
26+
MetadataBuild {
27+
source: stackable_operator::builder::meta::Error,
28+
},
29+
#[snafu(display("object is missing metadata to build owner reference"))]
30+
ObjectMissingMetadataForOwnerRef {
31+
source: stackable_operator::builder::meta::Error,
32+
},
33+
}
34+
35+
/// The rolegroup metrics [`Service`] is a service that exposes metrics and a prometheus scraping label
36+
pub fn build_rolegroup_metrics_service(
37+
shs: &v1alpha1::SparkHistoryServer,
38+
resolved_product_image: &ResolvedProductImage,
39+
rolegroup_ref: &RoleGroupRef<v1alpha1::SparkHistoryServer>,
40+
) -> Result<Service, Error> {
41+
Ok(Service {
42+
metadata: ObjectMetaBuilder::new()
43+
.name_and_namespace(shs)
44+
.name(rolegroup_ref.rolegroup_metrics_service_name())
45+
.ownerreference_from_resource(shs, None, Some(true))
46+
.context(ObjectMissingMetadataForOwnerRefSnafu)?
47+
.with_recommended_labels(recommended_labels(
48+
shs,
49+
&resolved_product_image.app_version_label_value,
50+
&rolegroup_ref.role_group,
51+
))
52+
.context(MetadataBuildSnafu)?
53+
.with_labels(prometheus_labels())
54+
.with_annotations(prometheus_annotations())
55+
.build(),
56+
spec: Some(ServiceSpec {
57+
// Internal communication does not need to be exposed
58+
type_: Some("ClusterIP".to_string()),
59+
cluster_ip: Some("None".to_string()),
60+
ports: Some(metrics_ports()),
61+
selector: Some(
62+
Labels::role_group_selector(
63+
shs,
64+
HISTORY_APP_NAME,
65+
&rolegroup_ref.role,
66+
&rolegroup_ref.role_group,
67+
)
68+
.context(LabelBuildSnafu)?
69+
.into(),
70+
),
71+
publish_not_ready_addresses: Some(true),
72+
..ServiceSpec::default()
73+
}),
74+
status: None,
75+
})
76+
}
77+
78+
fn metrics_ports() -> Vec<ServicePort> {
79+
vec![ServicePort {
80+
name: Some("metrics".to_string()),
81+
port: METRICS_PORT.into(),
82+
protocol: Some("TCP".to_string()),
83+
..ServicePort::default()
84+
}]
85+
}
86+
87+
/// Common labels for Prometheus
88+
fn prometheus_labels() -> Labels {
89+
Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label")
90+
}
91+
92+
/// Common annotations for Prometheus
93+
///
94+
/// These annotations can be used in a ServiceMonitor.
95+
///
96+
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
97+
fn prometheus_annotations() -> Annotations {
98+
Annotations::try_from([
99+
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
100+
("prometheus.io/port".to_owned(), METRICS_PORT.to_string()),
101+
("prometheus.io/scheme".to_owned(), "http".to_owned()),
102+
("prometheus.io/scrape".to_owned(), "true".to_owned()),
103+
])
104+
.expect("should be valid annotations")
105+
}

0 commit comments

Comments
 (0)