Skip to content

Commit

Permalink
Supporting specify IPv4 address for default session host (#258)
Browse files Browse the repository at this point in the history
* Supporting specify IPv4 address for default session host

* Add defaults

* Fixing lint
  • Loading branch information
ausias-armesto authored Dec 3, 2024
1 parent 05851e1 commit 6e7b466
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-helm-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Lint
run: helm -f ./values-stage.yaml lint
run: helm lint -f ./values-staging.yaml .
working-directory: 'charts/cluster-hoprd/'

package:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-helm-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Lint
run: helm lint
run: helm lint -f ./values-staging.yaml .
working-directory: 'charts/hoprd-operator/'

package:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hoprd_operator"
version = "0.2.19"
version = "0.2.20"
authors = ["HOPR Association <[email protected]>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions charts/cluster-hoprd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ This chart packages the creation of a ClusterHoprd
| `wallet.identityPassword` | Password used by all identities defined bellow | `""` |
| `wallet.hoprdApiToken` | API Token used by all nodes of the cluster | `""` |
| `network` | Hoprd Network: rotsee, dufour | `""` |
| `identityPool.minReadyIdentities` | Minimum number of identites in ready state | `0` |
| `identityPool.funding.enabled` | Enable cron auto-funding | `false` |
| `identityPool.funding.schedule` | Cron schedule to run auto-funding job. | `0 1 * * 1` |
| `identityPool.funding.nativeAmount` | Number of xDai to fund each node | `0.01` |
| `identities` | Map of identities to create | `{}` |
| `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 <providence|saint-louis> | `""` |
| `supportedRelease` | The kind of supported release <saint-louis> | `""` |
| `forceIdentityName` | Forces identity names to be set in child Hopd resources | `false` |
| `deployment` | Deployment spec | `{}` |
| `service.type` | Service Type | `ClusterIP` |
| `config` | Custom configuration of nodes | `""` |
10 changes: 5 additions & 5 deletions charts/cluster-hoprd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ version: 2.0.2
enabled: true

##
## @param supportedRelease The kind of supported release <providence|saint-louis>
## @param supportedRelease The kind of supported release <saint-louis>
##
supportedRelease: ""

Expand All @@ -79,10 +79,10 @@ forceIdentityName: false
##
deployment: {}

##
## @param service Service spec
##
service:
service:
##
## @param service.type Service Type
##
type: "ClusterIP"


Expand Down
4 changes: 2 additions & 2 deletions charts/hoprd-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion charts/hoprd-operator/templates/crd-cluster-hoprd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ spec:
type: string
description: 'Release Name of the supported version'
enum:
- providence
- saint-louis
forceIdentityName:
type: boolean
Expand Down
1 change: 0 additions & 1 deletion charts/hoprd-operator/templates/crd-hoprd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ spec:
type: string
description: 'Release Name of the supported version'
enum:
- providence
- saint-louis
service:
type: object
Expand Down
4 changes: 0 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,21 @@ 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";
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";
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,
}
75 changes: 40 additions & 35 deletions src/hoprd/hoprd_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<Vec<VolumeMount>> = 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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -243,7 +249,12 @@ pub async fn job_delete_database(context_data: Arc<ContextData>, deployment_name
let api: Api<Job> = 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
Expand Down Expand Up @@ -295,7 +306,7 @@ pub async fn job_delete_database(context_data: Arc<ContextData>, 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(),
Expand Down Expand Up @@ -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
}

Expand Down
71 changes: 27 additions & 44 deletions src/hoprd/hoprd_deployment_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -107,57 +105,42 @@ impl HoprdDeploymentSpec {
}
}

pub fn get_liveness_probe(supported_release: SupportedReleaseEnum, hoprd_deployment_spec_option: Option<HoprdDeploymentSpec>) -> Option<Probe> {
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<HoprdDeploymentSpec>) -> Option<Probe> {
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<HoprdDeploymentSpec>) -> Option<Probe> {
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<HoprdDeploymentSpec>) -> Option<Probe> {
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<HoprdDeploymentSpec>) -> Option<Probe> {
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<HoprdDeploymentSpec>) -> Option<Probe> {
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)
}
}
}
Expand Down

0 comments on commit 6e7b466

Please sign in to comment.