Skip to content

Commit 680a3ea

Browse files
authored
Merge pull request #51 from olivercodes/patch-1
Lint cleanup and cmd/cyclonus fmt fixes
2 parents 7182a2c + 8570569 commit 680a3ea

File tree

9 files changed

+82
-61
lines changed

9 files changed

+82
-61
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ linters:
1515
- govet
1616
- misspell
1717
- exportloopref
18+
- unused
1819
disable:
1920
- scopelint
21+
- deadcode
22+
- structcheck
23+
- varcheck
24+
- rowserrcheck
25+
- sqlclosecheck
2026
disable-all: false
2127
presets:
2228
- bugs

cmd/cyclonus/pkg/cli/analyze.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ func Lint(kubePolicies []*networkingv1.NetworkPolicy) {
166166
}
167167

168168
// QueryTargetPod matches targets; targets exist in only a single namespace and can't be matched by namespace
169-
// label, therefore we match by exact namespace and by pod labels.
169+
//
170+
// label, therefore we match by exact namespace and by pod labels.
170171
type QueryTargetPod struct {
171172
Namespace string
172173
Labels map[string]string

cmd/cyclonus/pkg/connectivity/testcasestate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package connectivity
22

33
import (
4+
"time"
5+
46
"github.com/mattfenwick/cyclonus/pkg/connectivity/probe"
57
"github.com/mattfenwick/cyclonus/pkg/kube"
68
"github.com/pkg/errors"
79
"github.com/sirupsen/logrus"
810
v1 "k8s.io/api/core/v1"
911
networkingv1 "k8s.io/api/networking/v1"
10-
"time"
1112
)
1213

1314
type TestCaseState struct {
@@ -272,7 +273,7 @@ func NewLabelsDiff(actual map[string]string, expected map[string]string) *Labels
272273
ld.Same = append(ld.Same, k)
273274
}
274275
}
275-
for k, _ := range expected {
276+
for k := range expected {
276277
if _, ok := actual[k]; !ok {
277278
ld.Missing = append(ld.Missing, k)
278279
}

cmd/cyclonus/pkg/generator/testcase.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func ParseProbeMode(mode string) (ProbeMode, error) {
135135
}
136136

137137
// ProbeConfig: exactly one field must be non-null (or, in AllAvailable's case, non-false). This
138-
// models a discriminated union (sum type).
138+
//
139+
// models a discriminated union (sum type).
139140
type ProbeConfig struct {
140141
AllAvailable bool
141142
PortProtocol *PortProtocol

cmd/cyclonus/pkg/generator/testcasegenerator.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@ TODO
55
Test cases:
66
77
1 policy with ingress:
8-
- empty ingress
9-
- ingress with 1 rule
10-
- empty
11-
- 1 port
12-
- empty
13-
- protocol
14-
- port
15-
- port + protocol
16-
- 2 ports
17-
- 1 from
18-
- 8 combos: (nil + nil => might mean ipblock must be non-nil)
19-
- pod sel: nil, empty, non-empty
20-
- ns sel: nil, empty, non-empty
21-
- ipblock
22-
- no except
23-
- yes except
24-
- 2 froms
25-
- 1 pod/ns, 1 ipblock
26-
- 2 pod/ns
27-
- 2 ipblocks
28-
- 1 port, 1 from
29-
- 2 ports, 2 froms
30-
- ingress with 2 rules
31-
- ingress with 3 rules
8+
- empty ingress
9+
- ingress with 1 rule
10+
- empty
11+
- 1 port
12+
- empty
13+
- protocol
14+
- port
15+
- port + protocol
16+
- 2 ports
17+
- 1 from
18+
- 8 combos: (nil + nil => might mean ipblock must be non-nil)
19+
- pod sel: nil, empty, non-empty
20+
- ns sel: nil, empty, non-empty
21+
- ipblock
22+
- no except
23+
- yes except
24+
- 2 froms
25+
- 1 pod/ns, 1 ipblock
26+
- 2 pod/ns
27+
- 2 ipblocks
28+
- 1 port, 1 from
29+
- 2 ports, 2 froms
30+
- ingress with 2 rules
31+
- ingress with 3 rules
32+
3233
2 policies with ingress
3334
1 policy with egress
3435
2 policies with egress

cmd/cyclonus/pkg/kube/labelselector.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111

1212
// IsNameMatch follows the kube pattern of "empty string means matches All"
1313
// It will return:
14-
// if matcher is empty: true
15-
// if objectName and matcher are the same: true
16-
// otherwise false
14+
//
15+
// if matcher is empty: true
16+
// if objectName and matcher are the same: true
17+
// otherwise false
1718
func IsNameMatch(objectName string, matcher string) bool {
1819
if matcher == "" {
1920
return true

cmd/cyclonus/pkg/kube/netpol/policies.go

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,17 @@ func AllowAllTo_Version2(namespace string, targetLabels map[string]string) *netw
246246
kind: NetworkPolicy
247247
apiVersion: networking.k8s.io/v1
248248
metadata:
249-
Namespace: secondary
250-
name: web-allow-all-namespaces
249+
250+
Namespace: secondary
251+
name: web-allow-all-namespaces
252+
251253
spec:
252-
podSelector:
253-
matchLabels:
254-
app: web
255-
ingress:
256-
- from:
254+
255+
podSelector:
256+
matchLabels:
257+
app: web
258+
ingress:
259+
- from:
257260
*/
258261
func AllowAllTo_Version3(namespace string, targetLabels map[string]string) *networkingv1.NetworkPolicy {
259262
return &networkingv1.NetworkPolicy{
@@ -543,20 +546,23 @@ func AllowNoEgressFromLabels(namespace string, targetLabels map[string]string) *
543546
apiVersion: networking.k8s.io/v1
544547
kind: NetworkPolicy
545548
metadata:
546-
name: foo-deny-egress
549+
550+
name: foo-deny-egress
551+
547552
spec:
548-
podSelector:
549-
matchLabels:
550-
app: foo
551-
policyTypes:
552-
- Egress
553-
egress:
554-
# allow DNS resolution
555-
- ports:
556-
- port: 53
557-
protocol: UDP
558-
- port: 53
559-
protocol: TCP
553+
554+
podSelector:
555+
matchLabels:
556+
app: foo
557+
policyTypes:
558+
- Egress
559+
egress:
560+
# allow DNS resolution
561+
- ports:
562+
- port: 53
563+
protocol: UDP
564+
- port: 53
565+
protocol: TCP
560566
*/
561567
func AllowEgressOnPort(namespace string, targetLabels map[string]string, port int) *networkingv1.NetworkPolicy {
562568
tcp := v1.ProtocolTCP
@@ -667,14 +673,17 @@ func AllowEgressToAllNamespacesOnPort(namespace string, targetLabels map[string]
667673
apiVersion: networking.k8s.io/v1
668674
kind: NetworkPolicy
669675
metadata:
670-
name: allow-nothing
676+
677+
name: allow-nothing
678+
671679
spec:
672-
podSelector:
673-
matchLabels:
674-
app: foo
675-
policyTypes:
676-
- Egress
677-
- Ingress
680+
681+
podSelector:
682+
matchLabels:
683+
app: foo
684+
policyTypes:
685+
- Egress
686+
- Ingress
678687
*/
679688
func AllowNoIngressNorEgress(namespace string, targetLabels map[string]string) *networkingv1.NetworkPolicy {
680689
return &networkingv1.NetworkPolicy{

cmd/cyclonus/pkg/kube/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import "fmt"
44

55
// QualifiedServiceAddress returns the address that can be used to hit a service from
66
// any namespace in the cluster
7-
//func QualifiedServiceAddress(serviceName string, namespace string, dnsDomain string) string {
8-
// return fmt.Sprintf("%s.%s.svc.%s", serviceName, namespace, dnsDomain)
7+
//
8+
// func QualifiedServiceAddress(serviceName string, namespace string, dnsDomain string) string {
9+
// return fmt.Sprintf("%s.%s.svc.%s", serviceName, namespace, dnsDomain)
910
func QualifiedServiceAddress(serviceName string, namespace string) string {
1011
return fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, namespace)
1112
}

hack/verify-gofmt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -euo pipefail
1818

1919
echo "Verifying gofmt"
2020

21-
diff=$(find . -name "*.go" | grep -v "\/vendor\/" | grep -v "\/cmd\/cyclonus\/" | xargs gofmt -s -d 2>&1)
21+
diff=$(find . -name "*.go" | grep -v "\/vendor\/" | xargs gofmt -s -d 2>&1)
2222
if [[ -n "${diff}" ]]; then
2323
echo "${diff}"
2424
echo

0 commit comments

Comments
 (0)