Skip to content

Commit e05d782

Browse files
authored
Merge pull request #3690 from alexandear-org/refactor/enable-staticcheck-qf
refactor: Fix staticcheck QF* issues
2 parents b94e2fc + 8b7ba1e commit e05d782

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ linters:
118118
# https://staticcheck.dev/docs/configuration/options/#checks
119119
checks:
120120
- all
121-
- -QF*
121+
- -QF1001 # apply De Morgan's law
122+
- -QF1008 # remove embedded field from selector
122123
- -SA3000 # false positive for Go 1.15+. See https://github.com/golang/go/issues/34129
123124
- -ST1000
124125
- -ST1001 # duplicates revive.dot-imports

pkg/guestagent/kubernetesservice/kubernetesservice.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ func (s *ServiceWatcher) GetPorts() []Entry {
140140
}
141141

142142
var port int32
143-
if service.Spec.Type == corev1.ServiceTypeNodePort {
143+
switch service.Spec.Type {
144+
case corev1.ServiceTypeNodePort:
144145
port = portEntry.NodePort
145-
} else if service.Spec.Type == corev1.ServiceTypeLoadBalancer {
146+
case corev1.ServiceTypeLoadBalancer:
146147
port = portEntry.Port
147148
}
148149

pkg/hostagent/dns/dns.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ func newStaticClientConfig(ips []string) (*dns.ClientConfig, error) {
7878

7979
func (h *Handler) lookupCnameToHost(cname string) string {
8080
seen := make(map[string]bool)
81-
for {
82-
// break cyclic definition
83-
if seen[cname] {
84-
break
85-
}
81+
for !seen[cname] { // break cyclic definition
8682
if _, ok := h.cnameToHost[cname]; ok {
8783
seen[cname] = true
8884
cname = h.cnameToHost[cname]

pkg/hostagent/dns/dns_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func TestDNSRecords(t *testing.T) {
5353
"host.lima.internal": "10.10.0.34",
5454
"my.host": "host.lima.internal",
5555
"default": "my.domain.com",
56+
"cycle1.example.com": "cycle2.example.com",
57+
"cycle2.example.com": "cycle1.example.com",
58+
"self.example.com": "self.example.com",
5659
},
5760
}
5861

@@ -120,6 +123,23 @@ func TestDNSRecords(t *testing.T) {
120123
assert.Assert(t, regexMatch(dnsResult.String(), tc.expectedCNAME))
121124
}
122125
})
126+
127+
t.Run("test cyclic CNAME records", func(t *testing.T) {
128+
tests := []struct {
129+
testDomain string
130+
expectedCNAME string
131+
}{
132+
{testDomain: "cycle1.example.com", expectedCNAME: `cycle1.example.com.`},
133+
{testDomain: "self.example.com", expectedCNAME: `self.example.com.`},
134+
}
135+
136+
for _, tc := range tests {
137+
req := new(dns.Msg)
138+
req.SetQuestion(dns.Fqdn(tc.testDomain), dns.TypeCNAME)
139+
h.ServeDNS(w, req)
140+
assert.Assert(t, regexMatch(dnsResult.String(), tc.expectedCNAME))
141+
}
142+
})
123143
}
124144

125145
type TestResponseWriter struct{}

0 commit comments

Comments
 (0)