Skip to content

Commit

Permalink
Bump golangci to v1.59.1
Browse files Browse the repository at this point in the history
I made the changes that were required to pass the linter. I removed the internal `directory` which hasn't made much sense for a long time. I've modified the GitHub action

the new linter has depguard as the main change, which is a guard for imported packages. these must be explicitly enabled/disabled in the configuration.
- https://golangci-lint.run/usage/linters/#depguard
- https://github.com/OpenPeeDeeP/depguard
  • Loading branch information
kuritka committed Jun 11, 2024
1 parent e99099a commit 373c3f9
Show file tree
Hide file tree
Showing 29 changed files with 80 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@8032b262982c71a7cf7a6d2aa823106fc57e545e
with:
version: v1.51.2
version: v1.59.1
skip-go-installation: true
- name: golic
run: |
Expand Down
24 changes: 24 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ linters-settings:
lll:
line-length: 150

depguard:
# https://golangci-lint.run/usage/linters/#depguard
# https://github.com/OpenPeeDeeP/depguard
rules:
main:
allow:
- $gostd
- k8s.io/apimachinery
- k8s.io/client-go
- k8s.io/api
- sigs.k8s.io/controller-runtime
- sigs.k8s.io/external-dns
- github.com/AbsaOSS
- github.com/ghodss/yaml
- github.com/go-logr
- github.com/golang/mock/
- github.com/infobloxopen
- github.com/k8gb-io
- github.com/miekg
- github.com/prometheus
- github.com/rs/zerolog
- github.com/stretchr/testify
- go.opentelemetry.io/otel

issues:
exclude-rules:
- path: _test\.go
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LOG_LEVEL ?= debug
CONTROLLER_GEN_VERSION ?= v0.8.0
GOLIC_VERSION ?= v0.7.2
GOKART_VERSION ?= v0.5.1
GOLANGCI_VERSION ?= v1.51.2
GOLANGCI_VERSION ?= v1.59.1
POD_NAMESPACE ?= k8gb
CLUSTER_GEO_TAG ?= eu
EXT_GSLB_CLUSTERS_GEO_TAGS ?= us
Expand Down
4 changes: 2 additions & 2 deletions controllers/depresolver/depresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
import (
"sync"

"github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/utils"

"github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/rs/zerolog"
)

Expand Down
3 changes: 2 additions & 1 deletion controllers/depresolver/depresolver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
"strconv"
"strings"

"github.com/k8gb-io/k8gb/controllers/utils"

"github.com/AbsaOSS/env-binder/env"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/rs/zerolog"
)

Expand Down
22 changes: 11 additions & 11 deletions controllers/depresolver/depresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
"strings"
"testing"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
utils2 "github.com/k8gb-io/k8gb/controllers/utils"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -58,7 +58,7 @@ var predefinedConfig = Config{
ClusterGeoTag: "us",
ExtClustersGeoTags: []string{"za", "eu"},
EdgeDNSType: DNSTypeInfoblox,
EdgeDNSServers: []utils.DNSServer{
EdgeDNSServers: []utils2.DNSServer{
{
Host: "dns.cloud.example.com",
Port: 53,
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestResolveConfigWithEmptyEdgeDnsServer(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.EdgeDNSServers = []utils.DNSServer{}
expected.EdgeDNSServers = []utils2.DNSServer{}
// act,assert
arrangeVariablesAndAssert(t, expected, assert.Error)
}
Expand All @@ -357,7 +357,7 @@ func TestResolveConfigWithTwoEdgeDnsServers(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.EdgeDNSServers = []utils.DNSServer{
expected.EdgeDNSServers = []utils2.DNSServer{
{
Host: "8.8.8.8",
Port: 53,
Expand All @@ -375,7 +375,7 @@ func TestResolveConfigWithNoEdgeDnsServer(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.EdgeDNSServers = []utils.DNSServer{}
expected.EdgeDNSServers = []utils2.DNSServer{}
// act,assert
arrangeVariablesAndAssert(t, expected, assert.Error, EdgeDNSServersKey)
}
Expand All @@ -384,7 +384,7 @@ func TestResolveConfigWithEmptyIpAddressInEdgeDnsServer(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.EdgeDNSServers = []utils.DNSServer{
expected.EdgeDNSServers = []utils2.DNSServer{
{
Host: defaultEdgeDNSServerIP,
Port: 53,
Expand All @@ -398,7 +398,7 @@ func TestResolveConfigWithHostnameEdgeDnsServer(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.EdgeDNSServers = []utils.DNSServer{
expected.EdgeDNSServers = []utils2.DNSServer{
{
Host: "server-nonprod.on.domain.l3.2l.com",
Port: 53,
Expand All @@ -413,7 +413,7 @@ func TestResolveConfigWithInvalidIpAddressEdgeDnsServer(t *testing.T) {
// arrange
defer cleanup()
expected := predefinedConfig
expected.EdgeDNSServers = []utils.DNSServer{
expected.EdgeDNSServers = []utils2.DNSServer{
{
Host: fmt.Sprintf("%s.", defaultEdgeDNSServerIP),
Port: 53,
Expand Down Expand Up @@ -1251,7 +1251,7 @@ func TestNsServerNamesForLocalEdgeDNS(t *testing.T) {
defer cleanup()
for _, edgeDNSServer := range []string{"127.0.0.1", "localhost"} {
customConfig := predefinedConfig
customConfig.EdgeDNSServers = []utils.DNSServer{
customConfig.EdgeDNSServers = []utils2.DNSServer{
{
Host: edgeDNSServer,
Port: 53,
Expand Down Expand Up @@ -1550,7 +1550,7 @@ func getTestContext(testData string) (client.Client, *k8gbv1beta1.Gslb) {
if err != nil {
panic(fmt.Errorf("can't open example CR file: %s", testData))
}
gslb, err := utils.YamlToGslb(gslbYaml)
gslb, err := utils2.YamlToGslb(gslbYaml)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/depresolver/depresolver_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"regexp"
"strings"

"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/utils"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion controllers/gslb_controller_reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
"context"
"fmt"

"github.com/k8gb-io/k8gb/controllers/utils"

"github.com/k8gb-io/k8gb/controllers/providers/metrics"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/depresolver"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/logging"
"github.com/k8gb-io/k8gb/controllers/providers/dns"
"go.opentelemetry.io/otel/codes"
Expand Down
27 changes: 14 additions & 13 deletions controllers/gslb_controller_reconciliation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import (
"testing"
"time"

utils2 "github.com/k8gb-io/k8gb/controllers/utils"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/depresolver"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/logging"
"github.com/k8gb-io/k8gb/controllers/mocks"
"github.com/k8gb-io/k8gb/controllers/providers/assistant"
Expand Down Expand Up @@ -74,7 +75,7 @@ var predefinedConfig = depresolver.Config{
ReconcileRequeueSeconds: 30,
ClusterGeoTag: "us-west-1",
ExtClustersGeoTags: []string{"us-east-1"},
EdgeDNSServers: []utils.DNSServer{
EdgeDNSServers: []utils2.DNSServer{
{
Host: "127.0.0.1",
Port: 7753,
Expand All @@ -97,7 +98,7 @@ var predefinedConfig = depresolver.Config{
},
}

var fakeDNSSettings = utils.FakeDNSSettings{
var fakeDNSSettings = utils2.FakeDNSSettings{
FakeDNSPort: 7753,
EdgeDNSZoneFQDN: "example.com.",
DNSZoneFQDN: "cloud.example.com.",
Expand All @@ -111,7 +112,7 @@ const (
defaultEdgeDNS1 = "1.1.1.1"
)

var defaultEdgeDNSServers = []utils.DNSServer{
var defaultEdgeDNSServers = []utils2.DNSServer{
{
Host: defaultEdgeDNS1,
Port: 53,
Expand Down Expand Up @@ -441,7 +442,7 @@ func TestLocalDNSRecordsHasSpecialAnnotation(t *testing.T) {
{IP: "10.0.0.2"},
{IP: "10.0.0.3"},
}
utils.NewFakeDNS(fakeDNSSettings).
utils2.NewFakeDNS(fakeDNSSettings).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 3)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 2)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 1)).
Expand Down Expand Up @@ -494,7 +495,7 @@ func TestCanGetExternalTargetsFromK8gbInAnotherLocation(t *testing.T) {
{IP: "10.0.0.3"},
}
dnsEndpoint := &externaldns.DNSEndpoint{}
utils.NewFakeDNS(fakeDNSSettings).
utils2.NewFakeDNS(fakeDNSSettings).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 3)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 2)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 1)).
Expand Down Expand Up @@ -528,7 +529,7 @@ func TestCanGetExternalTargetsFromK8gbInAnotherLocation(t *testing.T) {

func TestCanCheckExternalGslbTXTRecordForValidityAndFailIfItIsExpired(t *testing.T) {
// arrange
utils.NewFakeDNS(fakeDNSSettings).
utils2.NewFakeDNS(fakeDNSSettings).
AddTXTRecord("test-gslb-heartbeat-eu.example.com.", oldEdgeTimestamp("10m")).
Start().
RunTestFunc(func() {
Expand All @@ -543,7 +544,7 @@ func TestCanCheckExternalGslbTXTRecordForValidityAndFailIfItIsExpired(t *testing

func TestCanCheckExternalGslbTXTRecordForValidityAndPAssIfItISNotExpired(t *testing.T) {
// arrange
utils.NewFakeDNS(fakeDNSSettings).
utils2.NewFakeDNS(fakeDNSSettings).
AddTXTRecord("test-gslb-heartbeat-za.example.com.", oldEdgeTimestamp("3m")).
Start().
RunTestFunc(func() {
Expand Down Expand Up @@ -635,13 +636,13 @@ func TestReturnsExternalRecordsUsingFailoverStrategy(t *testing.T) {
dnsEndpoint := &externaldns.DNSEndpoint{}
customConfig := predefinedConfig
customConfig.ClusterGeoTag = "za"
customConfig.EdgeDNSServers = []utils.DNSServer{
customConfig.EdgeDNSServers = []utils2.DNSServer{
{
Host: "localhost",
Port: 7753,
},
}
utils.NewFakeDNS(fakeDNSSettings).
utils2.NewFakeDNS(fakeDNSSettings).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 3)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 2)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 1)).
Expand Down Expand Up @@ -702,7 +703,7 @@ func TestReturnsExternalRecordsUsingFailoverStrategyAndFallbackDNSserver(t *test
dnsEndpoint := &externaldns.DNSEndpoint{}
customConfig := predefinedConfig
customConfig.ClusterGeoTag = "za"
customConfig.EdgeDNSServers = []utils.DNSServer{
customConfig.EdgeDNSServers = []utils2.DNSServer{
{ // this one will be tried frist, but fails
Host: "localhost",
Port: 7752,
Expand All @@ -716,7 +717,7 @@ func TestReturnsExternalRecordsUsingFailoverStrategyAndFallbackDNSserver(t *test
Port: 7754,
},
}
utils.NewFakeDNS(fakeDNSSettings).
utils2.NewFakeDNS(fakeDNSSettings).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 2)).
AddARecord("localtargets-roundrobin.cloud.example.com.", net.IPv4(10, 1, 0, 1)).
Start().
Expand Down Expand Up @@ -1284,7 +1285,7 @@ func provideSettings(t *testing.T, expected depresolver.Config) (settings testSe
t.Fatalf("Can't open example CR file: %s", crSampleYaml)
}
// Set the log to development mode for verbose logs.
gslb, err := utils.YamlToGslb(gslbYaml)
gslb, err := utils2.YamlToGslb(gslbYaml)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/gslb_controller_weight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestWeight(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

injectWeight := func(ctx context.Context, gslb *k8gbv1beta1.Gslb, client client.Client) error {
injectWeight := func(_ context.Context, gslb *k8gbv1beta1.Gslb, _ client.Client) error {
if !test.injectWeights {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"reflect"

"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/utils"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
netv1 "k8s.io/api/networking/v1"
Expand Down
6 changes: 3 additions & 3 deletions controllers/logging/logr.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func newLogrSinkAdapter(z *zerolog.Logger) *logrSinkAdapter {
}
}

func (a *logrSinkAdapter) Init(info logr.RuntimeInfo) {
func (a *logrSinkAdapter) Init(_ logr.RuntimeInfo) {

}

func (a *logrSinkAdapter) Enabled(level int) bool {
func (a *logrSinkAdapter) Enabled(_ int) bool {
return true
}

func (a *logrSinkAdapter) Info(level int, msg string, keysAndValues ...interface{}) {
func (a *logrSinkAdapter) Info(_ int, msg string, keysAndValues ...interface{}) {
a.WithValues(keysAndValues)
if a.name != "" {
a.z.Info().Msgf("%s: %s %s", a.name, msg, a.valuesAsJSON())
Expand Down
7 changes: 4 additions & 3 deletions controllers/providers/assistant/gslb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
"strings"
"time"

"github.com/k8gb-io/k8gb/controllers/utils"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/internal/utils"
"github.com/k8gb-io/k8gb/controllers/logging"

"github.com/miekg/dns"
Expand Down Expand Up @@ -305,7 +306,7 @@ func (r *Gslb) GetExternalTargets(host string, extClusterNsNames map[string]stri
Msg("Adding external Gslb targets from cluster")
glueA, err := dnsQuery(cluster, r.edgeDNSServers)
if err != nil {
return
return targets
}
log.Info().
Str("nameserver", cluster).
Expand All @@ -323,7 +324,7 @@ func (r *Gslb) GetExternalTargets(host string, extClusterNsNames map[string]stri
lHost := fmt.Sprintf("localtargets-%s", host)
a, err := dnsQuery(lHost, nameServersToUse)
if err != nil {
return
return targets
}
clusterTargets := getARecords(a)
if len(clusterTargets) > 0 {
Expand Down
Loading

0 comments on commit 373c3f9

Please sign in to comment.