1- use std:: { collections:: BTreeMap , str:: FromStr } ;
1+ use std:: { collections:: BTreeMap , num :: TryFromIntError , str:: FromStr } ;
22
33use snafu:: { OptionExt , ResultExt , Snafu } ;
4- use stackable_operator:: kube:: { Resource , ResourceExt } ;
4+ use stackable_operator:: {
5+ kube:: { Resource , ResourceExt } ,
6+ role_utils:: RoleGroup ,
7+ time:: Duration ,
8+ } ;
59use strum:: { EnumDiscriminants , IntoStaticStr } ;
610
7- use super :: { ProductVersion , RoleGroupName , ValidatedCluster } ;
11+ use super :: { ProductVersion , RoleGroupName , ValidatedCluster , ValidatedOpenSearchConfig } ;
812use crate :: {
9- crd:: v1alpha1,
13+ crd:: v1alpha1:: { self , OpenSearchConfig } ,
1014 framework:: {
1115 ClusterName ,
1216 role_utils:: { RoleGroupConfig , with_validated_config} ,
@@ -38,10 +42,17 @@ pub enum Error {
3842 ValidateOpenSearchConfig {
3943 source : stackable_operator:: config:: fragment:: ValidationError ,
4044 } ,
45+
46+ #[ snafu( display( "termination grace period is too long (got {duration}, maximum allowed is {max})" , max = Duration :: from_secs( i64 :: MAX as u64 ) ) ) ]
47+ TerminationGracePeriodTooLong {
48+ source : TryFromIntError ,
49+ duration : Duration ,
50+ } ,
4151}
4252
4353type Result < T , E = Error > = std:: result:: Result < T , E > ;
4454
55+ // TODO split
4556// no client needed
4657pub fn validate ( cluster : & v1alpha1:: OpenSearchCluster ) -> Result < ValidatedCluster > {
4758 let raw_cluster_name = cluster. meta ( ) . name . clone ( ) . context ( GetClusterNameSnafu ) ?;
@@ -59,13 +70,38 @@ pub fn validate(cluster: &v1alpha1::OpenSearchCluster) -> Result<ValidatedCluste
5970 let role_group_name =
6071 RoleGroupName :: from_str ( raw_role_group_name) . context ( ParseRoleGroupNameSnafu ) ?;
6172
62- let validated_role_group = with_validated_config (
73+ let merged_role_group : RoleGroup < OpenSearchConfig , _ > = with_validated_config (
6374 role_group_config,
6475 & cluster. spec . nodes ,
6576 & v1alpha1:: OpenSearchConfig :: default_config ( ) ,
6677 )
6778 . context ( ValidateOpenSearchConfigSnafu ) ?;
68- let validated_role_group_config = RoleGroupConfig :: from ( validated_role_group) ;
79+
80+ let graceful_shutdown_timeout = merged_role_group. config . config . graceful_shutdown_timeout ;
81+
82+ let termination_grace_period_seconds = graceful_shutdown_timeout
83+ . as_secs ( )
84+ . try_into ( )
85+ . context ( TerminationGracePeriodTooLongSnafu {
86+ duration : graceful_shutdown_timeout,
87+ } ) ?;
88+
89+ let validated_config = ValidatedOpenSearchConfig {
90+ node_roles : merged_role_group. config . config . node_roles ,
91+ resources : merged_role_group. config . config . resources ,
92+ termination_grace_period_seconds,
93+ } ;
94+
95+ let validated_role_group_config = RoleGroupConfig {
96+ // Kubernetes defaults to 1 if not set
97+ replicas : merged_role_group. replicas . unwrap_or ( 1 ) ,
98+ config : validated_config,
99+ config_overrides : merged_role_group. config . config_overrides ,
100+ env_overrides : merged_role_group. config . env_overrides ,
101+ cli_overrides : merged_role_group. config . cli_overrides ,
102+ pod_overrides : merged_role_group. config . pod_overrides ,
103+ product_specific_common_config : merged_role_group. config . product_specific_common_config ,
104+ } ;
69105
70106 role_group_configs. insert ( role_group_name, validated_role_group_config) ;
71107 }
0 commit comments