Skip to content

Commit

Permalink
Add golangci
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh92 committed May 29, 2024
1 parent 1c5bd9e commit 70f47b6
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 7 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: golangci-lint
on:
push:
branches:
- main
pull_request:

permissions:
contents: read
checks: write
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.19'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
53 changes: 53 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

linters-settings:
goheader:
template: |-
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
linters:
enable:
- goheader
- gosec
- gosimple
- govet
- ineffassign
- misspell
- staticcheck
- typecheck
- unused

run:
modules-download-mode: readonly
timeout: 5m
issues-exit-code: 1
13 changes: 6 additions & 7 deletions cloudstack_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ func (cs *CSCloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName st
if err != nil {
klog.Errorf("Error parsing port: %v", err)
} else {
lb.deleteFirewallRule(lbRule.Publicipid, int(port), protocol)
_, err = lb.deleteFirewallRule(lbRule.Publicipid, int(port), protocol)
if err != nil {
klog.Errorf("Error deleting firewall rule: %v", err)
}
}

klog.V(4).Infof("Deleting load balancer rule: %v", lbRule.Name)
Expand Down Expand Up @@ -657,10 +660,7 @@ func compareStringSlice(x, y []string) bool {
delete(diff, _y)
}
}
if len(diff) == 0 {
return true
}
return false
return len(diff) == 0
}

func ruleToString(rule *cloudstack.FirewallRule) string {
Expand Down Expand Up @@ -699,7 +699,7 @@ func rulesToString(rules []*cloudstack.FirewallRule) string {
func rulesMapToString(rules map[*cloudstack.FirewallRule]bool) string {
ls := &strings.Builder{}
first := true
for rule, _ := range rules {
for rule := range rules {
if first {
first = false
} else {
Expand Down Expand Up @@ -740,7 +740,6 @@ func (lb *loadBalancer) updateFirewallRule(publicIpId string, publicPort int, pr
for _, rule := range r.FirewallRules {
if rule.Protocol == protocol.IPProtocol() && rule.Startport == publicPort && rule.Endport == publicPort {
filtered[rule] = true
} else {
}
}
klog.V(4).Infof("Matching rules for %v: %v", lb.ipAddr, rulesMapToString(filtered))
Expand Down

0 comments on commit 70f47b6

Please sign in to comment.