Skip to content

Commit

Permalink
chore: Version HbaseCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Feb 4, 2025
1 parent 9139c87 commit e156914
Show file tree
Hide file tree
Showing 16 changed files with 1,538 additions and 343 deletions.
298 changes: 272 additions & 26 deletions Cargo.lock

Large diffs are not rendered by default.

1,346 changes: 1,140 additions & 206 deletions Cargo.nix

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ edition = "2021"
repository = "https://github.com/stackabletech/hbase-operator"

[workspace.dependencies]
stackable-versioned = { git = "https://github.com/stackabletech/operator-rs.git", features = ["k8s"], tag = "stackable-versioned-0.5.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.85.0" }
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }

anyhow = "1.0"
built = { version = "0.7", features = ["chrono", "git2"] }
clap = "4.5"
Expand All @@ -22,8 +26,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
snafu = "0.8"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.85.0" }
product-config = { git = "https://github.com/stackabletech/product-config.git", tag = "0.7.0" }
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.40", features = ["full"] }
tracing = "0.1"
Expand Down
3 changes: 3 additions & 0 deletions crate-hashes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions rust/operator-binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ repository.workspace = true
publish = false

[dependencies]
stackable-versioned.workspace = true
stackable-operator.workspace = true
product-config.workspace = true

anyhow.workspace = true
clap.workspace = true
const_format.workspace = true
fnv.workspace = true
futures.workspace = true
indoc.workspace = true
product-config.workspace = true
serde.workspace = true
serde_json.workspace = true
snafu.workspace = true
stackable-operator.workspace = true
strum.workspace = true
tokio.workspace = true
tracing.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions rust/operator-binary/src/config/jvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn is_heap_jvm_argument(jvm_argument: &str) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::crd::{HbaseCluster, HbaseRole};
use crate::crd::{v1alpha1, HbaseRole};

#[test]
fn test_construct_jvm_arguments_defaults() {
Expand Down Expand Up @@ -254,7 +254,8 @@ mod tests {
String,
String,
) {
let hbase: HbaseCluster = serde_yaml::from_str(hbase_cluster).expect("illegal test input");
let hbase: v1alpha1::HbaseCluster =
serde_yaml::from_str(hbase_cluster).expect("illegal test input");

let hbase_role = HbaseRole::RegionServer;
let merged_config = hbase
Expand Down
5 changes: 3 additions & 2 deletions rust/operator-binary/src/crd/affinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod tests {
};

use super::*;
use crate::HbaseCluster;
use crate::crd::v1alpha1;

#[rstest]
#[case(HbaseRole::Master)]
Expand Down Expand Up @@ -122,7 +122,8 @@ mod tests {
default:
replicas: 1
"#;
let hbase: HbaseCluster = serde_yaml::from_str(input).expect("illegal test input");
let hbase: v1alpha1::HbaseCluster =
serde_yaml::from_str(input).expect("illegal test input");
let merged_config = hbase
.merged_config(
&role,
Expand Down
111 changes: 57 additions & 54 deletions rust/operator-binary/src/crd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use stackable_operator::{
status::condition::{ClusterCondition, HasStatusCondition},
time::Duration,
};
use stackable_versioned::versioned;
use strum::{Display, EnumIter, EnumString};

use crate::crd::{affinity::get_affinity, security::AuthorizationConfig};
Expand Down Expand Up @@ -72,6 +73,55 @@ pub const HBASE_REST_UI_PORT: u16 = 8085;
// Newer versions use the same port as the UI because Hbase provides it's own metrics API
pub const METRICS_PORT: u16 = 9100;

#[versioned(version(name = "v1alpha1"))]
pub mod versioned {
/// An HBase cluster stacklet. This resource is managed by the Stackable operator for Apache HBase.
/// Find more information on how to use it and the resources that the operator generates in the
/// [operator documentation](DOCS_BASE_URL_PLACEHOLDER/hbase/).
///
/// The CRD contains three roles: `masters`, `regionServers` and `restServers`.
#[versioned(k8s(
group = "hbase.stackable.tech",
kind = "HbaseCluster",
plural = "hbaseclusters",
shortname = "hbase",
status = "HbaseClusterStatus",
namespaced,
crates(
kube_core = "stackable_operator::kube::core",
k8s_openapi = "stackable_operator::k8s_openapi",
schemars = "stackable_operator::schemars"
)
))]
#[derive(Clone, CustomResource, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HbaseClusterSpec {
// no doc string - See ProductImage struct
pub image: ProductImage,

/// Configuration that applies to all roles and role groups.
/// This includes settings for logging, ZooKeeper and HDFS connection, among other things.
pub cluster_config: HbaseClusterConfig,

// no doc string - See ClusterOperation struct
#[serde(default)]
pub cluster_operation: ClusterOperation,

/// The HBase master process is responsible for assigning regions to region servers and
/// manages the cluster.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub masters: Option<Role<HbaseConfigFragment, GenericRoleConfig, JavaCommonConfig>>,

/// Region servers hold the data and handle requests from clients for their region.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub region_servers: Option<Role<HbaseConfigFragment, GenericRoleConfig, JavaCommonConfig>>,

/// Rest servers provide a REST API to interact with.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rest_servers: Option<Role<HbaseConfigFragment, GenericRoleConfig, JavaCommonConfig>>,
}
}

#[derive(Snafu, Debug)]
pub enum Error {
#[snafu(display("the role [{role}] is invalid and does not exist in HBase"))]
Expand All @@ -90,53 +140,6 @@ pub enum Error {
FragmentValidationFailure { source: ValidationError },
}

/// An HBase cluster stacklet. This resource is managed by the Stackable operator for Apache HBase.
/// Find more information on how to use it and the resources that the operator generates in the
/// [operator documentation](DOCS_BASE_URL_PLACEHOLDER/hbase/).
///
/// The CRD contains three roles: `masters`, `regionServers` and `restServers`.
#[derive(Clone, CustomResource, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[kube(
group = "hbase.stackable.tech",
version = "v1alpha1",
kind = "HbaseCluster",
plural = "hbaseclusters",
shortname = "hbase",
status = "HbaseClusterStatus",
namespaced,
crates(
kube_core = "stackable_operator::kube::core",
k8s_openapi = "stackable_operator::k8s_openapi",
schemars = "stackable_operator::schemars"
)
)]
#[serde(rename_all = "camelCase")]
pub struct HbaseClusterSpec {
// no doc string - See ProductImage struct
pub image: ProductImage,

/// Configuration that applies to all roles and role groups.
/// This includes settings for logging, ZooKeeper and HDFS connection, among other things.
pub cluster_config: HbaseClusterConfig,

// no doc string - See ClusterOperation struct
#[serde(default)]
pub cluster_operation: ClusterOperation,

/// The HBase master process is responsible for assigning regions to region servers and
/// manages the cluster.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub masters: Option<Role<HbaseConfigFragment, GenericRoleConfig, JavaCommonConfig>>,

/// Region servers hold the data and handle requests from clients for their region.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub region_servers: Option<Role<HbaseConfigFragment, GenericRoleConfig, JavaCommonConfig>>,

/// Rest servers provide a REST API to interact with.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub rest_servers: Option<Role<HbaseConfigFragment, GenericRoleConfig, JavaCommonConfig>>,
}

#[derive(Clone, Debug, Default, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HbaseClusterConfig {
Expand Down Expand Up @@ -422,7 +425,7 @@ pub struct HbaseConfig {
}

impl Configuration for HbaseConfigFragment {
type Configurable = HbaseCluster;
type Configurable = v1alpha1::HbaseCluster;

fn compute_env(
&self,
Expand Down Expand Up @@ -499,7 +502,7 @@ pub struct HbaseClusterStatus {
pub conditions: Vec<ClusterCondition>,
}

impl HasStatusCondition for HbaseCluster {
impl HasStatusCondition for v1alpha1::HbaseCluster {
fn conditions(&self) -> Vec<ClusterCondition> {
match &self.status {
Some(status) => status.conditions.clone(),
Expand All @@ -508,7 +511,7 @@ impl HasStatusCondition for HbaseCluster {
}
}

impl HbaseCluster {
impl v1alpha1::HbaseCluster {
/// The name of the role-level load-balanced Kubernetes `Service`
pub fn server_role_service_name(&self) -> Option<String> {
self.metadata.name.clone()
Expand All @@ -519,7 +522,7 @@ impl HbaseCluster {
&self,
role_name: impl Into<String>,
group_name: impl Into<String>,
) -> RoleGroupRef<HbaseCluster> {
) -> RoleGroupRef<v1alpha1::HbaseCluster> {
RoleGroupRef {
cluster: ObjectRef::from_obj(self),
role: role_name.into(),
Expand All @@ -541,7 +544,7 @@ impl HbaseCluster {
/// Get the RoleGroup struct for the given ref
pub fn get_role_group(
&self,
rolegroup_ref: &RoleGroupRef<HbaseCluster>,
rolegroup_ref: &RoleGroupRef<v1alpha1::HbaseCluster>,
) -> Result<&RoleGroup<HbaseConfigFragment, JavaCommonConfig>, Error> {
let role_variant =
HbaseRole::from_str(&rolegroup_ref.role).with_context(|_| InvalidRoleSnafu {
Expand Down Expand Up @@ -708,7 +711,7 @@ mod tests {
transform_all_roles_to_config, validate_all_roles_and_groups_config,
};

use crate::crd::{merged_env, HbaseCluster, HbaseRole};
use super::*;

#[test]
pub fn test_env_overrides() {
Expand Down Expand Up @@ -754,7 +757,7 @@ spec:
"#};

let deserializer = serde_yaml::Deserializer::from_str(input);
let hbase: HbaseCluster =
let hbase: v1alpha1::HbaseCluster =
serde_yaml::with::singleton_map_recursive::deserialize(deserializer).unwrap();

let roles = HashMap::from([(
Expand Down
6 changes: 3 additions & 3 deletions rust/operator-binary/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use stackable_operator::{
};

use crate::{
crd::{HbaseCluster, HbaseRole, HBASE_SITE_XML},
crd::{v1alpha1, HbaseRole, HBASE_SITE_XML},
hbase_controller::build_recommended_labels,
kerberos::{self, kerberos_discovery_config_properties},
zookeeper::ZookeeperConnectionInformation,
Expand All @@ -24,7 +24,7 @@ pub enum Error {
#[snafu(display("object {hbase} is missing metadata to build owner reference"))]
ObjectMissingMetadataForOwnerRef {
source: stackable_operator::builder::meta::Error,
hbase: ObjectRef<HbaseCluster>,
hbase: ObjectRef<v1alpha1::HbaseCluster>,
},

#[snafu(display("failed to build ConfigMap"))]
Expand All @@ -43,7 +43,7 @@ pub enum Error {

/// Creates a discovery config map containing the `hbase-site.xml` for clients.
pub fn build_discovery_configmap(
hbase: &HbaseCluster,
hbase: &v1alpha1::HbaseCluster,
cluster_info: &KubernetesClusterInfo,
zookeeper_connection_information: &ZookeeperConnectionInformation,
resolved_product_image: &ResolvedProductImage,
Expand Down
Loading

0 comments on commit e156914

Please sign in to comment.