Skip to content

Commit

Permalink
fix(autok3s): Upgrade golang builder to v1.20.8
Browse files Browse the repository at this point in the history
Also upgraded golangci-lint version to adapt v1.20+ golang
And use revive linter instead of golint
And lint fixes
  • Loading branch information
orangedeng authored and JacieChao committed Sep 15, 2023
1 parent dacf25f commit be99484
Show file tree
Hide file tree
Showing 34 changed files with 94 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"disable-all": true,
"enable": [
"govet",
"golint",
"revive",
"goimports",
"misspell",
"ineffassign",
Expand Down
13 changes: 10 additions & 3 deletions Dockerfile.dapper
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
FROM registry.suse.com/bci/golang:1.19
# FROM registry.suse.com/bci/golang:1.20
FROM registry.suse.com/bci/bci-base:latest
ARG PROXY
ARG GOPROXY
RUN zypper -n install netcat wget curl gawk
ARG ARCH=amd64
ARG GO_VERSION=1.20.8
RUN curl -sSL https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz -o /tmp/go.tar.gz \
&& rm -rf /usr/local/go && tar -C /usr/local -xzf /tmp/go.tar.gz \
&& /usr/local/go/bin/go version
ENV GOPATH=/go PATH=/go/bin:/usr/local/go/bin:/root/go/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN zypper -n install netcat wget curl gawk git make
RUN zypper install -y -f docker
## install golangci-lint
RUN if [ "$(go env GOARCH)" = "amd64" ]; then \
export HTTPS_PROXY=${PROXY}; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.1; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.54.2; \
golangci-lint --version; \
fi
## install mockgen
Expand Down
6 changes: 2 additions & 4 deletions cmd/airgap/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ var (
if err := cobra.MaximumNArgs(2)(cmd, args); err != nil {
return err
}
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return err
}
return nil

return cobra.MinimumNArgs(1)(cmd, args)
},
RunE: importFunc,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/airgap/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func init() {
listCmd.Flags().BoolVarP(&airgapFlags.isJSON, "json", "j", airgapFlags.isJSON, "json output")
}

func list(cmd *cobra.Command, args []string) error {
func list(cmd *cobra.Command, _ []string) error {
pkgs, err := common.DefaultDB.ListPackages(nil)
if err != nil {
return errors.Wrap(err, "failed to list airgap packages.")
return errors.Wrap(err, "failed to list airgap packages")
}
if airgapFlags.isJSON {
data, err := json.Marshal(pkgs)
Expand Down
2 changes: 1 addition & 1 deletion cmd/airgap/update_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
}
)

func updateInstallScript(cmd *cobra.Command, args []string) error {
func updateInstallScript(cmd *cobra.Command, _ []string) error {
buff := bytes.NewBuffer([]byte{})
if err := settings.GetScriptFromSource(buff); err != nil {
return err
Expand Down
7 changes: 2 additions & 5 deletions cmd/sshkey/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
exportCmd.Flags().StringVarP(&sshKeyFlags.OutputPath, "output", "o", ".", "The path to write key pair files, will write to id_rsa, id_rsa.pub and pub.cert under the output path")
}

func validateFiles(cmd *cobra.Command, args []string) error {
func validateFiles(_ *cobra.Command, args []string) error {
if err := pathExists(sshKeyFlags.OutputPath); err != nil {
return err
}
Expand All @@ -51,11 +51,8 @@ func validateFiles(cmd *cobra.Command, args []string) error {
}
toValidate = append(toValidate, filename)
}
if err := pathsNotExists(sshKeyFlags.OutputPath, toValidate...); err != nil {
return err
}

return nil
return pathsNotExists(sshKeyFlags.OutputPath, toValidate...)
}

func export(cmd *cobra.Command, args []string) error {
Expand Down
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module github.com/cnrancher/autok3s

go 1.19
go 1.20

replace (
go4.org/unsafe/assume-no-moving-gc => go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2
inet.af/netaddr => inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a
)

require (
github.com/AlecAivazis/survey/v2 v2.3.5
Expand Down Expand Up @@ -170,7 +175,7 @@ require (
go.opencensus.io v0.24.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1107,9 +1107,8 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE=
go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 h1:FyBZqvoA/jbNzuAWLQE2kG820zMAkcilx6BMjGbL/E4=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 h1:WJhcL4p+YeDxmZWg141nRm7XC8IDmhz7lk5GpadO1Sg=
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -1639,8 +1638,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 h1:U2fwK6P2EqmopP/hFLTOAjWTki0qgd4GMJn5X8wOleU=
inet.af/netaddr v0.0.0-20220811202034-502d2d690317/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k=
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a h1:1XCVEdxrvL6c0TGOhecLuB7U9zYNdxZEjvOqJreKZiM=
inet.af/netaddr v0.0.0-20230525184311-b8eac61e914a/go.mod h1:e83i32mAQOW1LAqEIweALsuK2Uw4mhQadA5r7b0Wobo=
k8s.io/api v0.18.0/go.mod h1:q2HRQkfDzHMBZL9l/y9rH63PkQl4vae0xRT+8prbrK8=
k8s.io/api v0.20.1/go.mod h1:KqwcCVogGxQY3nBlRpwt+wpAMF/KjaCc7RpywacvqUo=
k8s.io/api v0.20.4/go.mod h1:++lNL1AJMkDymriNniQsWRkMDzRaX2Y/POTUi8yvqYQ=
Expand Down
2 changes: 1 addition & 1 deletion hack/lib/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function autok3s::lint::lint() {

if autok3s::lint::validate; then
for path in "$@"; do
golangci-lint run "${path}"
golangci-lint -v run "${path}"
done
else
autok3s::log::warn "no golangci-lint available, using go fmt/vet instead"
Expand Down
2 changes: 1 addition & 1 deletion pkg/airgap/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (d *downloader) validateVersion() error {
downloadURL := fmt.Sprintf("%s/%s", sourceURL, imageListFilename)
resp, err := doRequestWithCtx(d.ctx, http.MethodGet, downloadURL, nil)
if err != nil {
return errors.Wrapf(err, "failed to download image list of k3s version %s, this version may be not validated.", d.pkg.K3sVersion)
return errors.Wrapf(err, "failed to download image list of k3s version %s, this version may be not validated", d.pkg.K3sVersion)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
Expand Down
6 changes: 2 additions & 4 deletions pkg/common/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ func MoveLogs() error {
if err := os.MkdirAll(filepath.Join(newRoot, rel), 0755); err != nil {
return err
}
if err := os.Rename(path, GetClusterLogFilePath(rel)); err != nil {
return err
}
return nil

return os.Rename(path, GetClusterLogFilePath(rel))
}); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/hosts/dialer/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (d *DockerShell) Terminal() error {
}

// OpenTerminal open docker websocket terminal.
func (d *DockerShell) OpenTerminal(win hosts.ShellWindowSize) error {
func (d *DockerShell) OpenTerminal(_ hosts.ShellWindowSize) error {
return d.ExecStart(false)
}

Expand Down Expand Up @@ -443,6 +443,6 @@ func (d *DockerShell) ChangeWindowSize(win hosts.ShellWindowSize) error {
}

// Write write implement.
func (d *DockerShell) Write(b []byte) error {
func (d *DockerShell) Write(_ []byte) error {
return nil
}
2 changes: 1 addition & 1 deletion pkg/hosts/dialer/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type SSHShell struct {
dialer *SSHDialer
}

func (d *SSHShell) Write(b []byte) error {
func (d *SSHShell) Write(_ []byte) error {
return nil
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ func (p *Amazon) SetConfig(config []byte) error {
}

func (p *Amazon) rollbackInstance(ids []string) error {
if err := p.terminateInstance(ids); err != nil {
return err
}
return nil
return p.terminateInstance(ids)
}

func (p *Amazon) generateInstance(ssh *types.SSH) (*types.Cluster, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/providers/k3d/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ func (p *K3d) JoinCheck() error {
}

// GenerateMasterExtraArgs generates K3S master extra args.
func (p *K3d) GenerateMasterExtraArgs(cluster *types.Cluster, master types.Node) string {
func (p *K3d) GenerateMasterExtraArgs(_ *types.Cluster, _ types.Node) string {
return ""
}

// GenerateWorkerExtraArgs generates K3S worker extra args.
func (p *K3d) GenerateWorkerExtraArgs(cluster *types.Cluster, worker types.Node) string {
func (p *K3d) GenerateWorkerExtraArgs(_ *types.Cluster, _ types.Node) string {
return ""
}

Expand Down Expand Up @@ -340,7 +340,7 @@ func (p *K3d) obtainKubeCfg() (kubeCfg, ip string, err error) {
return
}

func (p *K3d) createK3d(ssh *types.SSH) (*types.Cluster, error) {
func (p *K3d) createK3d(_ *types.SSH) (*types.Cluster, error) {
masterNum, _ := strconv.Atoi(p.Master)
workerNum, _ := strconv.Atoi(p.Worker)

Expand Down
8 changes: 4 additions & 4 deletions pkg/providers/native/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func (p *Native) GenerateManifest() []string {
}

// GenerateMasterExtraArgs generates K3S master extra args.
func (p *Native) GenerateMasterExtraArgs(cluster *types.Cluster, master types.Node) string {
func (p *Native) GenerateMasterExtraArgs(_ *types.Cluster, _ types.Node) string {
// no need to support.
return ""
}

// GenerateWorkerExtraArgs generates K3S worker extra args.
func (p *Native) GenerateWorkerExtraArgs(cluster *types.Cluster, worker types.Node) string {
func (p *Native) GenerateWorkerExtraArgs(_ *types.Cluster, _ types.Node) string {
// no need to support.
return ""
}
Expand Down Expand Up @@ -414,7 +414,7 @@ func (p *Native) getInstanceNodes() ([]types.Node, error) {
return nodes, nil
}

func (p *Native) uninstallCluster(f bool) (string, error) {
func (p *Native) uninstallCluster(_ bool) (string, error) {
// don't uninstall cluster if it's not handled by autok3s
if p.Status.Standalone {
p.Logger.Infof("[%s] cluster %s is not handled by autok3s, we won't uninstall the cluster automatically", p.GetProviderName(), p.Name)
Expand All @@ -428,6 +428,6 @@ func (p *Native) uninstallCluster(f bool) (string, error) {
return p.ContextName, nil
}

func (p *Native) isInstanceRunning(state string) bool {
func (p *Native) isInstanceRunning(_ string) bool {
return true
}
7 changes: 2 additions & 5 deletions pkg/providers/tencent/tencent.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ func (p *Tencent) describeVpcTaskResult(taskID uint64) error {
request := vpc.NewDescribeTaskResultRequest()
request.TaskId = tencentCommon.Uint64Ptr(taskID)

if err := wait.ExponentialBackoff(common.Backoff, func() (bool, error) {
return wait.ExponentialBackoff(common.Backoff, func() (bool, error) {
response, err := p.v.DescribeTaskResult(request)
if err != nil {
return false, nil
Expand All @@ -932,10 +932,7 @@ func (p *Tencent) describeVpcTaskResult(taskID uint64) error {
}

return true, nil
}); err != nil {
return err
}
return nil
})
}

func (p *Tencent) getInstanceStatus(aimStatus string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/proxy/k8s_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewK8sProxy() http.Handler {

type errorResponder struct{}

func (r *errorResponder) Error(w http.ResponseWriter, req *http.Request, err error) {
func (r *errorResponder) Error(w http.ResponseWriter, _ *http.Request, err error) {
logrus.Errorf("Error while proxying request: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/store/addon/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, data ty
return a.ByID(apiOp, schema, addon.Name)
}

func (a *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.APIObjectList, error) {
func (a *Store) List(_ *types.APIRequest, schema *types.APISchema) (types.APIObjectList, error) {
result := types.APIObjectList{}
list, err := common.DefaultDB.ListAddon()
if err != nil {
Expand All @@ -62,7 +62,7 @@ func (a *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
return result, nil
}

func (a *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
func (a *Store) ByID(_ *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
addon, err := common.DefaultDB.GetAddon(id)
if err != nil {
return types.APIObject{}, err
Expand Down Expand Up @@ -115,11 +115,11 @@ func (a *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, data ty
return a.ByID(apiOp, schema, id)
}

func (a *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
func (a *Store) Delete(_ *types.APIRequest, _ *types.APISchema, id string) (types.APIObject, error) {
err := common.DefaultDB.DeleteAddon(id)
return types.APIObject{}, err
}

func (a *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, wr types.WatchRequest) (chan types.APIEvent, error) {
func (a *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, _ types.WatchRequest) (chan types.APIEvent, error) {
return common.DefaultDB.Watch(apiOp, schema), nil
}
8 changes: 4 additions & 4 deletions pkg/server/store/cluster/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func LinkCluster(request *types.APIRequest) (types.APIObject, error) {

type join struct{}

func (j join) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
func (j join) ServeHTTP(_ http.ResponseWriter, req *http.Request) {
apiRequest := types.GetAPIContext(req.Context())
clusterID := apiRequest.Name
if clusterID == "" {
Expand Down Expand Up @@ -137,7 +137,7 @@ func (j join) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
apiRequest.WriteResponse(http.StatusOK, types.APIObject{})
}

func nodesHandler(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
func nodesHandler(_ *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
state, err := common.DefaultDB.GetClusterByID(id)
if err != nil || state == nil {
// find from failed cluster.
Expand All @@ -163,7 +163,7 @@ func nodesHandler(apiOp *types.APIRequest, schema *types.APISchema, id string) (

type explorer struct{}

func (e explorer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
func (e explorer) ServeHTTP(_ http.ResponseWriter, req *http.Request) {
apiRequest := types.GetAPIContext(req.Context())
clusterID := apiRequest.Name
if clusterID == "" {
Expand Down Expand Up @@ -198,7 +198,7 @@ func (e explorer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

type downloadKubeconfig struct{}

func (d downloadKubeconfig) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
func (d downloadKubeconfig) ServeHTTP(_ http.ResponseWriter, req *http.Request) {
apiRequest := types.GetAPIContext(req.Context())
vars := mux.Vars(req)
clusterID := vars["name"]
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/store/cluster/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Store struct {
}

// Create creates cluster based on the request data.
func (c *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, data types.APIObject) (types.APIObject, error) {
func (c *Store) Create(_ *types.APIRequest, schema *types.APISchema, data types.APIObject) (types.APIObject, error) {
providerName := data.Data().String("provider")
b, err := json.Marshal(data.Data())
if err != nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ func (c *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
}

// ByID returns cluster by ID.
func (c *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
func (c *Store) ByID(_ *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
state, err := common.DefaultDB.GetClusterByID(id)
if err != nil || state == nil {
return types.APIObject{}, apierror.NewAPIError(validation.NotFound, fmt.Sprintf("cluster %s is not found, got error: %v", id, err))
Expand Down Expand Up @@ -121,7 +121,7 @@ func (c *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string
}

// Delete deletes cluster by ID.
func (c *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id string) (types.APIObject, error) {
func (c *Store) Delete(_ *types.APIRequest, _ *types.APISchema, id string) (types.APIObject, error) {
state, err := common.DefaultDB.GetClusterByID(id)
if err != nil || state == nil {
return types.APIObject{}, apierror.NewAPIError(validation.NotFound, fmt.Sprintf("cluster %s is not found, got error: %v", id, err))
Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *Store) Delete(apiOp *types.APIRequest, schema *types.APISchema, id stri
}

// Watch watches cluster change event.
func (c *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.WatchRequest) (chan types.APIEvent, error) {
func (c *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, _ types.WatchRequest) (chan types.APIEvent, error) {
result := make(chan types.APIEvent)
data := common.DefaultDB.Watch(apiOp, schema)
go func() {
Expand Down
Loading

0 comments on commit be99484

Please sign in to comment.