feat(cryptpad): Use constants for deployment retry logic

Refactor the installer to use global constants for the maximum number of retries and the check interval when verifying deployments.

This change removes hardcoded values from the FQDN and deployment status checks, improving maintainability and centralizing configuration.
This commit is contained in:
peternashaat
2025-10-30 13:20:12 +00:00
parent 82d37374d8
commit 81adc60eea

View File

@@ -10,6 +10,9 @@ import os
import strings
import time
const max_deployment_retries = 30
const deployment_check_interval_seconds = 2
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
// We don't have a long-running process to manage with startupmanager for this installer,
// but we'll keep the function for consistency.
@@ -135,8 +138,8 @@ fn install() ! {
console.print_info('Gateway YAML file applied successfully.')
// 5. Verify TFGW deployments
verify_tfgw_deployment(tfgw_name: 'cryptpad-main', namespace: installer.namespace, retry: 30)!
verify_tfgw_deployment(tfgw_name: 'cryptpad-sandbox', namespace: installer.namespace, retry: 30)!
verify_tfgw_deployment(tfgw_name: 'cryptpad-main', namespace: installer.namespace)!
verify_tfgw_deployment(tfgw_name: 'cryptpad-sandbox', namespace: installer.namespace)!
// 6. Apply Cryptpad YAML
console.print_info('Applying Cryptpad YAML file to the cluster...')
@@ -149,13 +152,13 @@ fn install() ! {
// 7. Verify deployment status
console.print_info('Verifying deployment status...')
mut is_running := false
for i in 0 .. 30 {
for i in 0 .. max_deployment_retries {
if running()! {
is_running = true
break
}
console.print_info('Waiting for CryptPad deployment to be ready... (${i + 1}/30)')
time.sleep(2 * time.second)
console.print_info('Waiting for CryptPad deployment to be ready... (${i + 1}/${max_deployment_retries})')
time.sleep(deployment_check_interval_seconds * time.second)
}
if is_running {
@@ -171,14 +174,13 @@ struct VerifyTfgwDeployment {
pub mut:
tfgw_name string // tfgw serivce generating the FQDN
namespace string // namespace name for cryptpad deployments/services
retry int // number of retries
}
// Function for verifying the generating of of the FQDN using tfgw crd
fn verify_tfgw_deployment(args VerifyTfgwDeployment) ! {
console.print_info('Verifying TFGW deployment for ${args.tfgw_name}...')
mut is_fqdn_generated := false
for i in 0 .. 30 {
for i in 0 .. max_deployment_retries {
res := osal.exec(
cmd: 'kubectl get tfgw ${args.tfgw_name} -n ${args.namespace} -o jsonpath="{.status.fqdn}"'
ignore_error: true
@@ -187,8 +189,8 @@ fn verify_tfgw_deployment(args VerifyTfgwDeployment) ! {
is_fqdn_generated = true
break
}
console.print_info('Waiting for FQDN to be generated for ${args.tfgw_name}... (${i + 1}/30)')
time.sleep(2 * time.second)
console.print_info('Waiting for FQDN to be generated for ${args.tfgw_name}... (${i + 1}/${max_deployment_retries})')
time.sleep(deployment_check_interval_seconds * time.second)
}
if !is_fqdn_generated {