diff --git a/Cargo.lock b/Cargo.lock index f7af4fc..f84a211 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,7 +541,7 @@ dependencies = [ [[package]] name = "hoprd_operator" -version = "0.2.20" +version = "0.2.21" dependencies = [ "async-recursion", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 88e700d..96e2c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hoprd_operator" -version = "0.2.20" +version = "0.2.21" authors = ["HOPR Association "] edition = "2021" diff --git a/charts/cluster-hoprd/Chart.yaml b/charts/cluster-hoprd/Chart.yaml index c133914..a193fa3 100644 --- a/charts/cluster-hoprd/Chart.yaml +++ b/charts/cluster-hoprd/Chart.yaml @@ -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" diff --git a/charts/cluster-hoprd/templates/cluster-hoprd.yaml b/charts/cluster-hoprd/templates/cluster-hoprd.yaml index f30d958..deb50ae 100644 --- a/charts/cluster-hoprd/templates/cluster-hoprd.yaml +++ b/charts/cluster-hoprd/templates/cluster-hoprd.yaml @@ -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 }} \ No newline at end of file diff --git a/charts/cluster-hoprd/values.yaml b/charts/cluster-hoprd/values.yaml index 1b6b883..4fcc24c 100644 --- a/charts/cluster-hoprd/values.yaml +++ b/charts/cluster-hoprd/values.yaml @@ -79,6 +79,11 @@ forceIdentityName: false ## deployment: {} +## +## @param ports_allocation Ports allocation +## +ports_allocation: 10 + service: ## ## @param service.type Service Type diff --git a/charts/hoprd-operator/Chart.yaml b/charts/hoprd-operator/Chart.yaml index f727a7f..cd6ee8e 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.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" diff --git a/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml b/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml index ded5acb..8cefa40 100644 --- a/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml +++ b/charts/hoprd-operator/templates/crd-cluster-hoprd.yaml @@ -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. diff --git a/charts/hoprd-operator/templates/crd-hoprd.yaml b/charts/hoprd-operator/templates/crd-hoprd.yaml index 11c388a..a8da79f 100644 --- a/charts/hoprd-operator/templates/crd-hoprd.yaml +++ b/charts/hoprd-operator/templates/crd-hoprd.yaml @@ -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. diff --git a/charts/hoprd-operator/templates/cronjob-fast-sync.yaml b/charts/hoprd-operator/templates/cronjob-fast-sync.yaml index ad99dd5..f2426f2 100644 --- a/charts/hoprd-operator/templates/cronjob-fast-sync.yaml +++ b/charts/hoprd-operator/templates/cronjob-fast-sync.yaml @@ -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 diff --git a/src/constants.rs b/src/constants.rs index efd70ca..f33ee0f 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -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)] diff --git a/src/hoprd/hoprd_deployment.rs b/src/hoprd/hoprd_deployment.rs index de2db5d..cc9fe5f 100644 --- a/src/hoprd/hoprd_deployment.rs +++ b/src/hoprd/hoprd_deployment.rs @@ -41,6 +41,7 @@ pub async fn create_deployment(context_data: Arc, hoprd: &Hoprd, id let name: String = hoprd.name_any(); let owner_references: Option> = 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 = 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()); @@ -65,7 +66,7 @@ pub async fn create_deployment(context_data: Arc, 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() }; @@ -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!( "{}/{}:{}", @@ -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), @@ -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() }]), @@ -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, @@ -198,7 +209,8 @@ pub async fn modify_deployment(context_data: Arc, 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(()) @@ -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 } @@ -560,5 +560,12 @@ fn build_default_env_var(hoprd_host: &String) -> Vec { 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() + }, + + ] }