removed unused vars and improved readability

This commit is contained in:
Nils Carstensen 2024-04-18 21:04:16 +02:00
parent 7d25a03ee3
commit 86f7f1dc7b
No known key found for this signature in database
GPG Key ID: 1F25989330BF84C3

View File

@ -51,7 +51,12 @@ type sourceFile struct {
} }
// NewSourceFile watches a config file for changes. // NewSourceFile watches a config file for changes.
func NewSourceFile(path string, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) { func NewSourceFile(
path string,
nodeName types.NodeName,
period time.Duration,
updates chan<- interface{},
) {
// "github.com/sigma/go-inotify" requires a path without trailing "/" // "github.com/sigma/go-inotify" requires a path without trailing "/"
path = strings.TrimRight(path, string(os.PathSeparator)) path = strings.TrimRight(path, string(os.PathSeparator))
@ -60,7 +65,12 @@ func NewSourceFile(path string, nodeName types.NodeName, period time.Duration, u
config.run() config.run()
} }
func newSourceFile(path string, nodeName types.NodeName, period time.Duration, updates chan<- interface{}) *sourceFile { func newSourceFile(
path string,
nodeName types.NodeName,
period time.Duration,
updates chan<- interface{},
) *sourceFile {
send := func(objs []interface{}) { send := func(objs []interface{}) {
var pods []*v1.Pod var pods []*v1.Pod
for _, o := range objs { for _, o := range objs {
@ -170,7 +180,12 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) {
switch { switch {
case statInfo.Mode().IsDir(): case statInfo.Mode().IsDir():
klog.ErrorS(nil, "Provided manifest path is a directory, not recursing into manifest path", "path", path) klog.ErrorS(
nil,
"Provided manifest path is a directory, not recursing into manifest path",
"path",
path,
)
case statInfo.Mode().IsRegular(): case statInfo.Mode().IsRegular():
pod, err := s.extractFromFile(path) pod, err := s.extractFromFile(path)
if err != nil { if err != nil {
@ -181,7 +196,14 @@ func (s *sourceFile) extractFromDir(name string) ([]*v1.Pod, error) {
pods = append(pods, pod) pods = append(pods, pod)
} }
default: default:
klog.ErrorS(nil, "Manifest path is not a directory or file", "path", path, "mode", statInfo.Mode()) klog.ErrorS(
nil,
"Manifest path is not a directory or file",
"path",
path,
"mode",
statInfo.Mode(),
)
} }
} }
return pods, nil return pods, nil
@ -224,7 +246,11 @@ func (s *sourceFile) extractFromFile(filename string) (pod *v1.Pod, err error) {
return pod, nil return pod, nil
} }
return pod, fmt.Errorf("%v: couldn't parse as pod(%v), please check config file", filename, podErr) return pod, fmt.Errorf(
"%v: couldn't parse as pod(%v), please check config file",
filename,
podErr,
)
} }
func (s *sourceFile) replaceStore(pods ...*v1.Pod) (err error) { func (s *sourceFile) replaceStore(pods ...*v1.Pod) (err error) {