Skip to content

Commit

Permalink
build: add staticcheck (#3353)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Jan 10, 2023
1 parent cdad4b5 commit 1fa567f
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 10 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ ifeq ($(wildcard $(SKAFFOLD)),)
@mv skaffold ./bin/
endif

STATICCHECK = $(PROJECT_DIR)/bin/staticcheck
.PHONY: staticcheck
staticcheck.download: ## Download staticcheck locally if necessary.
@$(MAKE) _download_tool TOOL=staticcheck

# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -114,9 +119,15 @@ vet:
go vet ./...

.PHONY: lint
lint: verify.tidy golangci-lint
lint: verify.tidy golangci-lint staticcheck
$(GOLANGCI_LINT) run -v

.PHONY: staticcheck
staticcheck: staticcheck.download
$(STATICCHECK) -tags e2e_tests,integration_tests,istio_tests,conformance_tests \
-f stylish \
./...

.PHONY: verify.tidy
verify.tidy:
./scripts/verify-tidy.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/configuration.konghq.com_kongingresses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ spec:
allow. Deprecated: use Ingress'' "konghq.com/protocols" annotation
instead.'
items:
description: KongProtocol is a valid Kong protocol This alias is
necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/configuration.konghq.com_kongplugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -411,6 +413,8 @@ spec:
allow. Deprecated: use Ingress'' "konghq.com/protocols" annotation
instead.'
items:
description: KongProtocol is a valid Kong protocol This alias is
necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -753,6 +757,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -411,6 +413,8 @@ spec:
allow. Deprecated: use Ingress'' "konghq.com/protocols" annotation
instead.'
items:
description: KongProtocol is a valid Kong protocol This alias is
necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -753,6 +757,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
6 changes: 6 additions & 0 deletions deploy/single/all-in-one-postgres-enterprise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -411,6 +413,8 @@ spec:
allow. Deprecated: use Ingress'' "konghq.com/protocols" annotation
instead.'
items:
description: KongProtocol is a valid Kong protocol This alias is
necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -753,6 +757,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
6 changes: 6 additions & 0 deletions deploy/single/all-in-one-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -411,6 +413,8 @@ spec:
allow. Deprecated: use Ingress'' "konghq.com/protocols" annotation
instead.'
items:
description: KongProtocol is a valid Kong protocol This alias is
necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down Expand Up @@ -753,6 +757,8 @@ spec:
description: Protocols configures plugin to run on requests received on
specific protocols.
items:
description: KongProtocol is a valid Kong protocol This alias is necessary
to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
enum:
- http
- https
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ _Appears in:_

_Underlying type:_ `string`


KongProtocol is a valid Kong protocol This alias is necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342



Expand Down
2 changes: 1 addition & 1 deletion internal/dataplane/parser/translators/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type KongRouteTranslation struct {
Filters []gatewayv1beta1.HTTPRouteFilter
}

// TranslateHTTPRoutes translates a list of HTTPRoutes into a list of HTTPRouteTranslationMeta
// TranslateHTTPRoute translates a list of HTTPRoutes into a list of HTTPRouteTranslationMeta
// objects that can be used to instantiate Kong routes and services.
// The translation is done by grouping the HTTPRoutes by their backendRefs.
// This means that all the rules of a single HTTPRoute will be grouped together
Expand Down
5 changes: 4 additions & 1 deletion internal/dataplane/parser/wrappers_backendref.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ func backendRefsToKongStateBackends[T types.BackendRefT](
// these, we do not want a single impermissible ref to take the entire rule offline. in the case of edits,
// failing the entire rule could potentially delete routes that were previously online and in use, and
// that remain viable (because they still have some permissible backendRefs)
var namespace, kind string = route.GetNamespace(), ""
var (
namespace = route.GetNamespace()
kind string
)
if brw.Namespace() != nil {
namespace = *brw.Namespace()
}
Expand Down
3 changes: 1 addition & 2 deletions internal/manager/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/utils"
ctrlutils "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/utils"
)

Expand Down Expand Up @@ -102,7 +101,7 @@ func negotiateIngressAPI(config *Config, mapper meta.RESTMapper) (IngressAPI, er
}

func ShouldEnableCRDController(gvr schema.GroupVersionResource, restMapper meta.RESTMapper) bool {
if !utils.CRDExists(restMapper, gvr) {
if !ctrlutils.CRDExists(restMapper, gvr) {
ctrl.Log.WithName("controllers").WithName("crdCondition").
Info(fmt.Sprintf("disabling the '%s' controller due to missing CRD installation", gvr.Resource))
return false
Expand Down
3 changes: 2 additions & 1 deletion internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ func (s Store) GetIngressClassV1(name string) (*netv1.IngressClass, error) {
return p.(*netv1.IngressClass), nil
}

// GetIngressClassV1 returns the 'name' IngressClass resource.
// GetIngressClassParametersV1Alpha1 returns IngressClassParameters of configured
// IngressClass.
func (s Store) GetIngressClassParametersV1Alpha1() (*kongv1alpha1.IngressClassParameters, error) {
class, exists, err := s.stores.IngressClassV1.GetByKey(s.ingressClass)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/util/test/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ ctFsgXhf5+tDgbBZpcuTMpd3KnaDUYg=
// from which 192.168.5.2 routes to the host (https://github.com/abiosoft/colima/issues/220)
//
// This works if the test runs against a KIND cluster, and does not work against cloud providers (like GKE).

var AdmissionWebhookListenHost = admissionWebhookListenHost()

const (
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/configuration/v1/kongprotocol_types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1

// + KongProtocol is a valid Kong protocol
// + This alias is necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
// KongProtocol is a valid Kong protocol
// This alias is necessary to deal with https://github.com/kubernetes-sigs/controller-tools/issues/342
// +kubebuilder:validation:Enum=http;https;grpc;grpcs;tcp;tls;udp
// +kubebuilder:object:generate=true
type KongProtocol string
Expand Down
2 changes: 2 additions & 0 deletions staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Configuration options described in: https://staticcheck.io/docs/configuration/options/
checks = ["all", "-ST1000", "-ST1005"]
2 changes: 1 addition & 1 deletion third_party/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/go-delve/delve v1.20.1
github.com/golangci/golangci-lint v1.50.1
gotest.tools/gotestsum v1.8.2
honnef.co/go/tools v0.3.3
k8s.io/code-generator v0.26.0
sigs.k8s.io/controller-tools v0.11.1
sigs.k8s.io/kustomize/kustomize/v4 v4.5.7
Expand Down Expand Up @@ -220,7 +221,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.3.3 // indirect
k8s.io/api v0.26.0 // indirect
k8s.io/apiextensions-apiserver v0.26.0 // indirect
k8s.io/apimachinery v0.26.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions third_party/staticcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build third_party
// +build third_party

package third_party

import (
_ "honnef.co/go/tools/cmd/staticcheck"
)

//go:generate go install -modfile go.mod honnef.co/go/tools/cmd/staticcheck

0 comments on commit 1fa567f

Please sign in to comment.