1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-27 02:51:10 +00:00

Adding validate phase to the CI

Adds a validate phase to the CI which runs a linter. Also fixes
linter issues discovered during the initial run
This commit is contained in:
Michael Bolot 2022-10-14 15:21:17 -05:00
parent 7e4a51bda0
commit b73cc57b20
15 changed files with 128 additions and 37 deletions

View File

@ -29,6 +29,22 @@ steps:
- pull_request
---
kind: pipeline
name: validate
steps:
- name: validate
image: registry.suse.com/bci/bci-base:15.4
commands:
- zypper in -y go=1.19 git tar gzip make
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.49.0
- mv ./bin/golangci-lint /usr/local/bin/golangci-lint
- make validate
when:
event:
- push
- pull_request
---
kind: pipeline
name: test
steps:

67
.golangci.json Normal file
View File

@ -0,0 +1,67 @@
{
"linters": {
"disable-all": true,
"enable": [
"govet",
"revive",
"goimports",
"misspell",
"ineffassign",
"gofmt"
]
},
"linters-settings": {
"govet": {
"check-shadowing": false
},
"gofmt": {
"simplify": false
}
},
"run": {
"skip-dirs": [
"vendor",
"tests",
"pkg/client",
"pkg/generated"
],
"tests": false,
"timeout": "10m"
},
"issues": {
"exclude-rules": [
{
"linters": "govet",
"text": "^(nilness|structtag)"
},
{
"path":"pkg/apis/management.cattle.io/v3/globaldns_types.go",
"text":".*lobalDns.*"
},
{
"path": "pkg/apis/management.cattle.io/v3/zz_generated_register.go",
"text":".*lobalDns.*"
},
{
"path":"pkg/apis/management.cattle.io/v3/zz_generated_list_types.go",
"text":".*lobalDns.*"
},
{
"linters": "revive",
"text": "should have comment"
},
{
"linters": "revive",
"text": "should be of the form"
},
{
"linters": "revive",
"text": "by other packages, and that stutters"
},
{
"linters": "typecheck",
"text": "imported but not used as apierrors"
}
]
}
}

View File

@ -12,3 +12,6 @@ run-host: build
test:
bash scripts/test.sh
validate:
bash scripts/validate.sh

View File

@ -1,12 +1,12 @@
package cli
import (
"k8s.io/client-go/tools/clientcmd"
"os"
"time"
"github.com/rancher/steve/pkg/auth"
"github.com/urfave/cli"
"k8s.io/client-go/tools/clientcmd"
)
type WebhookConfig struct {

View File

@ -2,7 +2,6 @@ package auth
import (
"io/ioutil"
"k8s.io/client-go/rest"
"net/http"
"strings"
"time"
@ -13,6 +12,7 @@ import (
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/plugin/pkg/authenticator/token/webhook"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/transport"

View File

@ -280,7 +280,7 @@ func removeSummary(counts Summary, summary summary.Summary) Summary {
if counts.States == nil {
counts.States = map[string]int{}
}
counts.States[simpleState(summary)] -= 1
counts.States[simpleState(summary)]--
}
return counts
}
@ -297,7 +297,7 @@ func addSummary(counts Summary, summary summary.Summary) Summary {
if counts.States == nil {
counts.States = map[string]int{}
}
counts.States[simpleState(summary)] += 1
counts.States[simpleState(summary)]++
}
return counts
}

View File

@ -6,7 +6,7 @@ import (
"github.com/rancher/steve/pkg/schema/table"
apiextv1 "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1"
"github.com/rancher/wrangler/pkg/schemas"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

View File

@ -5,7 +5,7 @@ import (
"strings"
"github.com/rancher/apiserver/pkg/types"
"github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1"
v1 "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
)

View File

@ -41,11 +41,11 @@ func (c *Collection) Schemas(user user.Info) (*types.APISchemas, error) {
func (c *Collection) removeOldRecords(access *accesscontrol.AccessSet, user user.Info) {
current, ok := c.userCache.Get(user.GetName())
if ok {
currentId, cOk := current.(string)
if cOk && currentId != access.ID {
currentID, cOk := current.(string)
if cOk && currentID != access.ID {
// we only want to keep around one record per user. If our current access record is invalid, purge the
//record of it from the cache, so we don't keep duplicates
c.purgeUserRecords(currentId)
c.purgeUserRecords(currentID)
c.userCache.Remove(user.GetName())
}
}

View File

@ -9,11 +9,6 @@ import (
func k8sAPI(sf schema.Factory, apiOp *types.APIRequest) {
vars := mux.Vars(apiOp.Request)
group := vars["group"]
if group == "core" {
group = ""
}
apiOp.Name = vars["name"]
apiOp.Type = vars["type"]

View File

@ -170,7 +170,7 @@ func (p *ParallelPartitionLister) feeder(ctx context.Context, state listState, l
}
capacity = 0
return nil
} else {
}
result <- list.Objects
capacity -= len(list.Objects)
if list.Continue == "" {
@ -181,7 +181,6 @@ func (p *ParallelPartitionLister) feeder(ctx context.Context, state listState, l
state.PartitionName = partition.Name()
state.Offset = 0
}
}
})
}

View File

@ -166,7 +166,7 @@ func isPassthroughUnconstrained(apiOp *types.APIRequest, schema *types.APISchema
if apiOp.Namespace != "" {
if resources[apiOp.Namespace].All {
return nil, true
} else {
}
return []partition.Partition{
Partition{
Namespace: apiOp.Namespace,
@ -174,7 +174,6 @@ func isPassthroughUnconstrained(apiOp *types.APIRequest, schema *types.APISchema
},
}, false
}
}
var result []partition.Partition

12
scripts/validate.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
set -e
golangci-lint run
go mod tidy
go mod verify
unclean=$(git status --porcelain --untracked-files=no)
if [ -n "$unclean" ]; then
echo "Encountered dirty repo!";
echo "$unclean";
exit 1;
fi