Skip to content

Commit

Permalink
Fixing opening session
Browse files Browse the repository at this point in the history
  • Loading branch information
ausias-armesto committed Jan 13, 2025
1 parent 9c32ea2 commit c4c5270
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 33 deletions.
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.20"
version = "0.2.21"
authors = ["HOPR Association <[email protected]>"]
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion charts/cluster-hoprd/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

apiVersion: v2
name: cluster-hoprd
version: 0.3.2
version: 0.3.3
description: A Helm chart to deploy ClusterHoprd
type: application
icon: "https://hoprnet.org/assets/icons/logo.svg"
1 change: 1 addition & 0 deletions charts/cluster-hoprd/templates/cluster-hoprd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ spec:
{{- if .Values.deployment }}
deployment: {{ .Values.deployment | toYaml | nindent 4 }}
{{- end }}
portsAllocation: {{ .Values.ports_allocation }}
service: {{ .Values.service | toYaml | nindent 4 }}

config: {{ .Values.config | toYaml | nindent 4 }}
5 changes: 5 additions & 0 deletions charts/cluster-hoprd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ forceIdentityName: false
##
deployment: {}

##
## @param ports_allocation Ports allocation
##
ports_allocation: 10

service:
##
## @param service.type Service Type
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.18
appVersion: 0.2.20
version: 0.2.19
appVersion: 0.2.21
description: A Helm chart operator for managing Hopr nodes
type: application
icon: "https://hoprnet.org/assets/icons/logo.svg"
2 changes: 1 addition & 1 deletion charts/hoprd-operator/templates/crd-cluster-hoprd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ spec:
readinessProbe:
type: string
description: The definition of the readiness probe to be used by the node deployment
ports_allocation:
portsAllocation:
type: number
description: >-
Number of ports to be opened for session management in the hoprd node.
Expand Down
2 changes: 1 addition & 1 deletion charts/hoprd-operator/templates/crd-hoprd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
deleteDatabase:
type: boolean
description: 'Trigger to delete the database of the node'
ports_allocation:
portsAllocation:
type: number
description: >-
Number of ports to be opened for session management in the hoprd node.
Expand Down
2 changes: 1 addition & 1 deletion charts/hoprd-operator/templates/cronjob-fast-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
fi
# Upload to GCS with verification
if ! gcloud storage cp /tmp/hopr_logs.tar.gz gs://hoprd-sync-data-staging/hopr_logs.tar.gz; then
if ! gcloud storage cp /tmp/hopr_logs.tar.gz gs://{{ .Values.operator.crossplane.bucket.name }}/hopr_logs.tar.gz; then
echo "Failed to upload backup"
exit 1
fi
Expand Down
1 change: 1 addition & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub const HOPRD_API_HOST: &str = "HOPRD_API_HOST";
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_DEFAULT_SESSION_LISTEN_HOST: &str = "HOPRD_DEFAULT_SESSION_LISTEN_HOST";
pub const HOPRD_PORTS_ALLOCATION: u16 = 10;

#[derive(Serialize, Deserialize, Debug, PartialEq, Default, Clone, Hash, Copy, JsonSchema)]
Expand Down
57 changes: 32 additions & 25 deletions src/hoprd/hoprd_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub async fn create_deployment(context_data: Arc<ContextData>, hoprd: &Hoprd, id
let name: String = hoprd.name_any();
let owner_references: Option<Vec<OwnerReference>> = Some(vec![hoprd.controller_owner_ref(&()).unwrap()]);
let identity_pool: IdentityPool = identity_hoprd.get_identity_pool(context_data.client.clone()).await.unwrap();
let bucket_name= context_data.config.bucket_name.to_owned().unwrap();

let mut labels: BTreeMap<String, String> = utils::common_lables(context_data.config.instance.name.to_owned(), Some(name.to_owned()), Some("node".to_owned()));
labels.insert(constants::LABEL_NODE_NETWORK.to_owned(), identity_pool.spec.network.clone());
Expand All @@ -65,7 +66,7 @@ pub async fn create_deployment(context_data: Arc<ContextData>, hoprd: &Hoprd, id
owner_references,
..ObjectMeta::default()
},
spec: Some(build_deployment_spec(labels, &hoprd.spec, identity_pool, identity_hoprd, &hoprd_host, starting_port, last_port).await),
spec: Some(build_deployment_spec(labels, &hoprd.spec, identity_pool, identity_hoprd, &hoprd_host, starting_port, last_port, bucket_name).await),
..Deployment::default()
};

Expand All @@ -84,6 +85,7 @@ pub async fn build_deployment_spec(
hoprd_host: &str,
starting_port: u16,
last_port: u16,
bucket_name: String
) -> DeploymentSpec {
let image = format!(
"{}/{}:{}",
Expand All @@ -100,11 +102,24 @@ pub async fn build_deployment_spec(
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),
]);


let init_command = Some(vec![
format!(
r#"
set -e # Exit on any error
if ! ls /app/hoprd-db/db/hopr_logs.db* 1> /dev/null 2>&1; then
apk add --no-cache curl tar
curl -sf --retry 3 "https://storage.googleapis.com/{}/hopr_logs.tar.gz" -o /tmp/hopr_logs.tar.gz
tar xf /tmp/hopr_logs.tar.gz -C /
rm -f /tmp/hopr_logs.tar.gz
fi
echo $HOPRD_IDENTITY_FILE | base64 -d > /app/hoprd-identity/.hopr-id
echo $HOPRD_CONFIGURATION | base64 -d > /app/hoprd-identity/config.yaml
"#,
bucket_name
)]);


DeploymentSpec {
replicas: Some(replicas),
Expand Down Expand Up @@ -133,11 +148,7 @@ pub async fn build_deployment_spec(
..EnvVar::default()
},
]),
command: Some(vec!["/bin/sh".to_owned(), "-c".to_owned()]),
args: Some(vec![format!(
"{} && {}",
"echo $HOPRD_IDENTITY_FILE | base64 -d > /app/hoprd-identity/.hopr-id", "echo $HOPRD_CONFIGURATION | base64 -d > /app/hoprd-identity/config.yaml"
)]),
command: init_command,
volume_mounts: volume_mounts.to_owned(),
..Container::default()
}]),
Expand All @@ -147,7 +158,7 @@ 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,
// command,
// command: Some(vec!["sh".to_string(), "-c".to_string()]),
// args: Some(vec!["sleep 99999999".to_owned()]),
liveness_probe,
Expand Down Expand Up @@ -198,7 +209,8 @@ pub async fn modify_deployment(context_data: Arc<ContextData>, deployment_name:
let ports_allocation = hoprd_spec.ports_allocation.clone().unwrap_or(constants::HOPRD_PORTS_ALLOCATION);
let last_port = starting_port + ports_allocation;
let identity_pool: IdentityPool = identity_hoprd.get_identity_pool(context_data.client.clone()).await.unwrap();
let spec = build_deployment_spec(deployment.labels().to_owned(), hoprd_spec, identity_pool, identity_hoprd, &hoprd_host, starting_port, last_port).await;
let bucket_name= context_data.config.bucket_name.to_owned().unwrap();
let spec = build_deployment_spec(deployment.labels().to_owned(), hoprd_spec, identity_pool, identity_hoprd, &hoprd_host, starting_port, last_port, bucket_name).await;
let patch = &Patch::Merge(json!({ "spec": spec }));
api.patch(deployment_name, &PatchParams::default(), patch).await.unwrap();
Ok(())
Expand Down Expand Up @@ -449,18 +461,6 @@ fn build_env_vars(identity_pool: &IdentityPool, identity_hoprd: &IdentityHoprd,
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 Expand Up @@ -560,5 +560,12 @@ fn build_default_env_var(hoprd_host: &String) -> Vec<EnvVar> {
value: Some("0.0.0.0".to_owned()),
..EnvVar::default()
},
EnvVar {
name: constants::HOPRD_DEFAULT_SESSION_LISTEN_HOST.to_owned(),
value: Some("0.0.0.0:0".to_owned()),
..EnvVar::default()
},


]
}

0 comments on commit c4c5270

Please sign in to comment.