diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e08b815..982dc84b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,13 @@ All notable changes to this project will be documented in this file. This means you need to replace your simple database connection string with a typed struct. This struct is consistent between different CRDs, so that you can easily copy/paste it between stacklets. Read on the [Hive database documentation](https://docs.stackable.tech/home/nightly/hive/usage-guide/database-driver) for details ([#674]). +- Internal operator refactoring: introduce dereference() and validate() steps in the reconciler ([#707]). [#674]: https://github.com/stackabletech/hive-operator/pull/674 [#693]: https://github.com/stackabletech/hive-operator/pull/693 [#695]: https://github.com/stackabletech/hive-operator/pull/695 [#702]: https://github.com/stackabletech/hive-operator/pull/702 +[#707]: https://github.com/stackabletech/hive-operator/pull/707 ## [26.3.0] - 2026-03-16 diff --git a/rust/operator-binary/src/controller.rs b/rust/operator-binary/src/controller.rs index ade37ef0..e9945db4 100644 --- a/rust/operator-binary/src/controller.rs +++ b/rust/operator-binary/src/controller.rs @@ -1,7 +1,9 @@ //! Ensures that `Pod`s are configured and running for each [`v1alpha1::HiveCluster`] +mod dereference; +mod validate; + use std::{ - borrow::Cow, collections::{BTreeMap, HashMap}, hash::Hasher, sync::Arc, @@ -35,8 +37,7 @@ use stackable_operator::{ cli::OperatorEnvironmentOptions, cluster_resources::{ClusterResourceApplyStrategy, ClusterResources}, commons::{ - product_image_selection::{self, ResolvedProductImage}, - rbac::build_rbac_resources, + product_image_selection::ResolvedProductImage, rbac::build_rbac_resources, secret_class::SecretClassVolumeProvisionParts, }, constants::RESTART_CONTROLLER_ENABLED_LABEL, @@ -63,7 +64,6 @@ use stackable_operator::{ kvp::{Labels, ObjectLabels}, logging::controller::ReconcilerError, memory::{BinaryMultiple, MemoryQuantity}, - product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config}, product_logging::{ self, framework::{ @@ -74,7 +74,7 @@ use stackable_operator::{ CustomContainerLogConfig, }, }, - role_utils::{GenericRoleConfig, RoleGroupRef}, + role_utils::RoleGroupRef, shared::time::Duration, status::condition::{ compute_conditions, operations::ClusterOperationsConditionBuilder, @@ -92,6 +92,7 @@ use crate::{ jvm::{construct_hadoop_heapsize_env, construct_non_heap_jvm_args}, opa::{HiveOpaConfig, OPA_TLS_VOLUME_NAME}, }, + controller::validate::{ValidatedRoleConfig, ValidatedRoleGroupConfig}, crd::{ APP_NAME, CORE_SITE_XML, Container, HIVE_PORT, HIVE_PORT_NAME, HIVE_SITE_XML, HiveClusterStatus, HiveRole, JVM_SECURITY_PROPERTIES_FILE, METRICS_PORT, METRICS_PORT_NAME, @@ -100,7 +101,7 @@ use crate::{ STACKABLE_LOG_CONFIG_MOUNT_DIR, STACKABLE_LOG_CONFIG_MOUNT_DIR_NAME, STACKABLE_LOG_DIR, STACKABLE_LOG_DIR_NAME, databases::{MetadataDatabaseConnection, derby_driver_class}, - v1alpha1::{self, HiveMetastoreRoleConfig}, + v1alpha1, }, discovery::{self}, kerberos::{ @@ -116,7 +117,7 @@ use crate::{ pub const HIVE_CONTROLLER_NAME: &str = "hivecluster"; pub const HIVE_FULL_CONTROLLER_NAME: &str = concatcp!(HIVE_CONTROLLER_NAME, '.', OPERATOR_NAME); -const CONTAINER_IMAGE_BASE_NAME: &str = "hive"; +pub const CONTAINER_IMAGE_BASE_NAME: &str = "hive"; pub const MAX_HIVE_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity { value: 10.0, @@ -136,9 +137,6 @@ pub enum Error { #[snafu(display("object defines no namespace"))] ObjectHasNoNamespace, - #[snafu(display("object defines no metastore role"))] - NoMetaStoreRole, - #[snafu(display("failed to apply Service for {rolegroup}"))] ApplyRoleGroupService { source: stackable_operator::cluster_resources::Error, @@ -163,16 +161,6 @@ pub enum Error { rolegroup: RoleGroupRef, }, - #[snafu(display("failed to generate product config"))] - GenerateProductConfig { - source: stackable_operator::product_config_utils::Error, - }, - - #[snafu(display("invalid product config"))] - InvalidProductConfig { - source: stackable_operator::product_config_utils::Error, - }, - #[snafu(display("object is missing metadata to build owner reference"))] ObjectMissingMetadataForOwnerRef { source: stackable_operator::builder::meta::Error, @@ -201,9 +189,6 @@ pub enum Error { ))] S3TlsNoVerificationNotSupported, - #[snafu(display("failed to resolve and merge resource config for role and role group"))] - FailedToResolveResourceConfig { source: crate::crd::Error }, - #[snafu(display("failed to create hive container [{name}]"))] FailedToCreateHiveContainer { source: stackable_operator::builder::pod::container::Error, @@ -320,25 +305,18 @@ pub enum Error { #[snafu(display("failed to configure service"))] ServiceConfiguration { source: crate::service::Error }, - #[snafu(display("failed to resolve product image"))] - ResolveProductImage { - source: product_image_selection::Error, + #[snafu(display("failed to dereference cluster resources"))] + Dereference { + source: crate::controller::dereference::Error, }, - #[snafu(display("invalid OpaConfig"))] - InvalidOpaConfig { - source: stackable_operator::commons::opa::Error, - }, + #[snafu(display("failed to validate cluster configuration"))] + Validate { source: validate::Error }, #[snafu(display("failed to build TLS certificate SecretClass Volume"))] TlsCertSecretClassVolumeBuild { source: stackable_operator::builder::pod::volume::SecretOperatorVolumeSourceBuilderError, }, - - #[snafu(display("invalid metadata database connection"))] - InvalidMetadataDatabaseConnection { - source: stackable_operator::database_connections::Error, - }, } type Result = std::result::Result; @@ -348,6 +326,19 @@ impl ReconcilerError for Error { } } +/// The validated cluster: proves that product-config validation and config merging +/// succeeded for every role and role group before any resources are created. +/// Placed in the controller so that subsequent steps that reference this struct +/// only depend on the controller. +pub struct ValidatedCluster { + pub image: ResolvedProductImage, + pub role_groups: BTreeMap, + pub role_config: Option, + pub metadata_database_connection_details: JdbcDatabaseConnectionDetails, + pub s3_connection_spec: Option, + pub hive_opa_config: Option, +} + pub async fn reconcile_hive( hive: Arc>, ctx: Arc, @@ -361,69 +352,18 @@ pub async fn reconcile_hive( let client = &ctx.client; let hive_namespace = hive.namespace().context(ObjectHasNoNamespaceSnafu)?; - let resolved_product_image = hive - .spec - .image - .resolve( - CONTAINER_IMAGE_BASE_NAME, - &ctx.operator_environment.image_repository, - crate::built_info::PKG_VERSION, - ) - .context(ResolveProductImageSnafu)?; - let role = hive.spec.metastore.as_ref().context(NoMetaStoreRoleSnafu)?; - let hive_role = HiveRole::MetaStore; - - let s3_connection_spec: Option = - if let Some(s3) = &hive.spec.cluster_config.s3 { - Some( - s3.clone() - .resolve( - client, - &hive.namespace().ok_or(Error::ObjectHasNoNamespace)?, - ) - .await - .context(ConfigureS3ConnectionSnafu)?, - ) - } else { - None - }; - - let metadata_database_connection_details = hive - .spec - .cluster_config - .metadata_database - .jdbc_connection_details("METADATA") - .context(InvalidMetadataDatabaseConnectionSnafu)?; - - let validated_config = validate_all_roles_and_groups_config( - &resolved_product_image.product_version, - &transform_all_roles_to_config( - hive, - &[( - HiveRole::MetaStore.to_string(), - ( - vec![ - PropertyNameKind::Env, - PropertyNameKind::Cli, - PropertyNameKind::File(HIVE_SITE_XML.to_string()), - PropertyNameKind::File(JVM_SECURITY_PROPERTIES_FILE.to_string()), - ], - role.clone(), - ), - )] - .into(), - ) - .context(GenerateProductConfigSnafu)?, + let dereferenced = crate::controller::dereference::dereference(client, hive) + .await + .context(DereferenceSnafu)?; + + let validated = validate::validate_cluster( + hive, + &ctx.operator_environment.image_repository, &ctx.product_config, - false, - false, + dereferenced.s3_connection_spec, + dereferenced.hive_opa_config, ) - .context(InvalidProductConfigSnafu)?; - - let metastore_config = validated_config - .get(&HiveRole::MetaStore.to_string()) - .map(Cow::Borrowed) - .unwrap_or_default(); + .context(ValidateSnafu)?; let mut cluster_resources = ClusterResources::new( APP_NAME, @@ -454,55 +394,42 @@ pub async fn reconcile_hive( .await .context(ApplyRoleBindingSnafu)?; - let hive_opa_config = match hive.get_opa_config() { - Some(opa_config) => Some( - HiveOpaConfig::from_opa_config(client, hive, opa_config) - .await - .context(InvalidOpaConfigSnafu)?, - ), - None => None, - }; - let mut ss_cond_builder = StatefulSetConditionBuilder::default(); - for (rolegroup_name, rolegroup_config) in metastore_config.iter() { + for (rolegroup_name, validated_rg_config) in &validated.role_groups { let rolegroup = hive.metastore_rolegroup_ref(rolegroup_name); - let config = hive - .merged_config(&HiveRole::MetaStore, &rolegroup) - .context(FailedToResolveResourceConfigSnafu)?; - let rg_metrics_service = - build_rolegroup_metrics_service(hive, &resolved_product_image, &rolegroup) + build_rolegroup_metrics_service(hive, &validated.image, &rolegroup) .context(ServiceConfigurationSnafu)?; let rg_headless_service = - build_rolegroup_headless_service(hive, &resolved_product_image, &rolegroup) + build_rolegroup_headless_service(hive, &validated.image, &rolegroup) .context(ServiceConfigurationSnafu)?; let rg_configmap = build_metastore_rolegroup_config_map( hive, &hive_namespace, - &resolved_product_image, + &validated.image, &rolegroup, - rolegroup_config, - &metadata_database_connection_details, - s3_connection_spec.as_ref(), - &config, + &validated_rg_config.product_config_properties, + &validated.metadata_database_connection_details, + validated.s3_connection_spec.as_ref(), + &validated_rg_config.merged_config, &client.kubernetes_cluster_info, - hive_opa_config.as_ref(), + validated.hive_opa_config.as_ref(), )?; let rg_statefulset = build_metastore_rolegroup_statefulset( hive, - &hive_role, - &resolved_product_image, + &HiveRole::MetaStore, + &validated.image, &rolegroup, - rolegroup_config, - &metadata_database_connection_details, - s3_connection_spec.as_ref(), - &config, + &validated_rg_config.product_config_properties, + &validated.metadata_database_connection_details, + validated.s3_connection_spec.as_ref(), + &validated_rg_config.merged_config, &rbac_sa.name_any(), - hive_opa_config.as_ref(), + validated.hive_opa_config.as_ref(), )?; cluster_resources @@ -539,38 +466,39 @@ pub async fn reconcile_hive( ); } - let role_config = hive.role_config(&hive_role); - if let Some(HiveMetastoreRoleConfig { - common: GenericRoleConfig { - pod_disruption_budget: pdb, - }, - .. - }) = role_config - { - add_pdbs(pdb, hive, &hive_role, client, &mut cluster_resources) - .await - .context(FailedToCreatePdbSnafu)?; - } - // std's SipHasher is deprecated, and DefaultHasher is unstable across Rust releases. // We don't /need/ stability, but it's still nice to avoid spurious changes where possible. let mut discovery_hash = FnvHasher::with_key(0); - if let Some(HiveMetastoreRoleConfig { listener_class, .. }) = role_config { - let role_listener: Listener = - build_role_listener(hive, &resolved_product_image, &hive_role, listener_class) - .context(ListenerConfigurationSnafu)?; + if let Some(role_config) = validated.role_config { + add_pdbs( + &role_config.pdb, + hive, + &HiveRole::MetaStore, + client, + &mut cluster_resources, + ) + .await + .context(FailedToCreatePdbSnafu)?; + + let role_listener: Listener = build_role_listener( + hive, + &validated.image, + &HiveRole::MetaStore, + &role_config.listener_class, + ) + .context(ListenerConfigurationSnafu)?; let listener = cluster_resources.add(client, role_listener).await.context( ApplyGroupListenerSnafu { - role: hive_role.to_string(), + role: HiveRole::MetaStore.to_string(), }, )?; for discovery_cm in discovery::build_discovery_configmaps( hive, hive, - hive_role, - &resolved_product_image, + HiveRole::MetaStore, + &validated.image, None, listener, ) diff --git a/rust/operator-binary/src/controller/dereference.rs b/rust/operator-binary/src/controller/dereference.rs new file mode 100644 index 00000000..da0738b9 --- /dev/null +++ b/rust/operator-binary/src/controller/dereference.rs @@ -0,0 +1,60 @@ +use snafu::{ResultExt, Snafu}; +use stackable_operator::{crd::s3, kube::ResourceExt}; + +use crate::{config::opa::HiveOpaConfig, crd::v1alpha1}; + +#[derive(Snafu, Debug)] +pub enum Error { + #[snafu(display("object defines no namespace"))] + ObjectHasNoNamespace, + + #[snafu(display("failed to configure S3 connection"))] + ConfigureS3Connection { + source: s3::v1alpha1::ConnectionError, + }, + + #[snafu(display("invalid OPA configuration"))] + InvalidOpaConfig { + source: stackable_operator::commons::opa::Error, + }, +} + +/// External references resolved during the dereference step. +pub struct DereferencedObjects { + pub s3_connection_spec: Option, + pub hive_opa_config: Option, +} + +pub async fn dereference( + client: &stackable_operator::client::Client, + hive: &v1alpha1::HiveCluster, +) -> Result { + let s3_connection_spec: Option = + if let Some(s3) = &hive.spec.cluster_config.s3 { + Some( + s3.clone() + .resolve( + client, + &hive.namespace().ok_or(Error::ObjectHasNoNamespace)?, + ) + .await + .context(ConfigureS3ConnectionSnafu)?, + ) + } else { + None + }; + + let hive_opa_config = match hive.get_opa_config() { + Some(opa_config) => Some( + HiveOpaConfig::from_opa_config(client, hive, opa_config) + .await + .context(InvalidOpaConfigSnafu)?, + ), + None => None, + }; + + Ok(DereferencedObjects { + s3_connection_spec, + hive_opa_config, + }) +} diff --git a/rust/operator-binary/src/controller/validate.rs b/rust/operator-binary/src/controller/validate.rs new file mode 100644 index 00000000..00ac19e3 --- /dev/null +++ b/rust/operator-binary/src/controller/validate.rs @@ -0,0 +1,165 @@ +use std::{ + borrow::Cow, + collections::{BTreeMap, HashMap}, +}; + +use product_config::{ProductConfigManager, types::PropertyNameKind}; +use snafu::{OptionExt, ResultExt, Snafu}; +use stackable_operator::{ + commons::product_image_selection, + crd::s3, + product_config_utils::{transform_all_roles_to_config, validate_all_roles_and_groups_config}, + role_utils::GenericRoleConfig, +}; + +use crate::{ + config::opa::HiveOpaConfig, + controller::{CONTAINER_IMAGE_BASE_NAME, ValidatedCluster}, + crd::{ + HIVE_SITE_XML, HiveRole, JVM_SECURITY_PROPERTIES_FILE, MetaStoreConfig, + v1alpha1::{self, HiveMetastoreRoleConfig}, + }, +}; + +#[derive(Snafu, Debug)] +pub enum Error { + #[snafu(display("failed to resolve product image"))] + ResolveProductImage { + source: product_image_selection::Error, + }, + + #[snafu(display("object defines no metastore role"))] + NoMetaStoreRole, + + #[snafu(display("failed to generate product config"))] + GenerateProductConfig { + source: stackable_operator::product_config_utils::Error, + }, + + #[snafu(display("invalid product config"))] + InvalidProductConfig { + source: stackable_operator::product_config_utils::Error, + }, + + #[snafu(display("failed to resolve and merge config for role and role group"))] + FailedToResolveConfig { source: crate::crd::Error }, + + #[snafu(display("invalid metadata database connection"))] + InvalidMetadataDatabaseConnection { + source: stackable_operator::database_connections::Error, + }, +} + +/// Per-role configuration extracted during validation. +#[derive(Clone, Debug)] +pub struct ValidatedRoleConfig { + pub pdb: stackable_operator::commons::pdb::PdbConfig, + pub listener_class: String, +} + +/// Per-rolegroup configuration: the merged CRD config plus the product-config properties. +#[derive(Clone, Debug)] +pub struct ValidatedRoleGroupConfig { + pub merged_config: MetaStoreConfig, + pub product_config_properties: HashMap>, +} + +pub fn validate_cluster( + hive: &v1alpha1::HiveCluster, + image_repository: &str, + product_config_manager: &ProductConfigManager, + s3_connection_spec: Option, + hive_opa_config: Option, +) -> Result { + let resolved_product_image = hive + .spec + .image + .resolve( + CONTAINER_IMAGE_BASE_NAME, + image_repository, + crate::built_info::PKG_VERSION, + ) + .context(ResolveProductImageSnafu)?; + + let role = hive.spec.metastore.as_ref().context(NoMetaStoreRoleSnafu)?; + + let validated_config = validate_all_roles_and_groups_config( + &resolved_product_image.product_version, + &transform_all_roles_to_config( + hive, + &[( + HiveRole::MetaStore.to_string(), + ( + vec![ + PropertyNameKind::Env, + PropertyNameKind::Cli, + PropertyNameKind::File(HIVE_SITE_XML.to_string()), + PropertyNameKind::File(JVM_SECURITY_PROPERTIES_FILE.to_string()), + ], + role.clone(), + ), + )] + .into(), + ) + .context(GenerateProductConfigSnafu)?, + product_config_manager, + false, + false, + ) + .context(InvalidProductConfigSnafu)?; + + let metastore_config = validated_config + .get(&HiveRole::MetaStore.to_string()) + .map(Cow::Borrowed) + .unwrap_or_default(); + + let hive_role = HiveRole::MetaStore; + + let role_config = if let Some(HiveMetastoreRoleConfig { + common: GenericRoleConfig { + pod_disruption_budget: pdb, + }, + listener_class, + }) = hive.role_config(&hive_role) + { + Some(ValidatedRoleConfig { + pdb: pdb.clone(), + listener_class: listener_class.clone(), + }) + } else { + None + }; + + let mut group_configs = BTreeMap::new(); + for (rolegroup_name, rolegroup_config) in metastore_config.iter() { + let rolegroup = hive.metastore_rolegroup_ref(rolegroup_name); + + let merged_config = hive + .merged_config(&hive_role, &rolegroup) + .context(FailedToResolveConfigSnafu)?; + + group_configs.insert( + rolegroup_name.clone(), + ValidatedRoleGroupConfig { + merged_config, + product_config_properties: rolegroup_config.clone(), + }, + ); + } + + let metadata_database_connection_details = hive + .spec + .cluster_config + .metadata_database + .jdbc_connection_details("METADATA") + .context(InvalidMetadataDatabaseConnectionSnafu)?; + + Ok(ValidatedCluster { + image: resolved_product_image, + role_groups: group_configs, + role_config, + metadata_database_connection_details, + s3_connection_spec, + hive_opa_config, + }) +} diff --git a/rust/operator-binary/src/crd/mod.rs b/rust/operator-binary/src/crd/mod.rs index 7e4edc63..2b046f18 100644 --- a/rust/operator-binary/src/crd/mod.rs +++ b/rust/operator-binary/src/crd/mod.rs @@ -383,7 +383,7 @@ pub struct HdfsConnection { pub config_map: String, } -#[derive(Display, EnumString, EnumIter)] +#[derive(Clone, Debug, Display, EnumString, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd)] #[strum(serialize_all = "camelCase")] pub enum HiveRole { #[strum(serialize = "metastore")] diff --git a/tests/templates/kuttl/smoke/60-assert.yaml.j2 b/tests/templates/kuttl/smoke/60-assert.yaml.j2 index 37020496..602e0404 100644 --- a/tests/templates/kuttl/smoke/60-assert.yaml.j2 +++ b/tests/templates/kuttl/smoke/60-assert.yaml.j2 @@ -3,36 +3,517 @@ apiVersion: kuttl.dev/v1beta1 kind: TestAssert timeout: 900 --- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive-metastore + app.kubernetes.io/managed-by: listeners.stackable.tech_listener + app.kubernetes.io/name: listener + app.kubernetes.io/role-group: none + stackable.tech/vendor: Stackable + name: hive-metastore + ownerReferences: + - apiVersion: listeners.stackable.tech/v1alpha1 + blockOwnerDeletion: true + controller: true + kind: Listener + name: hive-metastore +spec: + ports: + - name: hive + port: 9083 + protocol: TCP + targetPort: 9083 + type: ClusterIP +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + stackable.tech/vendor: Stackable + name: hive-metastore-default-headless + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +spec: + ports: + - name: hive + port: 9083 + protocol: TCP + targetPort: 9083 + selector: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + type: ClusterIP +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + prometheus.io/path: /metrics + prometheus.io/port: "9084" + prometheus.io/scheme: http + prometheus.io/scrape: "true" + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + prometheus.io/scrape: "true" + stackable.tech/vendor: Stackable + name: hive-metastore-default-metrics + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +spec: + ports: + - name: metrics + port: 9084 + protocol: TCP + targetPort: 9084 + publishNotReadyAddresses: true + selector: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + type: ClusterIP +--- apiVersion: apps/v1 kind: StatefulSet metadata: + generation: 1 + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + restarter.stackable.tech/enabled: "true" + stackable.tech/vendor: Stackable name: hive-metastore-default - generation: 1 # There should be no unneeded Pod restarts + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive spec: + podManagementPolicy: Parallel + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + serviceName: hive-metastore-default-headless template: + metadata: + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + stackable.tech/vendor: Stackable spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchLabels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/name: hive + topologyKey: kubernetes.io/hostname + weight: 70 containers: - - name: hive - resources: - limits: - cpu: "1" - memory: 768Mi - requests: - cpu: 250m - memory: 768Mi {% if lookup('env', 'VECTOR_AGGREGATOR') %} - - name: vector + - name: vector +{% endif %} + - args: + - | + echo copying /stackable/mount/config to /stackable/config + cp -RL /stackable/mount/config/* /stackable/config + echo copying /stackable/mount/log-config/metastore-log4j2.properties to /stackable/config/metastore-log4j2.properties + cp -RL /stackable/mount/log-config/metastore-log4j2.properties /stackable/config/metastore-log4j2.properties + if test -f /stackable/config/core-site.xml; then config-utils template /stackable/config/core-site.xml; fi + if test -f /stackable/config/hive-site.xml; then config-utils template /stackable/config/hive-site.xml; fi + cert-tools generate-pkcs12-truststore --pem /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem --out /stackable/truststore.p12 --out-password changeit +{% if test_scenario['values']['s3-use-tls'] == 'true' %} + cert-tools generate-pkcs12-truststore --pkcs12 /stackable/truststore.p12:changeit --pem /stackable/secrets/minio-tls-certificates/ca.crt --out /stackable/truststore.p12 --out-password changeit +{% endif %} +{% if test_scenario['values']['opa-use-tls'] == 'true' %} + cert-tools generate-pkcs12-truststore --pkcs12 /stackable/truststore.p12:changeit --pem /stackable/secrets/opa-tls/ca.crt --out /stackable/truststore.p12 --out-password changeit {% endif %} + + + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ "${term_child_pid}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + trap - TERM + wait ${term_child_pid} 2>/dev/null + set -e + } + + rm -f /stackable/log/_vector/shutdown + prepare_signal_handlers + containerdebug --output=/stackable/log/containerdebug-state.json --loop & +{% if test_scenario['values']['hive'].split(',')[0].startswith('3.') %} + bin/start-metastore --config /stackable/config --db-type postgres --hive-bin-dir bin & +{% else %} + bin/base --config "/stackable/config" --service schemaTool -dbType "postgres" -initOrUpgradeSchema + bin/base --config "/stackable/config" --service metastore & + +{% endif %} + wait_for_termination $! + mkdir -p /stackable/log/_vector && touch /stackable/log/_vector/shutdown + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: HADOOP_HEAPSIZE + value: "614" + - name: HADOOP_OPTS + value: -Djava.security.properties=/stackable/config/security.properties + -javaagent:/stackable/jmx/jmx_prometheus_javaagent.jar=9084:/stackable/jmx/jmx_hive_config.yaml + -Djavax.net.ssl.trustStore=/stackable/truststore.p12 -Djavax.net.ssl.trustStorePassword=changeit + -Djavax.net.ssl.trustStoreType=pkcs12 + - name: CONTAINERDEBUG_LOG_DIRECTORY + value: /stackable/log/containerdebug + - name: METADATA_DATABASE_USERNAME + valueFrom: + secretKeyRef: + key: username + name: hive-credentials + - name: METADATA_DATABASE_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: hive-credentials + - name: COMMON_VAR + value: group-value + - name: GROUP_VAR + value: group-value + - name: ROLE_VAR + value: role-value + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 3 + initialDelaySeconds: 30 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: hive + timeoutSeconds: 1 + name: hive + ports: + - containerPort: 9083 + name: hive + protocol: TCP + - containerPort: 9084 + name: metrics + protocol: TCP + readinessProbe: + failureThreshold: 5 + initialDelaySeconds: 10 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: hive + timeoutSeconds: 1 + resources: + limits: + cpu: "1" + memory: 768Mi + requests: + cpu: 250m + memory: 768Mi + volumeMounts: + - mountPath: /stackable/secrets/test-hive-s3-secret-class + name: test-hive-s3-secret-class-s3-credentials +{% if test_scenario['values']['s3-use-tls'] == 'true' %} + - mountPath: /stackable/secrets/minio-tls-certificates + name: minio-tls-certificates-ca-cert +{% endif %} +{% if test_scenario['values']['opa-use-tls'] == 'true' %} + - mountPath: /stackable/secrets/opa-tls + name: opa-tls +{% endif %} + - mountPath: /stackable/config + name: config + - mountPath: /stackable/mount/config + name: config-mount + - mountPath: /stackable/log + name: log + - mountPath: /stackable/mount/log-config + name: log-config-mount + - mountPath: /stackable/listener + name: listener + dnsPolicy: ClusterFirst + enableServiceLinks: false + restartPolicy: Always + schedulerName: default-scheduler + securityContext: + fsGroup: 1000 + serviceAccount: hive-serviceaccount + serviceAccountName: hive-serviceaccount terminationGracePeriodSeconds: 300 + volumes: + - ephemeral: + volumeClaimTemplate: + metadata: + annotations: + secrets.stackable.tech/class: test-hive-s3-secret-class + secrets.stackable.tech/provision-parts: public-private + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: "1" + storageClassName: secrets.stackable.tech + volumeMode: Filesystem + name: test-hive-s3-secret-class-s3-credentials +{% if test_scenario['values']['s3-use-tls'] == 'true' %} + - ephemeral: + volumeClaimTemplate: + metadata: + annotations: + secrets.stackable.tech/class: minio-tls-certificates + secrets.stackable.tech/provision-parts: public + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: "1" + storageClassName: secrets.stackable.tech + volumeMode: Filesystem + name: minio-tls-certificates-ca-cert +{% endif %} +{% if test_scenario['values']['opa-use-tls'] == 'true' %} + - ephemeral: + volumeClaimTemplate: + metadata: + annotations: + secrets.stackable.tech/provision-parts: public + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: "1" + storageClassName: secrets.stackable.tech + volumeMode: Filesystem + name: opa-tls +{% endif %} + - emptyDir: + sizeLimit: 10Mi + name: config + - configMap: + defaultMode: 420 + name: hive-metastore-default + name: config-mount + - emptyDir: + sizeLimit: 30Mi + name: log + - configMap: + defaultMode: 420 + name: hive-metastore-default + name: log-config-mount + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + annotations: + listeners.stackable.tech/listener-name: hive-metastore + creationTimestamp: null + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + app.kubernetes.io/version: none + stackable.tech/vendor: Stackable + name: listener + spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: "1" + storageClassName: listeners.stackable.tech + volumeMode: Filesystem status: readyReplicas: 1 replicas: 1 --- +apiVersion: v1 +#data: +# HIVE: thrift://hive-metastore.$NAMESPACE.svc.cluster.local:9083 +kind: ConfigMap +metadata: + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: discovery + stackable.tech/vendor: Stackable + name: hive + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +--- +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: default + stackable.tech/vendor: Stackable + name: hive-metastore-default + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + name: hive-serviceaccount + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + labels: + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + name: hive-rolebinding + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: hive-clusterrole +subjects: +- kind: ServiceAccount + name: hive-serviceaccount +--- apiVersion: policy/v1 kind: PodDisruptionBudget metadata: + generation: 1 + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive name: hive-metastore + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +spec: + maxUnavailable: 1 + selector: + matchLabels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/name: hive status: expectedPods: 1 currentHealthy: 1 disruptionsAllowed: 1 +--- +apiVersion: listeners.stackable.tech/v1alpha1 +kind: Listener +metadata: + generation: 1 + labels: + app.kubernetes.io/component: metastore + app.kubernetes.io/instance: hive + app.kubernetes.io/managed-by: hive.stackable.tech_hivecluster + app.kubernetes.io/name: hive + app.kubernetes.io/role-group: none + stackable.tech/vendor: Stackable + name: hive-metastore + ownerReferences: + - apiVersion: hive.stackable.tech/v1alpha1 + controller: true + kind: HiveCluster + name: hive +spec: + ports: + - name: hive + port: 9083 + protocol: TCP +status: + ingressAddresses: + # address: hive-metastore.$NAMESPACE.svc.cluster.local + - addressType: Hostname + ports: + hive: 9083 + serviceName: hive-metastore