Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
settings:
gci:
sections:
- standard
- default
- localmodule
goimports:
local-prefixes:
- k8s.io/node-problem-detector
exclusions:
generated: lax
paths:
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ vet:
grep -v "./vendor/*" | \
xargs go vet -tags "$(HOST_PLATFORM_BUILD_TAGS)"

fmt:
fmt: $(GOLANGCI_LINT)
find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l
$(GOLANGCI_LINT) run --config .golangci.yml --fix ./...

version:
@echo $(VERSION)
Expand Down
2 changes: 1 addition & 1 deletion cmd/healthchecker/health_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"os"

"github.com/spf13/pflag"

"k8s.io/klog/v2"

"k8s.io/node-problem-detector/cmd/healthchecker/options"
"k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
"k8s.io/node-problem-detector/pkg/healthchecker"
Expand Down
5 changes: 2 additions & 3 deletions cmd/nodeproblemdetector/node_problem_detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func init() {
})
}

type nullExporter struct {
}
type nullExporter struct{}

func (ne *nullExporter) ExportProblems(*types.Status) {
}
Expand All @@ -96,7 +95,7 @@ func writeTempFile(t *testing.T, ext string, contents string) (string, error) {

fileName := f.Name()

if err := os.WriteFile(fileName, []byte(contents), 0644); err != nil {
if err := os.WriteFile(fileName, []byte(contents), 0o644); err != nil {
os.Remove(fileName)
return "", fmt.Errorf("cannot write config to temp file %s, %v", fileName, err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/nodeproblemdetector/node_problem_detector_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/spf13/pflag"
"k8s.io/klog/v2"

"k8s.io/node-problem-detector/cmd/options"
)

Expand Down
3 changes: 1 addition & 2 deletions cmd/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ package options
import (
"flag"
"fmt"
"net/url"
"os"
"time"

"net/url"

"github.com/spf13/pflag"

"k8s.io/node-problem-detector/pkg/exporters"
Expand Down
3 changes: 2 additions & 1 deletion pkg/custompluginmonitor/custom_plugin_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func init() {
CustomPluginMonitorName,
types.ProblemDaemonHandler{
CreateProblemDaemonOrDie: NewCustomPluginMonitorOrDie,
CmdOptionDescription: "Set to config file paths."})
CmdOptionDescription: "Set to config file paths.",
})
}

type customPluginMonitor struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/custompluginmonitor/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"k8s.io/klog/v2"

cpmtypes "k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
"k8s.io/node-problem-detector/pkg/util"
"k8s.io/node-problem-detector/pkg/util/tomb"
Expand Down
7 changes: 4 additions & 3 deletions pkg/custompluginmonitor/types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ func TestCustomPluginConfigApplyConfiguration(t *testing.T) {
},
},
"disable status update during initialization": {
Orig: CustomPluginConfig{PluginGlobalConfig: pluginGlobalConfig{
SkipInitialStatus: &disableInitialStatusUpdate,
},
Orig: CustomPluginConfig{
PluginGlobalConfig: pluginGlobalConfig{
SkipInitialStatus: &disableInitialStatusUpdate,
},
},
Wanted: CustomPluginConfig{
PluginGlobalConfig: pluginGlobalConfig{
Expand Down
9 changes: 4 additions & 5 deletions pkg/exporters/k8sexporter/condition/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import (
"sync"
"time"

"k8s.io/node-problem-detector/pkg/exporters/k8sexporter/problemclient"
"k8s.io/node-problem-detector/pkg/types"
problemutil "k8s.io/node-problem-detector/pkg/util"

v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
"k8s.io/utils/clock"

"k8s.io/klog/v2"
"k8s.io/node-problem-detector/pkg/exporters/k8sexporter/problemclient"
"k8s.io/node-problem-detector/pkg/types"
problemutil "k8s.io/node-problem-detector/pkg/util"
)

const (
Expand Down
5 changes: 2 additions & 3 deletions pkg/exporters/k8sexporter/condition/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import (
"time"

"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
testclock "k8s.io/utils/clock/testing"

"k8s.io/node-problem-detector/pkg/exporters/k8sexporter/problemclient"
"k8s.io/node-problem-detector/pkg/types"
problemutil "k8s.io/node-problem-detector/pkg/util"

v1 "k8s.io/api/core/v1"
testclock "k8s.io/utils/clock/testing"
)

const heartbeatPeriod = 1 * time.Minute
Expand Down
3 changes: 1 addition & 2 deletions pkg/exporters/k8sexporter/k8s_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
"net/http/pprof"
"strconv"

"k8s.io/klog/v2"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/utils/clock"

"k8s.io/node-problem-detector/cmd/options"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"
testclock "k8s.io/utils/clock/testing"

"github.com/stretchr/testify/assert"
)

const (
Expand Down
4 changes: 1 addition & 3 deletions pkg/exporters/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"k8s.io/node-problem-detector/pkg/types"
)

var (
handlers = make(map[types.ExporterType]types.ExporterHandler)
)
var handlers = make(map[types.ExporterType]types.ExporterHandler)

// Register registers a exporter factory method, which will be used to create the exporter.
func Register(exporterType types.ExporterType, handler types.ExporterHandler) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/exporters/stackdriver/stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (

"contrib.go.opencensus.io/exporter/stackdriver"
monitoredres "contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
"github.com/avast/retry-go/v4"
"github.com/spf13/pflag"
"go.opencensus.io/stats/view"
"google.golang.org/api/option"
"k8s.io/klog/v2"

"github.com/avast/retry-go/v4"
"k8s.io/node-problem-detector/pkg/exporters"
seconfig "k8s.io/node-problem-detector/pkg/exporters/stackdriver/config"
"k8s.io/node-problem-detector/pkg/types"
Expand All @@ -41,7 +41,8 @@ func init() {
clo := commandLineOptions{}
exporters.Register(exporterName, types.ExporterHandler{
CreateExporterOrDie: NewExporterOrDie,
Options: &clo})
Options: &clo,
})
}

const exporterName = "stackdriver"
Expand Down Expand Up @@ -95,7 +96,6 @@ var NPDMetricToSDMetric = map[metrics.MetricID]string{
}

func getMetricTypeConversionFunction(customMetricPrefix string) func(*view.View) string {

return func(view *view.View) string {
viewName := view.Measure.Name()

Expand Down
1 change: 1 addition & 0 deletions pkg/healthchecker/health_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"k8s.io/klog/v2"

"k8s.io/node-problem-detector/cmd/healthchecker/options"
"k8s.io/node-problem-detector/pkg/healthchecker/types"
)
Expand Down
1 change: 0 additions & 1 deletion pkg/healthchecker/health_checker_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func getUptimeFunc(service string) func() (time.Duration, error) {
// RestartSec of systemd and invoke interval of plugin got in sync. The service was repeatedly killed in
// activating state and hence ActiveEnterTimestamp was never updated.
out, err := execCommand(types.CmdTimeout, "systemctl", "show", service, "--property=InactiveExitTimestamp")

if err != nil {
return time.Duration(0), err
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/healthchecker/health_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ func TestComponentsSupported(t *testing.T) {
if checkFunc == nil {
t.Errorf("component %v should be supported", tc.component)
}

})
}

}
2 changes: 1 addition & 1 deletion pkg/healthchecker/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func setKubeEndpoints() {

kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeletPort))
kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeProxyPort))

}

func KubeProxyHealthCheckEndpoint() string {
return kubeProxyHealthCheckEndpoint
}

func KubeletHealthCheckEndpoint() string {
return kubeletHealthCheckEndpoint
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/problemdaemon/problem_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import (
"k8s.io/node-problem-detector/pkg/types"
)

var (
handlers = make(map[types.ProblemDaemonType]types.ProblemDaemonHandler)
)
var handlers = make(map[types.ProblemDaemonType]types.ProblemDaemonHandler)

// Register registers a problem daemon factory method, which will be used to create the problem daemon.
func Register(problemDaemonType types.ProblemDaemonType, handler types.ProblemDaemonHandler) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/systemlogmonitor/log_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func init() {
SystemLogMonitorName,
types.ProblemDaemonHandler{
CreateProblemDaemonOrDie: NewLogMonitorOrDie,
CmdOptionDescription: "Set to config file paths."})
CmdOptionDescription: "Set to config file paths.",
})
}

type logMonitor struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s *filelogWatcher) watchLoop() {
}

func (s *filelogWatcher) filterSkipList(line string) bool {
for _ , skipItem := range s.cfg.SkipList {
for _, skipItem := range s.cfg.SkipList {
if strings.Contains(line, skipItem) {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ package filelog
import (
"fmt"
"io"
"k8s.io/node-problem-detector/third_party/forked/cadvisor/tail"
"os"

"k8s.io/node-problem-detector/third_party/forked/cadvisor/tail"
)

// getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back
Expand Down
17 changes: 8 additions & 9 deletions pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
testclock "k8s.io/utils/clock/testing"

"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
"k8s.io/node-problem-detector/pkg/util"

"github.com/stretchr/testify/assert"
testclock "k8s.io/utils/clock/testing"
)

// getTestPluginConfig returns a plugin config for test. Use configuration for
Expand Down Expand Up @@ -185,22 +185,21 @@ func TestFilterSkipList(t *testing.T) {
},
},
}
testcase := []struct{
log string
testcase := []struct {
log string
expect bool
}{
{
log: `Jan 2 03:04:03 kernel: [0.000000] 1`,
log: `Jan 2 03:04:03 kernel: [0.000000] 1`,
expect: false,
},
{
log: `Jan 2 03:04:04 audit: [1.000000] 2`,
log: `Jan 2 03:04:04 audit: [1.000000] 2`,
expect: true,
},
{
log: `Jan 2 03:04:05 kubelet: [2.000000] 3`,
log: `Jan 2 03:04:05 kubelet: [2.000000] 3`,
expect: true,

},
}
for i, test := range testcase {
Expand Down
4 changes: 2 additions & 2 deletions pkg/systemlogmonitor/logwatchers/filelog/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"regexp"
"time"

logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"

"k8s.io/klog/v2"

logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
)

// translator translates log line into internal log type based on user defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package kmsg

import (
testclock "k8s.io/utils/clock/testing"
"testing"
"time"

"github.com/euank/go-kmsg-parser/kmsgparser"
"github.com/stretchr/testify/assert"
"time"
testclock "k8s.io/utils/clock/testing"

"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
Expand Down
4 changes: 2 additions & 2 deletions pkg/systemlogmonitor/logwatchers/log_watchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package logwatchers

import (
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"

"k8s.io/klog/v2"

"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
)

// createFuncs is a table of createFuncs for all supported log watchers.
Expand Down
1 change: 0 additions & 1 deletion pkg/systemstatsmonitor/disk_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ func (dc *diskCollector) collect() {
dc.mPercentUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, float64(usageStat.UsedPercent))
}
}

}

// listRootBlockDevices lists all block devices that's not a slave or holder.
Expand Down
Loading