Skip to content

Commit

Permalink
Reflect comments
Browse files Browse the repository at this point in the history
Signed-off-by: Daichi Sakaue <[email protected]>
  • Loading branch information
yokaze committed Nov 21, 2024
1 parent 45ac9c4 commit 28aaeaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions cmd/npv/app/manifest_blast.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ var manifestBlastCmd = &cobra.Command{
}

type manifestBlastEntry struct {
Direction string `json:"direction"`
Side string `json:"side"`
Namespace string `json:"namespace"`
Name string `json:"name"`
}

func lessManifestBlastEntry(x, y *manifestBlastEntry) bool {
ret := strings.Compare(x.Direction, y.Direction)
ret := strings.Compare(x.Side, y.Side)
if ret == 0 {
ret = strings.Compare(x.Namespace, y.Namespace)
}
Expand Down Expand Up @@ -85,22 +85,22 @@ func runManifestBlast(ctx context.Context, w io.Writer) error {

for _, ep := range idEndpoints[int(fromIdentity)] {
entry := manifestBlastEntry{
Direction: directionEgress,
Side: "From",
Namespace: ep.GetNamespace(),
Name: ep.GetName(),
}
arr = append(arr, entry)
}
for _, ep := range idEndpoints[int(toIdentity)] {
entry := manifestBlastEntry{
Direction: directionIngress,
Side: "To",
Namespace: ep.GetNamespace(),
Name: ep.GetName(),
}
arr = append(arr, entry)
}
return writeSimpleOrJson(w, arr, []string{"DIRECTION", "NAMESPACE", "NAME"}, len(arr), func(index int) []any {
return writeSimpleOrJson(w, arr, []string{"SIDE", "NAMESPACE", "NAME"}, len(arr), func(index int) []any {
ep := arr[index]
return []any{ep.Direction, ep.Namespace, ep.Name}
return []any{ep.Side, ep.Namespace, ep.Name}
})
}
8 changes: 4 additions & 4 deletions e2e/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ spec:
}

func testManifestBlast() {
expected := `Egress,test,self
Ingress,test,l3-ingress-explicit-allow-all
Ingress,test,l3-ingress-explicit-allow-all`
expected := `From,test,self
To,test,l3-ingress-explicit-allow-all
To,test,l3-ingress-explicit-allow-all`

It("should show blast radius", func() {
from := "--from=test/" + onePodByLabelSelector(Default, "test", "test=self")
Expand All @@ -141,7 +141,7 @@ Ingress,test,l3-ingress-explicit-allow-all`
// remove hash suffix from pod names
result = jqSafe(Default, result, "-r", `[.[] | .name = (.name | split("-") | .[0:5] | join("-"))]`)
result = jqSafe(Default, result, "-r", `[.[] | .name = (.name | if startswith("self") then "self" else . end)]`)
result = jqSafe(Default, result, "-r", `.[] | [.direction, .namespace, .name] | @csv`)
result = jqSafe(Default, result, "-r", `.[] | [.side, .namespace, .name] | @csv`)
resultString := strings.Replace(string(result), `"`, "", -1)
Expect(resultString).To(Equal(expected), "compare failed.\nactual: %s\nexpected: %s", resultString, expected)
})
Expand Down

0 comments on commit 28aaeaa

Please sign in to comment.