Skip to content

Commit

Permalink
Merge pull request #218 from ffromani/add-golangci-lint
Browse files Browse the repository at this point in the history
golangci-lint add developer config and related fixes
  • Loading branch information
swatisehgal authored Sep 22, 2023
2 parents adf579d + 8b72776 commit a039483
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 17 deletions.
36 changes: 36 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
run:
timeout: 5m
tests: false
skip-dirs:
- vendor
- test
modules-download-mode: vendor
linters:
disable-all: true
enable:
- errcheck
- bodyclose
- exportloopref
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- nosprintfhostport
- staticcheck
- tenv
- typecheck
- unconvert
- unused
- wastedassign
- whitespace
linters-settings:
misspell:
locale: US
ignore-words:
- NRO
- nro
- numaresource
- numa
- NUMA

22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
BINDIR=_out

GOLANGCI_LINT_VERSION=1.54.2
GOLANGCI_LINT_BIN=$(BINDIR)/golangci-lint
GOLANGCI_LINT_VERSION_TAG=v${GOLANGCI_LINT_VERSION}

all: deployer

.PHONY: vet
Expand Down Expand Up @@ -59,9 +65,25 @@ gofmt:
@echo "Running gofmt"
gofmt -s -w `find . -path ./vendor -prune -o -type f -name '*.go' -print`

# this is meant for developers only.
# DO NOT WIRE THIS IN CI! Let's use https://golangci-lint.run/usage/install/#github-actions instead
.PHONY: dev-lint
dev-lint: _out/golangci-lint
$(GOLANGCI_LINT_BIN) run

.PHONY: build-e2e
build-e2e: _out/e2e.test

_out/e2e.test: outdir test/e2e/*.go
go test -v -c -o _out/e2e.test ./test/e2e/

_out/golangci-lint: outdir
@if [ ! -x "$(GOLANGCI_LINT_BIN)" ]; then\
echo "Downloading golangci-lint $(GOLANGCI_LINT_VERSION)";\
curl -JL https://github.com/golangci/golangci-lint/releases/download/$(GOLANGCI_LINT_VERSION_TAG)/golangci-lint-$(GOLANGCI_LINT_VERSION)-linux-amd64.tar.gz -o _out/golangci-lint-$(GOLANGCI_LINT_VERSION)-linux-amd64.tar.gz;\
tar xz -C _out -f _out/golangci-lint-$(GOLANGCI_LINT_VERSION)-linux-amd64.tar.gz;\
ln -sf golangci-lint-1.54.2-linux-amd64/golangci-lint _out/golangci-lint;\
else\
echo "Using golangci-lint cached at $(GOLANGCI_LINT_BIN)";\
fi

2 changes: 1 addition & 1 deletion cmd/deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewVersionCommand(env *deployer.Environment, commonOpts *deploy.Options) *c
opts := versionOptions{}
version := &cobra.Command{
Use: "version",
Short: "emit the version and exits succesfully",
Short: "emit the version and exits successfully",
RunE: func(cmd *cobra.Command, args []string) error {
if opts.hashOnly {
fmt.Printf("%s\n", deployerversion.GitCommit)
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewRenderCommand(env *deployer.Environment, commonOpts *deploy.Options) *co
Short: "render all the manifests",
RunE: func(cmd *cobra.Command, args []string) error {
if commonOpts.UserPlatform == platform.Unknown {
return fmt.Errorf("must explicitely select a cluster platform")
return fmt.Errorf("must explicitly select a cluster platform")
}
return RenderManifests(env, commonOpts)
},
Expand All @@ -59,7 +59,7 @@ func NewRenderAPICommand(env *deployer.Environment, commonOpts *deploy.Options,
Short: "render the APIs needed for topology-aware-scheduling",
RunE: func(cmd *cobra.Command, args []string) error {
if commonOpts.UserPlatform == platform.Unknown {
return fmt.Errorf("must explicitely select a cluster platform")
return fmt.Errorf("must explicitly select a cluster platform")
}
apiManifests, err := api.GetManifests(commonOpts.UserPlatform)
if err != nil {
Expand All @@ -82,7 +82,7 @@ func NewRenderSchedulerPluginCommand(env *deployer.Environment, commonOpts *depl
Short: "render the scheduler plugin needed for topology-aware-scheduling",
RunE: func(cmd *cobra.Command, args []string) error {
if commonOpts.UserPlatform == platform.Unknown {
return fmt.Errorf("must explicitely select a cluster platform")
return fmt.Errorf("must explicitly select a cluster platform")
}

_, namespace, err := updaters.SetupNamespace(commonOpts.UpdaterType)
Expand Down Expand Up @@ -116,7 +116,7 @@ func NewRenderTopologyUpdaterCommand(env *deployer.Environment, commonOpts *depl
Short: "render the topology updater needed for topology-aware-scheduling",
RunE: func(cmd *cobra.Command, args []string) error {
if commonOpts.UserPlatform == platform.Unknown {
return fmt.Errorf("must explicitely select a cluster platform")
return fmt.Errorf("must explicitly select a cluster platform")
}
objs, _, err := makeUpdaterObjects(commonOpts)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (
type internalOptions struct {
rteConfigFile string
plat string
platVer string
}

func ShowHelp(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 0 additions & 1 deletion pkg/deployer/updaters/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
)

func GetObjects(opts Options, updaterType, namespace string) ([]client.Object, error) {

if updaterType == RTE {
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace, opts.EnableCRIHooks)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/flagcodec/flagcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// flagcodec allows to manipulate foreign command lines following the
// standard golang conventions. It offeres two-way processing aka
// parsing/marshalling of flags. It is different from the other, well
// parsing/marshaling of flags. It is different from the other, well
// established packages (pflag...) because it aims to manipulate command
// lines in general, not this program command line.

Expand Down Expand Up @@ -49,7 +49,7 @@ func ParseArgvKeyValue(args []string) *Flags {

// ParseArgvKeyValue parses a clean (trimmed) argv whose components are
// either toggles or key=value pairs. IOW, this is a restricted and easier
// to parse flavour of argv on which option and value are guaranteed to
// to parse flavor of argv on which option and value are guaranteed to
// be in the same item.
// IOW, we expect
// "--opt=foo"
Expand Down
8 changes: 4 additions & 4 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ func makeIgnitionConfig(ver platform.Version, withCRIHooks bool) ([]byte, error)
Systemd: igntypes.Systemd{
Units: []igntypes.Unit{
{
Contents: pointer.StringPtr(string(systemdServiceContent)),
Enabled: pointer.BoolPtr(true),
Contents: pointer.String(string(systemdServiceContent)),
Enabled: pointer.Bool(true),
Name: selinuxassets.RTEPolicyInstallServiceName,
},
},
Expand All @@ -405,9 +405,9 @@ func addFileToIgnitionConfig(files []igntypes.File, fileContent []byte, mode int
},
FileEmbedded1: igntypes.FileEmbedded1{
Contents: igntypes.Resource{
Source: pointer.StringPtr(fmt.Sprintf("%s,%s", defaultIgnitionContentSource, base64FileContent)),
Source: pointer.String(fmt.Sprintf("%s,%s", defaultIgnitionContentSource, base64FileContent)),
},
Mode: pointer.IntPtr(mode),
Mode: pointer.Int(mode),
},
})

Expand Down
2 changes: 1 addition & 1 deletion pkg/objectupdate/nfd/nfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func UpdaterDaemonSet(ds *appsv1.DaemonSet, opts objectupdate.DaemonSetOptions)

flags.SetOption("--pods-fingerprint", strconv.FormatBool(opts.PFPEnable))

// we need to explicitely disable the kubelet state dir monitoring, which is opt-out
// we need to explicitly disable the kubelet state dir monitoring, which is opt-out
flags.SetOption("--kubelet-state-dir", "")

c.Args = flags.Argv()
Expand Down
1 change: 0 additions & 1 deletion pkg/objectupdate/rte/rte.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func ContainerConfig(podSpec *corev1.PodSpec, cnt *corev1.Container, configMapNa
func DaemonSet(ds *appsv1.DaemonSet, plat platform.Platform, configMapName string, opts objectupdate.DaemonSetOptions) {
podSpec := &ds.Spec.Template.Spec
if cntSpec := objectupdate.FindContainerByName(ds.Spec.Template.Spec.Containers, manifests.ContainerNameRTE); cntSpec != nil {

cntSpec.Image = images.ResourceTopologyExporterImage

cntSpec.ImagePullPolicy = corev1.PullAlways
Expand Down
2 changes: 1 addition & 1 deletion pkg/objectupdate/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func SchedulerConfig(cm *corev1.ConfigMap, schedulerName string, cacheResyncPeri
return err
}

cm.Data[SchedulerConfigFileName] = string(newData)
cm.Data[SchedulerConfigFileName] = newData
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/stringify/noderesourcetopology.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NodeResourceTopologyList(nrts []nrtv1alpha2.NodeResourceTopology, tag strin
}
fmt.Fprintf(&b, "\n")
for idx := range nrts {
fmt.Fprintf(&b, NodeResourceTopology(nrts[idx]))
fmt.Fprint(&b, NodeResourceTopology(nrts[idx]))
}
fmt.Fprintf(&b, "NRT END dump\n")
return b.String()
Expand Down

0 comments on commit a039483

Please sign in to comment.