Skip to content

Commit

Permalink
CI linting fixes (#3205)
Browse files Browse the repository at this point in the history
* ci linting fixes

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* remove staticcheck

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* disable naming rule

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* disable stylecheck too

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* linter errors fixes

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* re-add staticcheck

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* fixes various linting issues

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* fix imports

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* fix tlsconfig

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* fix alibabacloud

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* ioutil fixes

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* remove all references to ioutil

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

* ignore linting for azure deprecated sdk

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>

Signed-off-by: Raffaele Di Fazio <difazio.raffaele@gmail.com>
  • Loading branch information
Raffo authored Dec 2, 2022
1 parent bbd007e commit 31e6bb8
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 52 deletions.
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ linters-settings:
suggest-new: true
misspell:
locale: US
revive:
confusing-naming: false
ignore-generated-header: true
rules:
- name: confusing-naming
disabled: true

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
Expand All @@ -25,6 +31,10 @@ linters:
- typecheck
- unconvert
- whitespace
- revive
- unused
- gosimple
- staticcheck

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package testutils

import (
"io/ioutil"
"io"
"log"
"os"

Expand All @@ -29,8 +29,8 @@ import (
func init() {
config.FastPoll = true
if os.Getenv("DEBUG") == "" {
logrus.SetOutput(ioutil.Discard)
log.SetOutput(ioutil.Discard)
logrus.SetOutput(io.Discard)
log.SetOutput(io.Discard)
} else {
if level, err := logrus.ParseLevel(os.Getenv("DEBUG")); err == nil {
logrus.SetLevel(level)
Expand Down
3 changes: 1 addition & 2 deletions pkg/tlsutils/tlsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
)
Expand Down Expand Up @@ -77,7 +76,7 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
}

roots := x509.NewCertPool()
pem, err := ioutil.ReadFile(caPath)
pem, err := os.ReadFile(caPath)
if err != nil {
return nil, fmt.Errorf("error reading %s: %s", caPath, err)
}
Expand Down
4 changes: 2 additions & 2 deletions provider/alibabacloud/alibaba_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package alibabacloud
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -99,7 +99,7 @@ type alibabaCloudConfig struct {
func NewAlibabaCloudProvider(configFile string, domainFilter endpoint.DomainFilter, zoneIDFileter provider.ZoneIDFilter, zoneType string, dryRun bool) (*AlibabaCloudProvider, error) {
cfg := alibabaCloudConfig{}
if configFile != "" {
contents, err := ioutil.ReadFile(configFile)
contents, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read Alibaba Cloud config file '%s': %v", configFile, err)
}
Expand Down
1 change: 1 addition & 0 deletions provider/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// nolint:staticcheck
package azure

import (
Expand Down
1 change: 1 addition & 0 deletions provider/azure/azure_private_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// nolint:staticcheck
package azure

import (
Expand Down
4 changes: 2 additions & 2 deletions provider/azure/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package azure

import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/Azure/go-autorest/autorest/adal"
Expand All @@ -42,7 +42,7 @@ type config struct {
}

func getConfig(configFile, resourceGroup, userAssignedIdentityClientID string) (*config, error) {
contents, err := ioutil.ReadFile(configFile)
contents, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read Azure config file '%s': %v", configFile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions provider/azure/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package azure

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
Expand All @@ -27,7 +26,7 @@ import (
)

func TestGetAzureEnvironmentConfig(t *testing.T) {
tmp, err := ioutil.TempFile("", "azureconf")
tmp, err := os.CreateTemp("", "azureconf")
if err != nil {
t.Errorf("couldn't write temp file %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions provider/bluecat/gateway/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"crypto/tls"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -181,7 +180,7 @@ func GetBluecatGatewayToken(cfg BluecatConfig) (string, http.Cookie, error) {
}
defer response.Body.Close()

responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
return "", http.Cookie{}, errors.Wrap(err, "failed to read login response from bluecat gateway")
}
Expand Down Expand Up @@ -504,7 +503,7 @@ func (c GatewayClientConfig) ServerFullDeploy() error {
}

if response.StatusCode != http.StatusCreated {
responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
return errors.Wrap(err, "failed to read full deploy response body")
}
Expand Down
6 changes: 3 additions & 3 deletions provider/bluecat/gateway/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package api

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestBluecatSplitProperties(t *testing.T) {
func TestCreateTXTRecord(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req := BluecatCreateTXTRecordRequest{}
requestBodyBytes, _ := ioutil.ReadAll(r.Body)
requestBodyBytes, _ := io.ReadAll(r.Body)
err := json.Unmarshal(requestBodyBytes, &req)
if err != nil {
t.Fatalf("failed to unmarshal body for server full deploy")
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestDeleteTXTRecord(t *testing.T) {
func TestServerFullDeploy(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req := BluecatServerFullDeployRequest{}
requestBodyBytes, _ := ioutil.ReadAll(r.Body)
requestBodyBytes, _ := io.ReadAll(r.Body)
err := json.Unmarshal(requestBodyBytes, &req)
if err != nil {
t.Fatalf("failed to unmarshal body for server full deploy")
Expand Down
3 changes: 1 addition & 2 deletions provider/coredns/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -191,7 +190,7 @@ func loadRoots(caPath string) (*x509.CertPool, error) {
}

roots := x509.NewCertPool()
pem, err := ioutil.ReadFile(caPath)
pem, err := os.ReadFile(caPath)
if err != nil {
return nil, fmt.Errorf("error reading %s: %s", caPath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions provider/designate/designate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"encoding/pem"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -174,7 +173,7 @@ func TestNewDesignateProvider(t *testing.T) {
Type: "CERTIFICATE",
Bytes: ts.Certificate().Raw,
}
tmpfile, err := ioutil.TempFile("", "os-test.crt")
tmpfile, err := os.CreateTemp("", "os-test.crt")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions provider/godaddy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -286,7 +286,7 @@ func (c *Client) CallAPIWithContext(ctx context.Context, method, path string, re
func (c *Client) UnmarshalResponse(response *http.Response, resType interface{}) error {
// Read all the response body
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions provider/ibmcloud/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package ibmcloud
import (
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -201,7 +201,7 @@ type ibmcloudChange struct {
}

func getConfig(configFile string) (*ibmcloudConfig, error) {
contents, err := ioutil.ReadFile(configFile)
contents, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed to read IBM Cloud config file '%s': %v", configFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions provider/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package oci

import (
"context"
"io/ioutil"
"os"
"strings"

"github.com/oracle/oci-go-sdk/common"
Expand Down Expand Up @@ -72,7 +72,7 @@ type ociDNSClient interface {
// LoadOCIConfig reads and parses the OCI ExternalDNS config file at the given
// path.
func LoadOCIConfig(path string) (*OCIConfig, error) {
contents, err := ioutil.ReadFile(path)
contents, err := os.ReadFile(path)
if err != nil {
return nil, errors.Wrapf(err, "reading OCI config file %q", path)
}
Expand Down
9 changes: 4 additions & 5 deletions provider/pihole/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -114,7 +113,7 @@ func (p *piholeClient) listRecords(ctx context.Context, rtype string) ([]*endpoi
return nil, err
}
defer body.Close()
raw, err := ioutil.ReadAll(body)
raw, err := io.ReadAll(body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -207,11 +206,11 @@ func (p *piholeClient) apply(ctx context.Context, action string, ep *endpoint.En
}

if p.cfg.DryRun {
log.Infof("DRY RUN: %s %s IN %s -> %s", strings.Title(action), ep.DNSName, ep.RecordType, ep.Targets[0])
log.Infof("DRY RUN: %s %s IN %s -> %s", action, ep.DNSName, ep.RecordType, ep.Targets[0])
return nil
}

log.Infof("%s %s IN %s -> %s", strings.Title(action), ep.DNSName, ep.RecordType, ep.Targets[0])
log.Infof("%s %s IN %s -> %s", action, ep.DNSName, ep.RecordType, ep.Targets[0])

form := p.newDNSActionForm(action, ep)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(form.Encode()))
Expand All @@ -226,7 +225,7 @@ func (p *piholeClient) apply(ctx context.Context, action string, ep *endpoint.En
}
defer body.Close()

raw, err := ioutil.ReadAll(body)
raw, err := io.ReadAll(body)
if err != nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package provider

import (
"io/ioutil"
"io"
"os"
"testing"

Expand All @@ -26,7 +26,7 @@ import (
)

func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

Expand Down
3 changes: 1 addition & 2 deletions provider/rdns/rdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"regexp"
Expand Down Expand Up @@ -309,7 +308,7 @@ func newEtcdv3Client() (RDNSClient, error) {

if ca != "" {
roots := x509.NewCertPool()
pem, err := ioutil.ReadFile(ca)
pem, err := os.ReadFile(ca)
if err != nil {
return nil, fmt.Errorf("error reading %s: %s", ca, err)
}
Expand Down
Loading

0 comments on commit 31e6bb8

Please sign in to comment.