From 81adc60eea020a01edb2943f4f53b8148a47af4a Mon Sep 17 00:00:00 2001 From: peternashaat Date: Thu, 30 Oct 2025 13:20:12 +0000 Subject: [PATCH] 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. --- .../k8s/cryptpad/cryptpad_actions.v | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/installers/k8s/cryptpad/cryptpad_actions.v b/lib/installers/k8s/cryptpad/cryptpad_actions.v index 92798562..040d4c88 100644 --- a/lib/installers/k8s/cryptpad/cryptpad_actions.v +++ b/lib/installers/k8s/cryptpad/cryptpad_actions.v @@ -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 {