diff --git a/Cargo.lock b/Cargo.lock index 546e67b..f7af4fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,7 +541,7 @@ dependencies = [ [[package]] name = "hoprd_operator" -version = "0.2.19" +version = "0.2.20" dependencies = [ "async-recursion", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 8b0f104..88e700d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hoprd_operator" -version = "0.2.19" +version = "0.2.20" authors = ["HOPR Association "] edition = "2021" diff --git a/charts/cluster-hoprd/README.md b/charts/cluster-hoprd/README.md index ec7891d..69dcac3 100644 --- a/charts/cluster-hoprd/README.md +++ b/charts/cluster-hoprd/README.md @@ -24,7 +24,7 @@ This chart packages the creation of a ClusterHoprd | `replicas` | Number of instances | `1` | | `version` | Hoprd node version to run | `2.0.2` | | `enabled` | Running status of the nodes | `true` | -| `supportedRelease` | The kind of supported release | `""` | +| `supportedRelease` | The kind of supported release | `""` | | `forceIdentityName` | Forces identity names to be set in child Hopd resources | `false` | | `deployment` | Deployment spec | `{}` | | `config` | Custom configuration of nodes | `""` | diff --git a/charts/cluster-hoprd/values.yaml b/charts/cluster-hoprd/values.yaml index 21cf2b9..d986941 100644 --- a/charts/cluster-hoprd/values.yaml +++ b/charts/cluster-hoprd/values.yaml @@ -65,7 +65,7 @@ version: 2.0.2 enabled: true ## -## @param supportedRelease The kind of supported release +## @param supportedRelease The kind of supported release ## supportedRelease: "" diff --git a/charts/hoprd-operator/Chart.yaml b/charts/hoprd-operator/Chart.yaml index b2e5b28..c78e823 100644 --- a/charts/hoprd-operator/Chart.yaml +++ b/charts/hoprd-operator/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: hoprd-operator -version: 0.2.16 -appVersion: 0.2.19 +version: 0.2.17 +appVersion: 0.2.20 description: A Helm chart operator for managing Hopr nodes type: application icon: "https://hoprnet.org/assets/icons/logo.svg" diff --git a/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml b/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml index c211797..ded5acb 100644 --- a/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml +++ b/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml @@ -76,7 +76,6 @@ spec: type: string description: 'Release Name of the supported version' enum: - - providence - saint-louis forceIdentityName: type: boolean diff --git a/charts/hoprd-operator/templates/crd-hoprd.yaml b/charts/hoprd-operator/templates/crd-hoprd.yaml index 6243f5a..11c388a 100644 --- a/charts/hoprd-operator/templates/crd-hoprd.yaml +++ b/charts/hoprd-operator/templates/crd-hoprd.yaml @@ -59,7 +59,6 @@ spec: type: string description: 'Release Name of the supported version' enum: - - providence - saint-louis service: type: object diff --git a/src/constants.rs b/src/constants.rs index e7c7a20..efd70ca 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -41,7 +41,6 @@ pub const HOPRD_API_TOKEN: &str = "HOPRD_API_TOKEN"; pub const HOPRD_NETWORK: &str = "HOPRD_NETWORK"; pub const HOPRD_CONFIGURATION_FILE_PATH: &str = "HOPRD_CONFIGURATION_FILE_PATH"; pub const HOPRD_CONFIGURATION: &str = "HOPRD_CONFIGURATION"; -pub const HOPRD_ANNOUNCE: &str = "HOPRD_ANNOUNCE"; pub const HOPRD_SAFE_ADDRESS: &str = "HOPRD_SAFE_ADDRESS"; pub const HOPRD_MODULE_ADDRESS: &str = "HOPRD_MODULE_ADDRESS"; pub const HOPRD_IDENTITY: &str = "HOPRD_IDENTITY"; @@ -49,7 +48,6 @@ pub const HOPRD_DATA: &str = "HOPRD_DATA"; pub const HOPRD_HOST: &str = "HOPRD_HOST"; pub const HOPRD_API: &str = "HOPRD_API"; pub const HOPRD_API_HOST: &str = "HOPRD_API_HOST"; -pub const HOPRD_INIT: &str = "HOPRD_INIT"; pub const HOPRD_HEALTH_CHECK: &str = "HOPRD_HEALTH_CHECK"; pub const HOPRD_HEALTH_CHECK_HOST: &str = "HOPRD_HEALTH_CHECK_HOST"; pub const HOPRD_SESSION_PORT_RANGE: &str = "HOPRD_SESSION_PORT_RANGE"; @@ -57,9 +55,7 @@ pub const HOPRD_PORTS_ALLOCATION: u16 = 10; #[derive(Serialize, Deserialize, Debug, PartialEq, Default, Clone, Hash, Copy, JsonSchema)] pub enum SupportedReleaseEnum { - #[serde(rename = "providence")] #[default] - Providence, #[serde(rename = "saint-louis")] SaintLouis, } diff --git a/src/hoprd/hoprd_deployment.rs b/src/hoprd/hoprd_deployment.rs index 0917593..de2db5d 100644 --- a/src/hoprd/hoprd_deployment.rs +++ b/src/hoprd/hoprd_deployment.rs @@ -13,7 +13,7 @@ use crate::{ use futures::StreamExt; use k8s_openapi::api::batch::v1::JobSpec; use k8s_openapi::api::core::v1::{ - Container, ContainerPort, EmptyDirVolumeSource, EnvVar, EnvVarSource, PersistentVolumeClaimVolumeSource, PodSpec, PodTemplateSpec, SecretKeySelector, Volume, VolumeMount, + Container, ContainerPort, EmptyDirVolumeSource, EnvVar, EnvVarSource, ObjectFieldSelector, PersistentVolumeClaimVolumeSource, PodSpec, PodTemplateSpec, SecretKeySelector, Volume, VolumeMount, }; use k8s_openapi::api::{ apps::v1::{Deployment, DeploymentSpec, DeploymentStrategy}, @@ -93,13 +93,18 @@ pub async fn build_deployment_spec( ); let replicas: i32 = if hoprd_spec.enabled.unwrap_or(true) { 1 } else { 0 }; let resources = Some(HoprdDeploymentSpec::get_resource_requirements(hoprd_spec.deployment.clone())); - let liveness_probe = HoprdDeploymentSpec::get_liveness_probe(hoprd_spec.supported_release, hoprd_spec.deployment.clone()); - let readiness_probe = HoprdDeploymentSpec::get_readiness_probe(hoprd_spec.supported_release, hoprd_spec.deployment.clone()); - let startup_probe = HoprdDeploymentSpec::get_startup_probe(hoprd_spec.supported_release, hoprd_spec.deployment.clone()); + let liveness_probe = HoprdDeploymentSpec::get_liveness_probe(hoprd_spec.deployment.clone()); + let readiness_probe = HoprdDeploymentSpec::get_readiness_probe(hoprd_spec.deployment.clone()); + let startup_probe = HoprdDeploymentSpec::get_startup_probe(hoprd_spec.deployment.clone()); let volume_mounts: Option> = build_volume_mounts(); let hoprd_host_port = format!("{}:{}", hoprd_host, starting_port); let session_port_range = format!("{}:{}", starting_port + 1, last_port - 1); let encoded_configuration = general_purpose::STANDARD.encode(&hoprd_spec.config); + let command = Some(vec![ + "sh".to_string(), + "-c".to_string(), + format!("HOPRD_DEFAULT_SESSION_LISTEN_HOST=\"$POD_IP:{}\" hoprd", starting_port + 1), + ]); DeploymentSpec { replicas: Some(replicas), @@ -142,7 +147,8 @@ pub async fn build_deployment_spec( image_pull_policy: Some("Always".to_owned()), ports: Some(build_ports(starting_port.into(), last_port.into())), env: Some(build_env_vars(&identity_pool, identity_hoprd, &hoprd_host_port, hoprd_spec, session_port_range)), - // command: Some(vec!["/bin/bash".to_owned(), "-c".to_owned()]), + command, + // command: Some(vec!["sh".to_string(), "-c".to_string()]), // args: Some(vec!["sleep 99999999".to_owned()]), liveness_probe, readiness_probe, @@ -243,7 +249,12 @@ pub async fn job_delete_database(context_data: Arc, deployment_name let api: Api = Api::namespaced(context_data.client.clone(), namespace); let rng = rand::thread_rng(); let suffix: String = rng.sample_iter(&Alphanumeric).take(10).map(char::from).collect(); - let bucket_name = context_data.config.bucket_name.as_ref().expect("No bucket name has been specified in hoprd operator configuration").clone(); + let bucket_name = context_data + .config + .bucket_name + .as_ref() + .expect("No bucket name has been specified in hoprd operator configuration") + .clone(); let commands = format!( r#" set -e # Exit on any error @@ -295,7 +306,7 @@ pub async fn job_delete_database(context_data: Arc, deployment_name containers: vec![Container { name: "delete-hoprd-db".to_string(), image: Some("debian:stable".to_string()), - command: Some(vec![ "/bin/sh".to_string(), "-c".to_string(), commands ]), + command: Some(vec!["/bin/sh".to_string(), "-c".to_string(), commands]), volume_mounts: Some(vec![VolumeMount { name: "hoprd-db".to_string(), mount_path: "/app/hoprd-db".to_string(), @@ -428,34 +439,28 @@ fn build_env_vars(identity_pool: &IdentityPool, identity_hoprd: &IdentityHoprd, env_vars.extend_from_slice(&build_crd_env_var(identity_pool, identity_hoprd)); env_vars.extend_from_slice(&build_default_env_var(hoprd_host)); env_vars.extend_from_slice(&HoprdDeploymentSpec::get_environment_variables(hoprd_spec.deployment.to_owned())); - if hoprd_spec.supported_release.eq(&constants::SupportedReleaseEnum::Providence) { - env_vars.push(EnvVar { - name: constants::HOPRD_ANNOUNCE.to_owned(), - value: Some("true".to_owned()), - ..EnvVar::default() - }); - env_vars.push(EnvVar { - name: constants::HOPRD_API.to_owned(), - value: Some("true".to_owned()), - ..EnvVar::default() - }); - env_vars.push(EnvVar { - name: constants::HOPRD_INIT.to_owned(), - value: Some("true".to_owned()), - ..EnvVar::default() - }); - } else { - env_vars.push(EnvVar { - name: constants::HOPRD_API.to_owned(), - value: Some("1".to_owned()), - ..EnvVar::default() - }); - env_vars.push(EnvVar { - name: constants::HOPRD_SESSION_PORT_RANGE.to_owned(), - value: Some(session_port_range), - ..EnvVar::default() - }); - } + env_vars.push(EnvVar { + name: constants::HOPRD_API.to_owned(), + value: Some("1".to_owned()), + ..EnvVar::default() + }); + env_vars.push(EnvVar { + name: constants::HOPRD_SESSION_PORT_RANGE.to_owned(), + value: Some(session_port_range), + ..EnvVar::default() + }); + // Get the pod IPV4 address + env_vars.push(EnvVar { + name: "POD_IP".to_owned(), + value_from: Some(EnvVarSource { + field_ref: Some(ObjectFieldSelector { + api_version: Some("v1".to_owned()), + field_path: "status.podIP".to_owned(), + }), + ..EnvVarSource::default() + }), + ..EnvVar::default() + }); env_vars } diff --git a/src/hoprd/hoprd_deployment_spec.rs b/src/hoprd/hoprd_deployment_spec.rs index 5775500..79581f8 100644 --- a/src/hoprd/hoprd_deployment_spec.rs +++ b/src/hoprd/hoprd_deployment_spec.rs @@ -6,8 +6,6 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; -use crate::constants::SupportedReleaseEnum; - #[derive(Serialize, Deserialize, Debug)] struct CustomEnvVar { name: String, @@ -107,57 +105,42 @@ impl HoprdDeploymentSpec { } } - pub fn get_liveness_probe(supported_release: SupportedReleaseEnum, hoprd_deployment_spec_option: Option) -> Option { - match supported_release { - SupportedReleaseEnum::Providence => None, - SupportedReleaseEnum::SaintLouis => { - let default_liveness_probe = HoprdDeploymentSpec::build_probe("/healthyz".to_owned(), Some(5), Some(1), Some(3)); - if let Some(hoprd_deployment_spec) = hoprd_deployment_spec_option { - if let Some(liveness_probe_string) = hoprd_deployment_spec.liveness_probe { - Some(serde_yaml::from_str(&liveness_probe_string).unwrap()) - } else { - Some(default_liveness_probe) - } - } else { - Some(default_liveness_probe) - } + pub fn get_liveness_probe(hoprd_deployment_spec_option: Option) -> Option { + let default_liveness_probe = HoprdDeploymentSpec::build_probe("/healthyz".to_owned(), Some(5), Some(1), Some(3)); + if let Some(hoprd_deployment_spec) = hoprd_deployment_spec_option { + if let Some(liveness_probe_string) = hoprd_deployment_spec.liveness_probe { + Some(serde_yaml::from_str(&liveness_probe_string).unwrap()) + } else { + Some(default_liveness_probe) } + } else { + Some(default_liveness_probe) } } - pub fn get_startup_probe(supported_release: SupportedReleaseEnum, hoprd_deployment_spec_option: Option) -> Option { - match supported_release { - SupportedReleaseEnum::Providence => None, - SupportedReleaseEnum::SaintLouis => { - let default_startup_probe = HoprdDeploymentSpec::build_probe("/startedz".to_owned(), Some(15), Some(1), Some(8)); - if let Some(hoprd_deployment_spec) = hoprd_deployment_spec_option { - if let Some(startup_probe_string) = hoprd_deployment_spec.startup_probe { - Some(serde_yaml::from_str(&startup_probe_string).unwrap()) - } else { - Some(default_startup_probe) - } - } else { - Some(default_startup_probe) - } + pub fn get_startup_probe(hoprd_deployment_spec_option: Option) -> Option { + let default_startup_probe = HoprdDeploymentSpec::build_probe("/startedz".to_owned(), Some(15), Some(1), Some(8)); + if let Some(hoprd_deployment_spec) = hoprd_deployment_spec_option { + if let Some(startup_probe_string) = hoprd_deployment_spec.startup_probe { + Some(serde_yaml::from_str(&startup_probe_string).unwrap()) + } else { + Some(default_startup_probe) } + } else { + Some(default_startup_probe) } } - pub fn get_readiness_probe(supported_release: SupportedReleaseEnum, hoprd_deployment_spec_option: Option) -> Option { - match supported_release { - SupportedReleaseEnum::Providence => None, - SupportedReleaseEnum::SaintLouis => { - let default_readiness_probe = HoprdDeploymentSpec::build_probe("/readyz".to_owned(), Some(10), Some(1), Some(6)); - if let Some(hoprd_deployment_spec) = hoprd_deployment_spec_option { - if let Some(readiness_probe_string) = hoprd_deployment_spec.readiness_probe { - Some(serde_yaml::from_str(&readiness_probe_string).unwrap()) - } else { - Some(default_readiness_probe) - } - } else { - Some(default_readiness_probe) - } + pub fn get_readiness_probe(hoprd_deployment_spec_option: Option) -> Option { + let default_readiness_probe = HoprdDeploymentSpec::build_probe("/readyz".to_owned(), Some(10), Some(1), Some(6)); + if let Some(hoprd_deployment_spec) = hoprd_deployment_spec_option { + if let Some(readiness_probe_string) = hoprd_deployment_spec.readiness_probe { + Some(serde_yaml::from_str(&readiness_probe_string).unwrap()) + } else { + Some(default_readiness_probe) } + } else { + Some(default_readiness_probe) } } }