mirror of
https://github.com/rancher/steve.git
synced 2025-04-27 11:00:48 +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:
parent
7e4a51bda0
commit
b73cc57b20
16
.drone.yml
16
.drone.yml
@ -29,6 +29,22 @@ steps:
|
|||||||
- pull_request
|
- pull_request
|
||||||
---
|
---
|
||||||
kind: pipeline
|
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
|
name: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
67
.golangci.json
Normal file
67
.golangci.json
Normal 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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
3
Makefile
3
Makefile
@ -12,3 +12,6 @@ run-host: build
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
bash scripts/test.sh
|
bash scripts/test.sh
|
||||||
|
|
||||||
|
validate:
|
||||||
|
bash scripts/validate.sh
|
@ -1,12 +1,12 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rancher/steve/pkg/auth"
|
"github.com/rancher/steve/pkg/auth"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebhookConfig struct {
|
type WebhookConfig struct {
|
||||||
|
@ -2,7 +2,6 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"k8s.io/client-go/rest"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -13,6 +12,7 @@ import (
|
|||||||
"k8s.io/apiserver/pkg/authentication/user"
|
"k8s.io/apiserver/pkg/authentication/user"
|
||||||
"k8s.io/apiserver/pkg/endpoints/request"
|
"k8s.io/apiserver/pkg/endpoints/request"
|
||||||
"k8s.io/apiserver/plugin/pkg/authenticator/token/webhook"
|
"k8s.io/apiserver/plugin/pkg/authenticator/token/webhook"
|
||||||
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
"k8s.io/client-go/transport"
|
"k8s.io/client-go/transport"
|
||||||
|
@ -280,7 +280,7 @@ func removeSummary(counts Summary, summary summary.Summary) Summary {
|
|||||||
if counts.States == nil {
|
if counts.States == nil {
|
||||||
counts.States = map[string]int{}
|
counts.States = map[string]int{}
|
||||||
}
|
}
|
||||||
counts.States[simpleState(summary)] -= 1
|
counts.States[simpleState(summary)]--
|
||||||
}
|
}
|
||||||
return counts
|
return counts
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ func addSummary(counts Summary, summary summary.Summary) Summary {
|
|||||||
if counts.States == nil {
|
if counts.States == nil {
|
||||||
counts.States = map[string]int{}
|
counts.States = map[string]int{}
|
||||||
}
|
}
|
||||||
counts.States[simpleState(summary)] += 1
|
counts.States[simpleState(summary)]++
|
||||||
}
|
}
|
||||||
return counts
|
return counts
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/rancher/steve/pkg/schema/table"
|
"github.com/rancher/steve/pkg/schema/table"
|
||||||
apiextv1 "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1"
|
apiextv1 "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1"
|
||||||
"github.com/rancher/wrangler/pkg/schemas"
|
"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"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
)
|
)
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rancher/apiserver/pkg/types"
|
"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/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/discovery"
|
||||||
)
|
)
|
||||||
|
@ -41,11 +41,11 @@ func (c *Collection) Schemas(user user.Info) (*types.APISchemas, error) {
|
|||||||
func (c *Collection) removeOldRecords(access *accesscontrol.AccessSet, user user.Info) {
|
func (c *Collection) removeOldRecords(access *accesscontrol.AccessSet, user user.Info) {
|
||||||
current, ok := c.userCache.Get(user.GetName())
|
current, ok := c.userCache.Get(user.GetName())
|
||||||
if ok {
|
if ok {
|
||||||
currentId, cOk := current.(string)
|
currentID, cOk := current.(string)
|
||||||
if cOk && currentId != access.ID {
|
if cOk && currentID != access.ID {
|
||||||
// we only want to keep around one record per user. If our current access record is invalid, purge the
|
// 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
|
//record of it from the cache, so we don't keep duplicates
|
||||||
c.purgeUserRecords(currentId)
|
c.purgeUserRecords(currentID)
|
||||||
c.userCache.Remove(user.GetName())
|
c.userCache.Remove(user.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,6 @@ import (
|
|||||||
|
|
||||||
func k8sAPI(sf schema.Factory, apiOp *types.APIRequest) {
|
func k8sAPI(sf schema.Factory, apiOp *types.APIRequest) {
|
||||||
vars := mux.Vars(apiOp.Request)
|
vars := mux.Vars(apiOp.Request)
|
||||||
group := vars["group"]
|
|
||||||
if group == "core" {
|
|
||||||
group = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
apiOp.Name = vars["name"]
|
apiOp.Name = vars["name"]
|
||||||
apiOp.Type = vars["type"]
|
apiOp.Type = vars["type"]
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func (p *ParallelPartitionLister) feeder(ctx context.Context, state listState, l
|
|||||||
}
|
}
|
||||||
capacity = 0
|
capacity = 0
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
result <- list.Objects
|
result <- list.Objects
|
||||||
capacity -= len(list.Objects)
|
capacity -= len(list.Objects)
|
||||||
if list.Continue == "" {
|
if list.Continue == "" {
|
||||||
@ -181,7 +181,6 @@ func (p *ParallelPartitionLister) feeder(ctx context.Context, state listState, l
|
|||||||
state.PartitionName = partition.Name()
|
state.PartitionName = partition.Name()
|
||||||
state.Offset = 0
|
state.Offset = 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ func isPassthroughUnconstrained(apiOp *types.APIRequest, schema *types.APISchema
|
|||||||
if apiOp.Namespace != "" {
|
if apiOp.Namespace != "" {
|
||||||
if resources[apiOp.Namespace].All {
|
if resources[apiOp.Namespace].All {
|
||||||
return nil, true
|
return nil, true
|
||||||
} else {
|
}
|
||||||
return []partition.Partition{
|
return []partition.Partition{
|
||||||
Partition{
|
Partition{
|
||||||
Namespace: apiOp.Namespace,
|
Namespace: apiOp.Namespace,
|
||||||
@ -174,7 +174,6 @@ func isPassthroughUnconstrained(apiOp *types.APIRequest, schema *types.APISchema
|
|||||||
},
|
},
|
||||||
}, false
|
}, false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var result []partition.Partition
|
var result []partition.Partition
|
||||||
|
|
||||||
|
12
scripts/validate.sh
Normal file
12
scripts/validate.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user