mz_orchestratord/
lib.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use std::fmt::Display;
11
12pub mod controller;
13pub mod k8s;
14pub mod metrics;
15pub mod tls;
16
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19    Anyhow(#[from] anyhow::Error),
20    Kube(#[from] kube::Error),
21    Reqwest(#[from] reqwest::Error),
22}
23
24impl Display for Error {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self {
27            Self::Anyhow(e) => write!(f, "{e}"),
28            Self::Kube(e) => write!(f, "{e}"),
29            Self::Reqwest(e) => write!(f, "{e}"),
30        }
31    }
32}
33
34pub fn matching_image_from_environmentd_image_ref(
35    environmentd_image_ref: &str,
36    image_name: &str,
37    image_tag: Option<&str>,
38) -> String {
39    let namespace = environmentd_image_ref
40        .rsplit_once('/')
41        .unwrap_or(("materialize", ""))
42        .0;
43    let tag = image_tag.unwrap_or_else(|| {
44        environmentd_image_ref
45            .rsplit_once(':')
46            .unwrap_or(("", "unstable"))
47            .1
48    });
49    format!("{namespace}/{image_name}:{tag}")
50}