diff --git a/internal/controller/ambient_utils.go b/internal/controller/ambient_utils.go index 0819aed..2d043e3 100644 --- a/internal/controller/ambient_utils.go +++ b/internal/controller/ambient_utils.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "regexp" + "time" corev1 "k8s.io/api/core/v1" // appsv1 "k8s.io/api/apps/v1" @@ -96,12 +97,16 @@ func attach_volume_to_waypoint(service_name, waypoint_name string) { pvcName := service_name + "-pvc" mountPath := "/data" + maxAttempts := 20 + // Retry on failure (sometimes deployment changes wjile updating) - for { + for attempts := 0; attempts < maxAttempts; attempts++ { // Get the specified deployment deployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), deploymentName, metav1.GetOptions{}) if err != nil { - panic(err.Error()) + fmt.Printf("Attempt %d: failed to get deployment: %v\n", attempts+1, err) + time.Sleep(2 * time.Second) // Wait before retrying + continue } // Define the volume and volume mount diff --git a/internal/controller/appnetconfig_controller.go b/internal/controller/appnetconfig_controller.go index 34f75dd..b128b68 100644 --- a/internal/controller/appnetconfig_controller.go +++ b/internal/controller/appnetconfig_controller.go @@ -141,13 +141,15 @@ func (r *AppNetConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request attach_volume_to_waypoint(server_service, waypoint_name) } - attach_cmd := exec.Command("kubectl", "apply", "-f", strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/APP-deploy/attach_all_elements.yml"), "APP", app_name)) - attach_output, attach_err := attach_cmd.CombinedOutput() + if backend != "grpc" { + attach_cmd := exec.Command("kubectl", "apply", "-f", strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/APP-deploy/attach_all_elements.yml"), "APP", app_name)) + attach_output, attach_err := attach_cmd.CombinedOutput() - // Check if there was an error running the command - if attach_err != nil { - l.Info("Reconciling AppNetConfig", "Error running kubectl: %s\nOutput:\n%s\n", kubectl_err, string(attach_output)) - return ctrl.Result{}, client.IgnoreNotFound(err) + // Check if there was an error running the command + if attach_err != nil { + l.Info("Reconciling AppNetConfig", "Error running kubectl: %s\nOutput:\n%s\n", kubectl_err, string(attach_output)) + return ctrl.Result{}, client.IgnoreNotFound(err) + } } l.Info("All elemenets deployed - Reconciliation finished!")