Skip to content

Commit f07635b

Browse files
authored
Improve output for unknown kinds (#94)
* Adding bookinfo test * Avoid matching ServiceAccount to Service * provide file context to "skipping object" message * "go test" to test all packages * No automatic releases (needs too much permissions) * Update workflow and job names Signed-off-by: Ziv Nevo <[email protected]>
1 parent 654eb28 commit f07635b

19 files changed

+1360
-20
lines changed

.github/workflows/go-build.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@ jobs:
2727
run: go build --tags static_all -v -o ./bin/net-top ./cmd/nettop
2828

2929
- name: Test
30-
run: |
31-
go test -v ./pkg/controller
32-
go test -v ./cmd/nettop/
33-
30+
run: go test -v ./...

.github/workflows/make-release.yaml

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create docker release and github release
1+
name: Create docker release and publish to pkg.go.dev
22

33
on:
44
push:
@@ -10,7 +10,7 @@ permissions:
1010

1111
jobs:
1212
push_to_registry:
13-
name: Publish a new Docker image and create a GitHub release
13+
name: Publish a new Docker image and publish a new version in pkg.go.dev
1414
runs-on: ubuntu-latest
1515
permissions:
1616
packages: write
@@ -32,18 +32,6 @@ jobs:
3232
push: true
3333
tags: ghcr.io/np-guard/net-top-analyzer:${{ github.ref_name }}
3434

35-
- name: Create a github release
36-
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
with:
40-
tag_name: ${{ github.ref_name }}
41-
release_name: Release ${{ github.ref_name }}
42-
body: |
43-
Changes in this Release:
44-
draft: false
45-
prerelease: false
46-
4735
- name: Set up Go
4836
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f
4937
with:

cmd/nettop/main_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func TestNetpolsJsonOutput(t *testing.T) {
7979
tests["guestbook"] = TestDetails{dirPath: filepath.Join(testsDir, "k8s_guestbook"),
8080
outFile: filepath.Join(testsDir, "k8s_guestbook", "output.json"),
8181
expectedOutput: filepath.Join(testsDir, "k8s_guestbook", "expected_netpol_output.json")}
82+
tests["bookinfo"] = TestDetails{dirPath: filepath.Join(testsDir, "bookinfo"),
83+
outFile: filepath.Join(testsDir, "bookinfo", "output.json"),
84+
expectedOutput: filepath.Join(testsDir, "bookinfo", "expected_netpol_output.json")}
8285

8386
for testName, testDetails := range tests {
8487
args := getTestArgs(testDetails.dirPath, testDetails.outFile, true, false, true)

pkg/controller/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
)
2828

2929
var (
30-
acceptedK8sTypesRegex = fmt.Sprintf("(%s|%s|%s|%s|%s|%s|%s|%s|%s|%s)",
30+
acceptedK8sTypesRegex = fmt.Sprintf("(^%s$|^%s$|^%s$|^%s$|^%s$|^%s$|^%s$|^%s$|^%s$|^%s$)",
3131
pod, replicaSet, replicationController, deployment, daemonset, statefulset, job, cronJob, service, configmap)
3232
acceptedK8sTypes = regexp.MustCompile(acceptedK8sTypesRegex)
3333
yamlSuffix = regexp.MustCompile(".ya?ml$")
@@ -138,7 +138,7 @@ func parseK8sYaml(mfp string, stopOn1stErr bool) ([]deployObject, []FileProcessi
138138
continue
139139
}
140140
if !acceptedK8sTypes.MatchString(groupVersionKind.Kind) {
141-
activeLogger.Infof("Skipping object with type: %s", groupVersionKind.Kind)
141+
activeLogger.Infof("in file: %s, document: %d, skipping object with type: %s", mfp, docID, groupVersionKind.Kind)
142142
} else {
143143
d := deployObject{}
144144
d.GroupKind = groupVersionKind.Kind
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
apiVersion: certmanager.k8s.io/v1alpha1
3+
kind: ClusterIssuer
4+
metadata:
5+
name: letsencrypt-staging
6+
namespace: istio-system
7+
spec:
8+
acme:
9+
# The ACME server URL
10+
server: https://acme-staging-v02.api.letsencrypt.org/directory
11+
# Email address used for ACME registration
12+
13+
# Name of a secret used to store the ACME account private key
14+
privateKeySecretRef:
15+
name: letsencrypt-staging
16+
# Enable the HTTP-01 challenge provider
17+
http01: {}
18+
---
19+
apiVersion: certmanager.k8s.io/v1alpha1
20+
kind: Certificate
21+
metadata:
22+
name: istio-ingressgateway-certs
23+
namespace: istio-system
24+
spec:
25+
secretName: istio-ingressgateway-certs
26+
issuerRef:
27+
name: letsencrypt-staging
28+
kind: ClusterIssuer
29+
commonName: bookinfo.example.com
30+
dnsNames:
31+
- bookinfo.example.com
32+
acme:
33+
config:
34+
- http01:
35+
ingressClass: none
36+
domains:
37+
- bookinfo.example.com

tests/bookinfo/bookinfo-db.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright Istio Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: Service
17+
metadata:
18+
name: mongodb
19+
labels:
20+
app: mongodb
21+
service: mongodb
22+
spec:
23+
ports:
24+
- port: 27017
25+
name: mongo
26+
selector:
27+
app: mongodb
28+
---
29+
apiVersion: apps/v1
30+
kind: Deployment
31+
metadata:
32+
name: mongodb-v1
33+
labels:
34+
app: mongodb
35+
version: v1
36+
spec:
37+
replicas: 1
38+
selector:
39+
matchLabels:
40+
app: mongodb
41+
version: v1
42+
template:
43+
metadata:
44+
labels:
45+
app: mongodb
46+
version: v1
47+
spec:
48+
containers:
49+
- name: mongodb
50+
image: docker.io/istio/examples-bookinfo-mongodb:1.16.4
51+
imagePullPolicy: IfNotPresent
52+
ports:
53+
- containerPort: 27017
54+
volumeMounts:
55+
- name: data-db
56+
mountPath: /data/db
57+
volumes:
58+
- name: data-db
59+
emptyDir: {}
60+
---
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright Istio Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
##################################################################################################
16+
# Details service v2
17+
##################################################################################################
18+
apiVersion: apps/v1
19+
kind: Deployment
20+
metadata:
21+
name: details-v2
22+
labels:
23+
app: details
24+
version: v2
25+
spec:
26+
replicas: 1
27+
selector:
28+
matchLabels:
29+
app: details
30+
version: v2
31+
template:
32+
metadata:
33+
labels:
34+
app: details
35+
version: v2
36+
spec:
37+
containers:
38+
- name: details
39+
image: docker.io/istio/examples-bookinfo-details-v2:1.16.4
40+
imagePullPolicy: IfNotPresent
41+
ports:
42+
- containerPort: 9080
43+
env:
44+
- name: DO_NOT_ENCRYPT
45+
value: "true"
46+
securityContext:
47+
runAsUser: 1000
48+
---

tests/bookinfo/bookinfo-details.yaml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright Istio Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
##################################################################################################
16+
# Details service
17+
##################################################################################################
18+
apiVersion: v1
19+
kind: Service
20+
metadata:
21+
name: details
22+
labels:
23+
app: details
24+
service: details
25+
spec:
26+
ports:
27+
- port: 9080
28+
name: http
29+
selector:
30+
app: details
31+
---
32+
apiVersion: apps/v1
33+
kind: Deployment
34+
metadata:
35+
name: details-v1
36+
labels:
37+
app: details
38+
version: v1
39+
spec:
40+
replicas: 1
41+
selector:
42+
matchLabels:
43+
app: details
44+
version: v1
45+
template:
46+
metadata:
47+
labels:
48+
app: details
49+
version: v1
50+
spec:
51+
containers:
52+
- name: details
53+
image: docker.io/istio/examples-bookinfo-details-v1:1.16.4
54+
imagePullPolicy: IfNotPresent
55+
ports:
56+
- containerPort: 9080
57+
securityContext:
58+
runAsUser: 1000
59+
---

tests/bookinfo/bookinfo-ingress.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright Istio Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
###########################################################################
16+
# Ingress resource (gateway)
17+
##########################################################################
18+
apiVersion: networking.k8s.io/v1
19+
kind: Ingress
20+
metadata:
21+
name: gateway
22+
annotations:
23+
kubernetes.io/ingress.class: "istio"
24+
spec:
25+
rules:
26+
- http:
27+
paths:
28+
- path: /productpage
29+
pathType: Exact
30+
backend:
31+
service:
32+
name: productpage
33+
port:
34+
number: 9080
35+
- path: /static/
36+
pathType: Prefix
37+
backend:
38+
service:
39+
name: productpage
40+
port:
41+
number: 9080
42+
- path: /login
43+
pathType: Exact
44+
backend:
45+
service:
46+
name: productpage
47+
port:
48+
number: 9080
49+
- path: /logout
50+
pathType: Exact
51+
backend:
52+
service:
53+
name: productpage
54+
port:
55+
number: 9080
56+
- path: /api/v1/products
57+
pathType: Prefix
58+
backend:
59+
service:
60+
name: productpage
61+
port:
62+
number: 9080
63+
---

0 commit comments

Comments
 (0)