CI linting fixes (#3205)

* 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>
This commit is contained in:
Raffaele Di Fazio 2022-12-02 19:57:53 +01:00 committed by GitHub
parent bbd007eed5
commit 31e6bb8578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 55 additions and 52 deletions

View File

@ -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.
@ -25,6 +31,10 @@ linters:
- typecheck
- unconvert
- whitespace
- revive
- unused
- gosimple
- staticcheck
issues:
# Excluding configuration per-path, per-linter, per-text and per-source

View File

@ -17,7 +17,7 @@ limitations under the License.
package testutils
import (
"io/ioutil"
"io"
"log"
"os"
@ -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)

View File

@ -21,7 +21,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
)
@ -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)
}

View File

@ -19,7 +19,7 @@ package alibabacloud
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
"time"
@ -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)
}

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// nolint:staticcheck
package azure
import (

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// nolint:staticcheck
package azure
import (

View File

@ -18,7 +18,7 @@ package azure
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/Azure/go-autorest/autorest/adal"
@ -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)
}

View File

@ -18,7 +18,6 @@ package azure
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
@ -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)
}

View File

@ -22,7 +22,6 @@ import (
"crypto/tls"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
@ -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")
}
@ -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")
}

View File

@ -15,7 +15,7 @@ package api
import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@ -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")
@ -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")

View File

@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net"
"os"
@ -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)
}

View File

@ -20,7 +20,6 @@ import (
"context"
"encoding/pem"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -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)
}

View File

@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"
@ -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
}

View File

@ -19,7 +19,7 @@ package ibmcloud
import (
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
"strconv"
"strings"
@ -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)
}

View File

@ -18,7 +18,7 @@ package oci
import (
"context"
"io/ioutil"
"os"
"strings"
"github.com/oracle/oci-go-sdk/common"
@ -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)
}

View File

@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
@ -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
}
@ -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()))
@ -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
}

View File

@ -17,7 +17,7 @@ limitations under the License.
package provider
import (
"io/ioutil"
"io"
"os"
"testing"
@ -26,7 +26,7 @@ import (
)
func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

View File

@ -22,7 +22,6 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"regexp"
@ -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)
}

View File

@ -53,7 +53,7 @@ func (api *defaultTencentAPIService) CreatePrivateZoneRecord(request *privatedns
client := api.ClientSetService.PrivateDnsCli(apiAction.Name)
if response, err = client.CreatePrivateZoneRecord(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -71,7 +71,7 @@ func (api *defaultTencentAPIService) DeletePrivateZoneRecord(request *privatedns
client := api.ClientSetService.PrivateDnsCli(apiAction.Name)
if response, err = client.DeletePrivateZoneRecord(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -89,7 +89,7 @@ func (api *defaultTencentAPIService) ModifyPrivateZoneRecord(request *privatedns
client := api.ClientSetService.PrivateDnsCli(apiAction.Name)
if response, err = client.ModifyPrivateZoneRecord(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -107,7 +107,7 @@ func (api *defaultTencentAPIService) DescribePrivateZoneList(request *privatedns
client := api.ClientSetService.PrivateDnsCli(apiAction.Name)
if response, err = client.DescribePrivateZoneList(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -125,7 +125,7 @@ func (api *defaultTencentAPIService) DescribePrivateZoneRecordList(request *priv
client := api.ClientSetService.PrivateDnsCli(apiAction.Name)
if response, err = client.DescribePrivateZoneRecordList(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -147,7 +147,7 @@ func (api *defaultTencentAPIService) DescribeDomainList(request *dnspod.Describe
client := api.ClientSetService.DnsPodCli(apiAction.Name)
if response, err = client.DescribeDomainList(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -165,7 +165,7 @@ func (api *defaultTencentAPIService) DescribeRecordList(request *dnspod.Describe
client := api.ClientSetService.DnsPodCli(apiAction.Name)
if response, err = client.DescribeRecordList(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -183,7 +183,7 @@ func (api *defaultTencentAPIService) CreateRecord(request *dnspod.CreateRecordRe
client := api.ClientSetService.DnsPodCli(apiAction.Name)
if response, err = client.CreateRecord(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -201,7 +201,7 @@ func (api *defaultTencentAPIService) DeleteRecord(request *dnspod.DeleteRecordRe
client := api.ClientSetService.DnsPodCli(apiAction.Name)
if response, err = client.DeleteRecord(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}
@ -219,7 +219,7 @@ func (api *defaultTencentAPIService) ModifyRecord(request *dnspod.ModifyRecordRe
client := api.ClientSetService.DnsPodCli(apiAction.Name)
if response, err = client.ModifyRecord(request); err != nil {
requestJson := JsonWrapper(request)
if retry := dealWithError(apiAction, requestJson, err); retry == false || times == api.RetryDefault {
if retry := dealWithError(apiAction, requestJson, err); retry || times == api.RetryDefault {
APIErrorRecord(apiAction, requestJson, JsonWrapper(response), err)
return nil, err
}

View File

@ -67,7 +67,6 @@ func NewTencentCloudProvider(domainFilter endpoint.DomainFilter, zoneIDFilter pr
type TencentCloudProvider struct {
provider.BaseProvider
logger *log.Logger
apiService cloudapi.TencentAPIService
domainFilter endpoint.DomainFilter
zoneIDFilter provider.ZoneIDFilter // Private Zone only

View File

@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"testing"
@ -54,7 +53,7 @@ func defaultHeader() http.Header {
}
func objBody(codec runtime.Encoder, obj runtime.Object) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj))))
return io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj))))
}
func fakeRESTClient(endpoints []*endpoint.Endpoint, apiVersion, kind, namespace, name string, annotations map[string]string, labels map[string]string, t *testing.T) rest.Interface {

View File

@ -23,10 +23,10 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"sort"
"strings"
"sync"
@ -116,7 +116,7 @@ func newRouteGroupClient(token, tokenPath string, timeout time.Duration) *routeG
cli.updateToken()
// cluster internal use custom CA to reach TLS endpoint
rootCA, err := ioutil.ReadFile(rootCAFile)
rootCA, err := os.ReadFile(rootCAFile)
if err != nil {
return cli
}
@ -138,7 +138,7 @@ func (cli *routeGroupClient) updateToken() {
return
}
token, err := ioutil.ReadFile(cli.tokenFile)
token, err := os.ReadFile(cli.tokenFile)
if err != nil {
log.Errorf("Failed to read token from file (%s): %v", cli.tokenFile, err)
return