Skip to content

Commit

Permalink
Merge pull request #316 from grafana/unify-disruptor-validations
Browse files Browse the repository at this point in the history
Apply fault injection validations uniformly
  • Loading branch information
pablochacin authored Aug 25, 2023
2 parents c2244fc + da4c87c commit b50ce14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/disruptors/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func (d *podDisruptor) InjectGrpcFaults(
return VisitCommands{}, fmt.Errorf("pod %q does not expose port %d", pod.Name, fault.Port)
}

if utils.HasHostNetwork(pod) {
return VisitCommands{}, fmt.Errorf("pod %q cannot be safely injected as it has hostNetwork set to true", pod.Name)
}

targetAddress, err := utils.PodIP(pod)
if err != nil {
return VisitCommands{}, err
Expand Down
15 changes: 9 additions & 6 deletions pkg/disruptors/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ func (d *serviceDisruptor) InjectHTTPFaults(
return VisitCommands{}, fmt.Errorf("pod %q cannot be safely injected as it has hostNetwork set to true", pod.Name)
}

// copy fault to change target port for the pod
podFault := fault
podFault.Port = port

targetAddress, err := utils.PodIP(pod)
if err != nil {
return VisitCommands{}, err
}

// copy fault to change target port for the pod
podFault := fault
podFault.Port = port
visitCommands := VisitCommands{
Exec: buildHTTPFaultCmd(targetAddress, podFault, duration, options),
Cleanup: buildCleanupCmd(),
Expand All @@ -125,14 +124,18 @@ func (d *serviceDisruptor) InjectGrpcFaults(
return VisitCommands{}, err
}

podFault := fault
podFault.Port = port
if utils.HasHostNetwork(pod) {
return VisitCommands{}, fmt.Errorf("pod %q cannot be safely injected as it has hostNetwork set to true", pod.Name)
}

targetAddress, err := utils.PodIP(pod)
if err != nil {
return VisitCommands{}, err
}

// copy fault to change target port for the pod
podFault := fault
podFault.Port = port
visitCommands := VisitCommands{
Exec: buildGrpcFaultCmd(targetAddress, podFault, duration, options),
Cleanup: buildCleanupCmd(),
Expand Down

0 comments on commit b50ce14

Please sign in to comment.