Skip to content

Commit eb8cac6

Browse files
authored
Merge pull request #126 from mattfenwick/cleanup
Refactoring
2 parents a135d68 + 6772f1f commit eb8cac6

37 files changed

+343
-213
lines changed

.github/workflows/kind_antrea.yml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v2
20+
- name: Set up Go
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.18
2024
- name: Run Cyclonus
2125
working-directory: hack/kind
2226
run: CNI=antrea RUN_FROM_SOURCE=true FROM_SOURCE_ARGS="${{ github.event.inputs.cyclonus_args }}" ./run-cyclonus.sh

.github/workflows/kind_calico.yml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v2
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: 1.18
1923
- name: Run Cyclonus
2024
working-directory: hack/kind
2125
run: CNI=calico RUN_FROM_SOURCE=true FROM_SOURCE_ARGS="${{ github.event.inputs.cyclonus_args }}" ./run-cyclonus.sh

.github/workflows/kind_cilium.yml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v2
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: 1.18
1923
- name: Run Cyclonus
2024
working-directory: hack/kind
2125
run: CNI=cilium RUN_FROM_SOURCE=true FROM_SOURCE_ARGS="${{ github.event.inputs.cyclonus_args }}" ./run-cyclonus.sh

.github/workflows/kind_ovn.yml

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- uses: actions/checkout@v2
21+
- name: Set up Go
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: 1.18
2125
- name: Run Cyclonus
2226
working-directory: hack/kind
2327
run: CNI=ovn-kubernetes RUN_FROM_SOURCE=true FROM_SOURCE_ARGS="${{ github.event.inputs.cyclonus_args }}" ./run-cyclonus.sh

examples/run.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -euo pipefail
44
set -xv
55

66
# run all 5
7+
printf "\n\n********************** run all 5 modes **************************\n\n"
78
go run ../cmd/cyclonus/main.go analyze \
89
--use-example-policies \
910
--mode explain,lint,query-target,query-traffic,probe \
@@ -12,29 +13,34 @@ go run ../cmd/cyclonus/main.go analyze \
1213
--probe-path ./probe-example.json
1314

1415
# run just the explainer
16+
printf "\n\n********************** run just the explainer **************************\n\n"
1517
go run ../cmd/cyclonus/main.go analyze \
1618
--mode explain \
1719
--policy-path ../networkpolicies/simple-example/
1820

1921
# run just the targets
22+
printf "\n\n********************** run just the targets **************************\n\n"
2023
go run ../cmd/cyclonus/main.go analyze \
2124
--mode query-target \
2225
--policy-path ../networkpolicies/simple-example/ \
2326
--target-pod-path ./targets.json
2427

2528
# run just the traffic
29+
printf "\n\n********************** run just the traffic **************************\n\n"
2630
go run ../cmd/cyclonus/main.go analyze \
2731
--mode query-traffic \
2832
--policy-path ../networkpolicies/simple-example/ \
2933
--traffic-path ./traffic.json
3034

3135
# run just the probe
36+
printf "\n\n********************** run just the probe **************************\n\n"
3237
go run ../cmd/cyclonus/main.go analyze \
3338
--mode probe \
3439
--policy-path ../networkpolicies/simple-example/ \
3540
--probe-path ./probe.json
3641

3742
# run just the linter
43+
printf "\n\n********************** run just the linter **************************\n\n"
3844
go run ../cmd/cyclonus/main.go analyze \
3945
--mode lint \
40-
--policy-path ../networkpolicies/simple-example
46+
--policy-path ../networkpolicies/simple-example

go.mod

+7-10
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ go 1.18
55
require (
66
github.com/go-resty/resty/v2 v2.5.0
77
github.com/jstemmer/go-junit-report v0.9.1
8+
github.com/mattfenwick/collections v0.0.8
89
github.com/olekukonko/tablewriter v0.0.4
9-
github.com/onsi/ginkgo v1.14.0
10-
github.com/onsi/gomega v1.10.1
10+
github.com/onsi/ginkgo/v2 v2.1.4
11+
github.com/onsi/gomega v1.19.0
1112
github.com/pkg/errors v0.9.1
12-
github.com/sirupsen/logrus v1.6.0
13+
github.com/sirupsen/logrus v1.8.1
1314
github.com/spf13/cobra v1.0.0
15+
golang.org/x/exp v0.0.0-20220706164943-b4a6d9510983
1416
k8s.io/api v0.24.2
1517
k8s.io/apimachinery v0.24.2
1618
k8s.io/client-go v0.24.2
@@ -23,7 +25,6 @@ require (
2325
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
2426
github.com/davecgh/go-spew v1.1.1 // indirect
2527
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
26-
github.com/fsnotify/fsnotify v1.4.9 // indirect
2728
github.com/go-logr/logr v1.2.0 // indirect
2829
github.com/go-openapi/jsonpointer v0.19.5 // indirect
2930
github.com/go-openapi/jsonreference v0.19.5 // indirect
@@ -36,26 +37,22 @@ require (
3637
github.com/inconshreveable/mousetrap v1.0.0 // indirect
3738
github.com/josharian/intern v1.0.0 // indirect
3839
github.com/json-iterator/go v1.1.12 // indirect
39-
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
4040
github.com/mailru/easyjson v0.7.6 // indirect
4141
github.com/mattn/go-runewidth v0.0.7 // indirect
4242
github.com/moby/spdystream v0.2.0 // indirect
4343
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4444
github.com/modern-go/reflect2 v1.0.2 // indirect
4545
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
46-
github.com/nxadm/tail v1.4.4 // indirect
4746
github.com/spf13/pflag v1.0.5 // indirect
48-
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
47+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
4948
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
50-
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
49+
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect
5150
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
5251
golang.org/x/text v0.3.7 // indirect
5352
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
54-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
5553
google.golang.org/appengine v1.6.7 // indirect
5654
google.golang.org/protobuf v1.27.1 // indirect
5755
gopkg.in/inf.v0 v0.9.1 // indirect
58-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
5956
gopkg.in/yaml.v2 v2.4.0 // indirect
6057
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
6158
k8s.io/klog/v2 v2.60.1 // indirect

go.sum

+16-10
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
174174
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
175175
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
176176
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
177-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
178177
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
178+
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
179179
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
180180
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
181181
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@@ -229,8 +229,6 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
229229
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
230230
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
231231
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
232-
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
233-
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
234232
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
235233
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
236234
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -243,6 +241,8 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
243241
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
244242
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
245243
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
244+
github.com/mattfenwick/collections v0.0.8 h1:9U+ZYBdZZIS7sC42bSV0nymyTzFjsLKNuQedUi6jiV8=
245+
github.com/mattfenwick/collections v0.0.8/go.mod h1:6JmZGWNsbA4g6OzJQGAOTalNWMPghEOl1q4abMZAJSQ=
246246
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
247247
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
248248
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -273,10 +273,13 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
273273
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
274274
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
275275
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
276+
github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY=
277+
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
276278
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
277279
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
278-
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
279280
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
281+
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
282+
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
280283
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
281284
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
282285
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -299,8 +302,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
299302
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
300303
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
301304
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
302-
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
303-
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
305+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
306+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
304307
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
305308
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
306309
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
@@ -361,6 +364,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
361364
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
362365
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
363366
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
367+
golang.org/x/exp v0.0.0-20220706164943-b4a6d9510983 h1:sUweFwmLOje8KNfXAVqGGAsmgJ/F8jJ6wBLJDt4BTKY=
368+
golang.org/x/exp v0.0.0-20220706164943-b4a6d9510983/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
364369
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
365370
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
366371
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -427,8 +432,9 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
427432
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
428433
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
429434
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
430-
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
431435
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
436+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
437+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
432438
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
433439
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
434440
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -461,7 +467,6 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
461467
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
462468
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
463469
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
464-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
465470
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
466471
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
467472
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -470,6 +475,7 @@ golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7w
470475
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
471476
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
472477
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
478+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
473479
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
474480
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
475481
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -502,8 +508,9 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
502508
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
503509
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
504510
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
505-
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
506511
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
512+
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d h1:/m5NbqQelATgoSPVC2Z23sR4kVNokFwDDyWh/3rGY+I=
513+
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
507514
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
508515
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
509516
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -576,7 +583,6 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
576583
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
577584
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
578585
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
579-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
580586
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
581587
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
582588
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=

pkg/cli/analyze.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package cli
22

33
import (
4-
"encoding/json"
54
"fmt"
5+
collections "github.com/mattfenwick/collections/pkg"
66
"github.com/mattfenwick/cyclonus/pkg/connectivity/probe"
77
"github.com/mattfenwick/cyclonus/pkg/generator"
88
"github.com/mattfenwick/cyclonus/pkg/linter"
9-
"io/ioutil"
109
"strings"
1110

1211
"github.com/mattfenwick/cyclonus/pkg/kube"
@@ -123,10 +122,13 @@ func RunAnalyzeCommand(args *AnalyzeArgs) {
123122
for _, mode := range args.Modes {
124123
switch mode {
125124
case ParseMode:
125+
fmt.Println("parsed policies:")
126126
ParsePolicies(kubePolicies)
127127
case ExplainMode:
128+
fmt.Println("explained policies:")
128129
ExplainPolicies(policies)
129130
case LintMode:
131+
fmt.Println("policy lint:")
130132
Lint(kubePolicies)
131133
case QueryTargetMode:
132134
pods := make([]*QueryTargetPod, len(kubePods))
@@ -136,10 +138,13 @@ func RunAnalyzeCommand(args *AnalyzeArgs) {
136138
Labels: p.Labels,
137139
}
138140
}
141+
fmt.Println("query target:")
139142
QueryTargets(policies, args.TargetPodPath, pods)
140143
case QueryTrafficMode:
144+
fmt.Println("query traffic:")
141145
QueryTraffic(policies, args.TrafficPath)
142146
case ProbeMode:
147+
fmt.Println("probe:")
143148
ProbeSyntheticConnectivity(policies, args.ProbePath, kubePods, kubeNamespaces)
144149
default:
145150
panic(errors.Errorf("unrecognized mode %s", mode))
@@ -156,7 +161,7 @@ func ExplainPolicies(explainedPolicies *matcher.Policy) {
156161
}
157162

158163
func Lint(kubePolicies []*networkingv1.NetworkPolicy) {
159-
warnings := linter.Lint(kubePolicies, map[linter.Check]bool{})
164+
warnings := linter.Lint(kubePolicies, collections.NewSet[linter.Check](nil))
160165
fmt.Println(linter.WarningsTable(warnings))
161166
}
162167

@@ -169,12 +174,9 @@ type QueryTargetPod struct {
169174

170175
func QueryTargets(explainedPolicies *matcher.Policy, podPath string, pods []*QueryTargetPod) {
171176
if podPath != "" {
172-
var podsFromFile []*QueryTargetPod
173-
bs, err := ioutil.ReadFile(podPath)
177+
podsFromFile, err := utils.ParseJsonFromFile[[]*QueryTargetPod](podPath)
174178
utils.DoOrDie(err)
175-
err = json.Unmarshal(bs, &podsFromFile)
176-
utils.DoOrDie(err)
177-
pods = append(pods, podsFromFile...)
179+
pods = append(pods, *podsFromFile...)
178180
}
179181

180182
for _, pod := range pods {
@@ -207,16 +209,13 @@ func QueryTargetHelper(policies *matcher.Policy, pod *QueryTargetPod) (*matcher.
207209
}
208210

209211
func QueryTraffic(explainedPolicies *matcher.Policy, trafficPath string) {
210-
var allTraffics []*matcher.Traffic
211212
if trafficPath == "" {
212213
logrus.Fatalf("%+v", errors.Errorf("path to traffic file required for QueryTraffic command"))
213214
}
214-
allTrafficBytes, err := ioutil.ReadFile(trafficPath)
215-
utils.DoOrDie(err)
216-
err = json.Unmarshal(allTrafficBytes, &allTraffics)
215+
allTraffics, err := utils.ParseJsonFromFile[[]*matcher.Traffic](trafficPath)
217216
utils.DoOrDie(err)
218217

219-
for _, traffic := range allTraffics {
218+
for _, traffic := range *allTraffics {
220219
fmt.Printf("Traffic:\n%s\n", traffic.Table())
221220

222221
result := explainedPolicies.IsTrafficAllowed(traffic)
@@ -231,11 +230,8 @@ type SyntheticProbeConnectivityConfig struct {
231230

232231
func ProbeSyntheticConnectivity(explainedPolicies *matcher.Policy, modelPath string, kubePods []v1.Pod, kubeNamespaces []v1.Namespace) {
233232
if modelPath != "" {
234-
bs, err := ioutil.ReadFile(modelPath)
235-
utils.DoOrDie(errors.Wrapf(err, "unable to read file %s", modelPath))
236-
config := &SyntheticProbeConnectivityConfig{}
237-
err = json.Unmarshal(bs, &config)
238-
utils.DoOrDie(errors.Wrapf(err, "unable to unmarshal json"))
233+
config, err := utils.ParseJsonFromFile[SyntheticProbeConnectivityConfig](modelPath)
234+
utils.DoOrDie(err)
239235

240236
jobBuilder := &probe.JobBuilder{TimeoutSeconds: 10}
241237

0 commit comments

Comments
 (0)