Skip to content

Commit

Permalink
update controller for ambient
Browse files Browse the repository at this point in the history
  • Loading branch information
Romero027 committed Jun 4, 2024
1 parent 564cd12 commit 280aebe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 7 additions & 2 deletions internal/controller/ambient_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"regexp"
"time"

corev1 "k8s.io/api/core/v1"
// appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions internal/controller/appnetconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down

0 comments on commit 280aebe

Please sign in to comment.