Skip to content

Commit

Permalink
fix ambient and grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Romero027 committed Oct 24, 2024
1 parent b573de1 commit 9cb9a1d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
15 changes: 7 additions & 8 deletions config/samples/echo/sample_echo_ambient.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ kind: AppNetConfig
metadata:
name: sample-echo-ambient # Name of the AppNetConfig
spec:
backend: ambient # Name of the backend (sidecar/ambient/grpc)
processors: # Name of the backend (sidecar/ambient/grpc)
- ambient
appName: echo # Name of the application
clientService: frontend # Name of the client service (must be a valid service in the same namespace as the AppNetConfig)
serverService: server # Name of the server service (must be a valid service in the same namespace as the AppNetConfig)
method: echo # Name of the RPC method (defined in the proto file)
appManifestFile: <APPNET_DIR_PATH>/config/samples/echo/echo.yaml # Path to the application manifest file
clientChain:
- name: fault # Name of the first element in the client chain
anyChain:
- name: fault # Name of the first element in the any(unconstraint) chain
file: <APPNET_DIR_PATH>/config/samples/echo/fault.appnet # Path to the fault injection element file
- name: logging # Name of the second element in the client chain
- name: logging # Name of the second element
file: <APPNET_DIR_PATH>/config/samples/echo/logging.appnet # Path to the logging element file
serverChain:
- name: firewall # Name of the first element in the server chain
- name: firewall # Name of the third element
file: <APPNET_DIR_PATH>/config/samples/echo/firewall.appnet # Path to the firewall element file
anyChain:
- name: metrics # Name of the first element in the any(unconstraint) chain
- name: metrics # Name of the last element
file: <APPNET_DIR_PATH>/config/samples/echo/metrics.appnet # Path to the metrics element file
proto: <APPNET_DIR_PATH>/config/samples/echo/echo.proto # Path to the protobuf definition of client service to server service communication
3 changes: 2 additions & 1 deletion config/samples/echo/sample_echo_grpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ kind: AppNetConfig
metadata:
name: sample-echo-grpc # Name of the AppNetConfig
spec:
backend: grpc # Name of the backend (sidecar/ambient/grpc)
processors: # Name of the backend (sidecar/ambient/grpc)
- grpc
appName: echo # Name of the application
clientService: frontend # Name of the client service (must be a valid service in the same namespace as the AppNetConfig)
serverService: server # Name of the server service (must be a valid service in the same namespace as the AppNetConfig)
Expand Down
3 changes: 2 additions & 1 deletion config/samples/echo/sample_echo_sidecar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ kind: AppNetConfig
metadata:
name: sample-echo-sidecar # Name of the AppNetConfig
spec:
backend: sidecar # Name of the backend (sidecar/ambient/grpc)
processors: # Name of the backend (sidecar/ambient/grpc)
- sidecar
appName: echo # Name of the application
clientService: frontend # Name of the client service (must be a valid service in the same namespace as the AppNetConfig)
serverService: server # Name of the server service (must be a valid service in the same namespace as the AppNetConfig)
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/ambient_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func attach_volume_to_waypoint(service_name, waypoint_name string) {
// Set deployment details
namespace := "default"
deploymentName := waypoint_name
pvcName := service_name + "-pvc"
mountPath := "/data"
pvcName := service_name + "-appnet-pvc"
mountPath := "/appnet"

maxAttempts := 20

Expand Down
55 changes: 32 additions & 23 deletions internal/controller/appnetconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,19 @@ func (r *AppNetConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request

l.Info("All elements compiled successfully - deploying to envoy")

attach_cmd := exec.Command("bash", strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/sidecar-ambient-attach/attach.sh"), "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", attach_err, string(attach_output))
return ctrl.Result{}, client.IgnoreNotFound(err)
attachPath := filepath.Join(compilerDir, "graph/generated/sidecar-ambient-attach/attach.sh")
attachPath = strings.ReplaceAll(attachPath, "APP", app_name)

// Check if the file exists
if _, err := os.Stat(attachPath); err == nil {
attach_cmd := exec.Command("bash", attachPath)
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", attach_err, string(attach_output))
return ctrl.Result{}, client.IgnoreNotFound(err)
}
}

kubectl_cmd := exec.Command("kubectl", "apply", "-Rf", strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/APP-deploy"), "APP", app_name))
Expand All @@ -146,22 +152,25 @@ func (r *AppNetConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request

// Deploy waypoint proxies & Make sure the waypoints are only applied once
// TODO(XZ): This is a temporary fix for the waypoint.
// if backend == "ambient" && currentVersion == 1 {
// // XZ: Temp hack to wait for all pods running
// waypoint_cmd := exec.Command("bash", strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/APP-deploy/waypoint_create.sh"), "APP", app_name))
// waypoint_output, waypoint_err := waypoint_cmd.CombinedOutput()

// // Check if there was an error running the command
// if waypoint_err != nil {
// l.Info("Reconciling AppNetConfig", "Error running istioctl waypoint: %s\nOutput:\n%s\n", waypoint_err, string(waypoint_output))
// return ctrl.Result{}, client.IgnoreNotFound(err)
// }

// // Attach volume to waypoint
// waypoint_name := find_waypoint_name(strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/APP-deploy/waypoint_create.sh"), "APP", app_name))
// l.Info("Reconciling AppNetConfig", server_service, waypoint_name)
// attach_volume_to_waypoint(server_service, waypoint_name)
// }
waypointPath := filepath.Join(compilerDir, "graph/generated/APP-deploy/waypoint_create.sh")
waypointPath = strings.ReplaceAll(waypointPath, "APP", app_name)

// Check if the file exists
if _, err := os.Stat(waypointPath); err == nil && currentVersion == 1 {
waypoint_cmd := exec.Command("bash", waypointPath)
waypoint_output, waypoint_err := waypoint_cmd.CombinedOutput()

// Check if there was an error running the command
if waypoint_err != nil {
l.Info("Reconciling AppNetConfig", "Error running istioctl waypoint: %s\nOutput:\n%s\n", waypoint_err, string(waypoint_output))
return ctrl.Result{}, client.IgnoreNotFound(err)
}

// Attach volume to waypoint
waypoint_name := find_waypoint_name(strings.ReplaceAll(filepath.Join(compilerDir, "graph/generated/APP-deploy/waypoint_create.sh"), "APP", app_name))
l.Info("Reconciling AppNetConfig", server_service, waypoint_name)
attach_volume_to_waypoint(server_service, waypoint_name)
}

l.Info("All elemenets deployed - Reconciliation finished!")

Expand Down
13 changes: 6 additions & 7 deletions internal/controller/spec_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type EdgeElementItem struct {
ProtoModName string `yaml:"proto_mod_name"`
ProtoModLocation string `yaml:"proto_mod_location"`
Upgrade bool `yaml:"upgrade"`
Processors []string `yaml:"processors"`
Processor []string `yaml:"processor"`
}

type PairElementItem struct {
Expand All @@ -49,19 +49,18 @@ func ConvertToAppNetSpec(appName, appManifestFile, clientService, serverService,
Link: make(map[string][]PairElementItem),
}

position := ""
if len(clientChain) > 0 {
for _, element := range clientChain {
appManifest.Edge[clientServerTag] = append(appManifest.Edge[clientServerTag], EdgeElementItem{
Method: method,
Name: element.Name,
Position: position,
Position: "client",
Proto: proto,
Path: element.File,
ProtoModName: protoModName,
ProtoModLocation: protoModLocation,
Upgrade: element.Upgrade,
Processors: processors,
Processor: processors,
})
}
}
Expand All @@ -77,7 +76,7 @@ func ConvertToAppNetSpec(appName, appManifestFile, clientService, serverService,
ProtoModName: protoModName,
ProtoModLocation: protoModLocation,
Upgrade: element.Upgrade,
Processors: processors,
Processor: processors,
})
}
}
Expand All @@ -87,13 +86,13 @@ func ConvertToAppNetSpec(appName, appManifestFile, clientService, serverService,
appManifest.Edge[clientServerTag] = append(appManifest.Edge[clientServerTag], EdgeElementItem{
Method: method,
Name: element.Name,
Position: position,
Position: "any",
Proto: proto,
Path: element.File,
ProtoModName: protoModName,
ProtoModLocation: protoModLocation,
Upgrade: element.Upgrade,
Processors: processors,
Processor: processors,
})
}
}
Expand Down

0 comments on commit 9cb9a1d

Please sign in to comment.