Skip to content

Commit 77c2688

Browse files
authored
Add golangci (apache#62)
1 parent 1c5bd9e commit 77c2688

File tree

3 files changed

+97
-7
lines changed

3 files changed

+97
-7
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: golangci-lint
19+
on:
20+
push:
21+
branches:
22+
- main
23+
pull_request:
24+
25+
permissions:
26+
contents: read
27+
checks: write
28+
jobs:
29+
golangci:
30+
name: lint
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-go@v5
35+
with:
36+
go-version: '1.19'
37+
- name: golangci-lint
38+
uses: golangci/golangci-lint-action@v6

.golangci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
linters-settings:
19+
goheader:
20+
template: |-
21+
* Licensed to the Apache Software Foundation (ASF) under one
22+
* or more contributor license agreements. See the NOTICE file
23+
* distributed with this work for additional information
24+
* regarding copyright ownership. The ASF licenses this file
25+
* to you under the Apache License, Version 2.0 (the
26+
* "License"); you may not use this file except in compliance
27+
* with the License. You may obtain a copy of the License at
28+
*
29+
* http://www.apache.org/licenses/LICENSE-2.0
30+
*
31+
* Unless required by applicable law or agreed to in writing,
32+
* software distributed under the License is distributed on an
33+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34+
* KIND, either express or implied. See the License for the
35+
* specific language governing permissions and limitations
36+
* under the License.
37+
38+
linters:
39+
enable:
40+
- goheader
41+
- gosec
42+
- gosimple
43+
- govet
44+
- ineffassign
45+
- misspell
46+
- staticcheck
47+
- typecheck
48+
- unused
49+
50+
run:
51+
modules-download-mode: readonly
52+
timeout: 5m
53+
issues-exit-code: 1

cloudstack_loadbalancer.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ func (cs *CSCloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName st
299299
if err != nil {
300300
klog.Errorf("Error parsing port: %v", err)
301301
} else {
302-
lb.deleteFirewallRule(lbRule.Publicipid, int(port), protocol)
302+
_, err = lb.deleteFirewallRule(lbRule.Publicipid, int(port), protocol)
303+
if err != nil {
304+
klog.Errorf("Error deleting firewall rule: %v", err)
305+
}
303306
}
304307

305308
klog.V(4).Infof("Deleting load balancer rule: %v", lbRule.Name)
@@ -657,10 +660,7 @@ func compareStringSlice(x, y []string) bool {
657660
delete(diff, _y)
658661
}
659662
}
660-
if len(diff) == 0 {
661-
return true
662-
}
663-
return false
663+
return len(diff) == 0
664664
}
665665

666666
func ruleToString(rule *cloudstack.FirewallRule) string {
@@ -699,7 +699,7 @@ func rulesToString(rules []*cloudstack.FirewallRule) string {
699699
func rulesMapToString(rules map[*cloudstack.FirewallRule]bool) string {
700700
ls := &strings.Builder{}
701701
first := true
702-
for rule, _ := range rules {
702+
for rule := range rules {
703703
if first {
704704
first = false
705705
} else {
@@ -740,7 +740,6 @@ func (lb *loadBalancer) updateFirewallRule(publicIpId string, publicPort int, pr
740740
for _, rule := range r.FirewallRules {
741741
if rule.Protocol == protocol.IPProtocol() && rule.Startport == publicPort && rule.Endport == publicPort {
742742
filtered[rule] = true
743-
} else {
744743
}
745744
}
746745
klog.V(4).Infof("Matching rules for %v: %v", lb.ipAddr, rulesMapToString(filtered))

0 commit comments

Comments
 (0)