Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-carlton committed Jan 19, 2024
1 parent 85d751e commit 4ca4b04
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 73 deletions.
66 changes: 65 additions & 1 deletion bin/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,70 @@
# Utility to gofmt, goimports and test a package
# Version: 1.0

#!/usr/bin/env bash

# Utility setting local kubernetes cluster
# Version: 1.0
# Author: Paul Carlton (mailto:[email protected])

set -euo pipefail

function usage()
{
echo "usage ${0} [--debug] [--flux-bootstrap] [--flux-reset] [--no-wait] [--install]" >&2
echo "This script will initialize docker kubernetes" >&2
echo " --debug: emmit debugging information" >&2
echo " --flux-bootstrap: force flux bootstrap" >&2
echo " --flux-reset: unistall flux before reinstall" >&2
echo " --cluster-type: the cluster type for Linux, k0s or kind, defaults to k0s" >&2
echo " --no-wait: do not wait for flux to be ready" >&2
echo " --install: install software required by kind cluster deployment" >&2
}

function args()
{
wait=1
install=""
bootstrap=0
reset=0
debug_str=""
cluster_type="k0s"
arg_list=( "$@" )
arg_count=${#arg_list[@]}
arg_index=0
while (( arg_index < arg_count )); do
case "${arg_list[${arg_index}]}" in
"--debug") set -x; debug_str="--debug";;
"--no-wait") wait=0;;
"--install") install="--install";;
"--flux-bootstrap") bootstrap=1;;
"--flux-reset") reset=1;;
"--cluster-type") (( arg_index+=1 )); cluster_type="${arg_list[${arg_index}]}";;
"-h") usage; exit;;
"--help") usage; exit;;
"-?") usage; exit;;
*) if [ "${arg_list[${arg_index}]:0:2}" == "--" ];then
echo "invalid argument: ${arg_list[${arg_index}]}" >&2
usage; exit
fi;
break;;
esac
(( arg_index+=1 ))
done

if [ "$aws" == "true" ]; then
if [ -z "$AWS_PROFILE" ]; then
echo "AWS_PROFILE not set" >&2
exit 1
fi
fi
}

args "$@"

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/envs.sh

if [ -z "$1" ] ; then
echo "please specify a package"
exit 1
Expand All @@ -16,6 +80,6 @@ if [ ! -d "$package_name" ] ; then
fi

TOP=`git rev-parse --show-toplevel`
gmake -C $TOP/$package_name --makefile=$TOP/makefile.mk gofmt
gmake -C $TOP/$package_name --makefile=$TOP/makefile.mk gofmt gofumpt
gmake -C $TOP/$package_name --makefile=$TOP/makefile.mk clean
gmake -C $TOP/$package_name --makefile=$TOP/makefile.mk
1 change: 0 additions & 1 deletion golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ linters:
- godox
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- revive
Expand Down
23 changes: 11 additions & 12 deletions pkg/httpclient/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand All @@ -32,11 +31,11 @@ var (
ErrorRequestFailed = errors.New("error making request")
ErrorRequestBodyInvalid = errors.New("failed to convert request body data to JSON")

tr *http.Transport // nolint:gochecknoglobals // ok
DefaultTimeout time.Duration // nolint:gochecknoglobals // ok
Post = "POST" // nolint:gochecknoglobals // ok
Delete = "DELETE" // nolint:gochecknoglobals // ok
Get = "GET" // nolint:gochecknoglobals // ok
tr *http.Transport //nolint:gochecknoglobals // ok
DefaultTimeout time.Duration //nolint:gochecknoglobals // ok
Post = "POST" //nolint:gochecknoglobals // ok
Delete = "DELETE" //nolint:gochecknoglobals // ok
Get = "GET" //nolint:gochecknoglobals // ok
)

func readingResponseBodyError(msg string) error {
Expand All @@ -51,7 +50,7 @@ func requestBodyError(msg string) error {
return fmt.Errorf("%w: %s", ErrorRequestBodyInvalid, msg)
}

func init() { // nolint:gochecknoinits // ok
func init() { //nolint:gochecknoinits // ok
tr = &http.Transport{
Proxy: http.ProxyFromEnvironment,
MaxIdleConns: oneHundred,
Expand Down Expand Up @@ -153,7 +152,7 @@ func (r *reqResp) CloseBody() {
}

// HTTPreq creates an HTTP client and sends a request. The response is held in reqResp.RespText.
func (r *reqResp) HTTPreq() error { // nolint:funlen,gocognit,gocyclo // ok
func (r *reqResp) HTTPreq() error { //nolint:funlen,gocyclo // ok
var err error

r.client.Timeout = *r.timeout
Expand All @@ -168,7 +167,7 @@ func (r *reqResp) HTTPreq() error { // nolint:funlen,gocognit,gocyclo // ok
return requestBodyError(e.Error())
}

inputJSON = ioutil.NopCloser(bytes.NewReader(jsonBytes))
inputJSON = io.NopCloser(bytes.NewReader(jsonBytes))
}

httpReq, err := http.NewRequestWithContext(r.ctx, *r.method, r.url.String(), inputJSON)
Expand All @@ -187,8 +186,8 @@ func (r *reqResp) HTTPreq() error { // nolint:funlen,gocognit,gocyclo // ok
start := time.Now()

for {
r.resp, err = r.client.Do(httpReq) // nolint:bodyclose // ok
if err != nil { // nolint:nestif // ok
r.resp, err = r.client.Do(httpReq) //nolint:bodyclose // ok
if err != nil { //nolint:nestif // ok
if strings.Contains(err.Error(), "connection refused") ||
strings.Contains(err.Error(), "http2: no cached connection was available") ||
strings.Contains(err.Error(), "net/http: TLS handshake timeout") ||
Expand Down Expand Up @@ -232,7 +231,7 @@ func (r *reqResp) HTTPreq() error { // nolint:funlen,gocognit,gocyclo // ok
func (r *reqResp) getRespBody() error {
defer r.resp.Body.Close()

data, err := ioutil.ReadAll(r.resp.Body)
data, err := io.ReadAll(r.resp.Body)
if err != nil {
return readingResponseBodyError(err.Error())
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/httpserver/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -72,7 +71,7 @@ func (handler *HandlerHTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("unrecognised request %s", ThePath), http.StatusBadRequest)
}

func (handler *HandlerHTTP) Start(handlers *MuxHTTP) {
func (handler *HandlerHTTP) Start(_ *MuxHTTP) {
go serveHTTP(*handler)
}

Expand Down Expand Up @@ -159,7 +158,7 @@ func JSONresponse(w http.ResponseWriter, jsonResp string) (int, string) {
func GetReqBody(r *http.Request) (string, error) {
defer r.Body.Close()

data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
return "", readingBodyError(err.Error())
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/kubectl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.21

require (
github.com/go-logr/logr v0.4.0
github.com/golang/mock v1.5.0
github.com/paul-carlton/goutils/pkg/logging v0.1.5
github.com/paul-carlton/goutils/pkg/mocks/kubectl v0.1.5
github.com/paul-carlton/goutils/pkg/mocks/logr v0.1.5
github.com/pkg/errors v0.9.1
go.uber.org/mock v0.4.0
)

require (
Expand All @@ -20,11 +20,10 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apimachinery v0.21.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubectl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -462,8 +460,9 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -532,8 +531,9 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
21 changes: 9 additions & 12 deletions pkg/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package kubectl

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

Expand All @@ -36,11 +36,11 @@ const (
)

var (
kubectlCmd = "kubectl" // nolint: gochecknoglobals // ok
kustomizeCmd = "kustomize" // nolint: gochecknoglobals // ok
applyArgs = []string{"-R", "-f"} // nolint: gochecknoglobals // ok
newExecProviderFunc = newExecProvider // nolint: gochecknoglobals // ok
tempDirProviderFunc = createTempDir // nolint: gochecknoglobals // ok
kubectlCmd = "kubectl" //nolint: gochecknoglobals // ok
kustomizeCmd = "kustomize" //nolint: gochecknoglobals // ok
applyArgs = []string{"-R", "-f"} //nolint: gochecknoglobals // ok
newExecProviderFunc = newExecProvider //nolint: gochecknoglobals // ok
tempDirProviderFunc = createTempDir //nolint: gochecknoglobals // ok
)

// Kubectl is a Factory interface that returns concrete Command implementations from named constructors.
Expand Down Expand Up @@ -182,10 +182,7 @@ func (c *abstractCommand) Run() (output []byte, err error) {

// createTempDir creates a temporary directory.
func createTempDir() (buildDir string, err error) {
buildDir, err = ioutil.TempDir("", "build-*")
if err != nil {
return "", errors.WithMessagef(err, "%s - failed to create temporary directory", logging.CallerStr(logging.Me))
}
buildDir = os.TempDir()

return buildDir, nil
}
Expand All @@ -199,7 +196,7 @@ func (c *abstractCommand) Build() (buildDir string) {

buildDir, err = tempDirProviderFunc()
if err != nil {
c.logError(err) // nolint:errcheck //ok
c.logError(err) //nolint:errcheck //ok

return buildDir
}
Expand All @@ -209,7 +206,7 @@ func (c *abstractCommand) Build() (buildDir string) {

c.output, err = c.factory.getExecProvider().ExecCmd(c.getPath(), c.getArgs()...)
if err != nil {
c.logError(err) // nolint:errcheck //ok
c.logError(err) //nolint:errcheck //ok
}

return buildDir
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/kubectl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestRealKubectlBinaryInstalled(t *testing.T) {
t.Logf("Kubectl (%T) %#v", k, k)

if err != nil {
t.Errorf("Error from NewKubectl constructor function: %w", err)
t.Errorf("Error from NewKubectl constructor function: %v", err)
} else {
t.Logf("Found '%s' binary at '%s'", kubectl.KubectlCmd, kubectl.GetFactoryPath(*k.(*kubectl.CommandFactory)))
}
Expand Down
Loading

0 comments on commit 4ca4b04

Please sign in to comment.