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 25, 2024
1 parent 84a05ac commit 768dece
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
38 changes: 19 additions & 19 deletions cmd/npv/app/manifest_blast.go → cmd/npv/app/manifest_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ import (
"github.com/spf13/cobra"
)

var manifestBlastOptions struct {
var manifestRangeOptions struct {
from string
to string
}

func init() {
manifestBlastCmd.Flags().StringVar(&manifestBlastOptions.from, "from", "", "egress pod")
manifestBlastCmd.Flags().StringVar(&manifestBlastOptions.to, "to", "", "ingress pod")
manifestCmd.AddCommand(manifestBlastCmd)
manifestRangeCmd.Flags().StringVar(&manifestRangeOptions.from, "from", "", "egress pod")
manifestRangeCmd.Flags().StringVar(&manifestRangeOptions.to, "to", "", "ingress pod")
manifestCmd.AddCommand(manifestRangeCmd)
}

var manifestBlastCmd = &cobra.Command{
Use: "blast",
Short: "Show blast radius of a generated manifest",
Long: `Show blast radius of a generated manifest`,
var manifestRangeCmd = &cobra.Command{
Use: "range",
Short: "List affected pods of a generated manifest",
Long: `List affected pods of a generated manifest`,

Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return runManifestBlast(context.Background(), cmd.OutOrStdout())
return runManifestRange(context.Background(), cmd.OutOrStdout())
},
}

type manifestBlastEntry struct {
type manifestRangeEntry struct {
Part string `json:"part"`
Namespace string `json:"namespace"`
Name string `json:"name"`
}

func lessManifestBlastEntry(x, y *manifestBlastEntry) bool {
func lessManifestRangeEntry(x, y *manifestRangeEntry) bool {
ret := strings.Compare(x.Part, y.Part)
if ret == 0 {
ret = strings.Compare(x.Namespace, y.Namespace)
Expand All @@ -49,17 +49,17 @@ func lessManifestBlastEntry(x, y *manifestBlastEntry) bool {
return ret < 0
}

func runManifestBlast(ctx context.Context, w io.Writer) error {
if manifestBlastOptions.from == "" || manifestBlastOptions.to == "" {
func runManifestRange(ctx context.Context, w io.Writer) error {
if manifestRangeOptions.from == "" || manifestRangeOptions.to == "" {
return errors.New("--from and --to options are required")
}

from, err := parseNamespacedName(manifestBlastOptions.from)
from, err := parseNamespacedName(manifestRangeOptions.from)
if err != nil {
return errors.New("--from and --to should be specified as NAMESPACE/POD")
}

to, err := parseNamespacedName(manifestBlastOptions.to)
to, err := parseNamespacedName(manifestRangeOptions.to)
if err != nil {
return errors.New("--from and --to should be specified as NAMESPACE/POD")
}
Expand All @@ -84,19 +84,19 @@ func runManifestBlast(ctx context.Context, w io.Writer) error {
return err
}

arr := make([]manifestBlastEntry, 0)
sort.Slice(arr, func(i, j int) bool { return lessManifestBlastEntry(&arr[i], &arr[j]) })
arr := make([]manifestRangeEntry, 0)
sort.Slice(arr, func(i, j int) bool { return lessManifestRangeEntry(&arr[i], &arr[j]) })

for _, ep := range idEndpoints[int(fromIdentity)] {
entry := manifestBlastEntry{
entry := manifestRangeEntry{
Part: "From",
Namespace: ep.GetNamespace(),
Name: ep.GetName(),
}
arr = append(arr, entry)
}
for _, ep := range idEndpoints[int(toIdentity)] {
entry := manifestBlastEntry{
entry := manifestRangeEntry{
Part: "To",
Namespace: ep.GetNamespace(),
Name: ep.GetName(),
Expand Down
6 changes: 3 additions & 3 deletions e2e/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ spec:
})
}

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

It("should show blast radius", func() {
It("should list affected pods", func() {
from := "--from=test/" + onePodByLabelSelector(Default, "test", "test=self")
to := "--to=test/" + onePodByLabelSelector(Default, "test", "test=l3-ingress-explicit-allow-all")
result := runViewerSafe(Default, nil, "manifest", "blast", from, to, "-o=json")
result := runViewerSafe(Default, nil, "manifest", "range", from, to, "-o=json")
// 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)]`)
Expand Down
2 changes: 1 addition & 1 deletion e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func runTest() {
Context("inspect", testInspect)
Context("summary", testSummary)
Context("manifest-generate", testManifestGenerate)
Context("manifest-blast", testManifestBlast)
Context("manifest-range", testManifestRange)
}

0 comments on commit 768dece

Please sign in to comment.