Skip to content

Commit

Permalink
Merge pull request #116 from flant/chore_lint
Browse files Browse the repository at this point in the history
chore: accept linter recommendations
  • Loading branch information
diafour committed Apr 3, 2020
2 parents bbc4d38 + 36a3919 commit 227fbe1
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 66 deletions.
2 changes: 0 additions & 2 deletions cmd/addon-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,4 @@ func main() {
app.DefineDebugCommands(kpApp)

kingpin.MustParse(kpApp.Parse(os.Args[1:]))

return
}
36 changes: 17 additions & 19 deletions pkg/addon-operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,6 @@ func (op *AddonOperator) InitAndStartHookQueues() {
}
}
}

return
}

func (op *AddonOperator) StartModuleManagerEventHandler() {
Expand Down Expand Up @@ -1276,37 +1274,37 @@ func (op *AddonOperator) SetupDebugServerHandles() {

if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(err.Error()))
_, _ = writer.Write([]byte(err.Error()))
return
}

outBytes, err := values.AsBytes(format)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(err.Error()))
_, _ = writer.Write([]byte(err.Error()))
return
}
writer.Write(outBytes)
_, _ = writer.Write(outBytes)
})

op.DebugServer.Router.Get("/global/patches.json", func(writer http.ResponseWriter, request *http.Request) {
jp := op.ModuleManager.GlobalValuesPatches()
data, err := json.Marshal(jp)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(err.Error()))
_, _ = writer.Write([]byte(err.Error()))
return
}
writer.Write(data)
_, _ = writer.Write(data)
})

op.DebugServer.Router.Get("/module/list.{format:(json|yaml|text)}", func(writer http.ResponseWriter, request *http.Request) {
format := chi.URLParam(request, "format")

fmt.Fprintf(writer, "Dump modules in %s format.\n", format)
_, _ = fmt.Fprintf(writer, "Dump modules in %s format.\n", format)

for _, mName := range op.ModuleManager.GetModuleNamesInOrder() {
fmt.Fprintf(writer, "%s \n", mName)
_, _ = fmt.Fprintf(writer, "%s \n", mName)
}

})
Expand All @@ -1319,7 +1317,7 @@ func (op *AddonOperator) SetupDebugServerHandles() {
m := op.ModuleManager.GetModule(modName)
if m == nil {
writer.WriteHeader(http.StatusNotFound)
writer.Write([]byte("Module not found"))
_, _ = writer.Write([]byte("Module not found"))
return
}

Expand All @@ -1334,17 +1332,17 @@ func (op *AddonOperator) SetupDebugServerHandles() {

if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(err.Error()))
_, _ = writer.Write([]byte(err.Error()))
return
}

outBytes, err := values.AsBytes(format)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(err.Error()))
_, _ = writer.Write([]byte(err.Error()))
return
}
writer.Write(outBytes)
_, _ = writer.Write(outBytes)
})

op.DebugServer.Router.Get("/module/{name}/patches.json", func(writer http.ResponseWriter, request *http.Request) {
Expand All @@ -1353,18 +1351,18 @@ func (op *AddonOperator) SetupDebugServerHandles() {
m := op.ModuleManager.GetModule(modName)
if m == nil {
writer.WriteHeader(http.StatusNotFound)
writer.Write([]byte("Module not found"))
_, _ = writer.Write([]byte("Module not found"))
return
}

jp := m.ValuesPatches()
data, err := json.Marshal(jp)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(err.Error()))
_, _ = writer.Write([]byte(err.Error()))
return
}
writer.Write(data)
_, _ = writer.Write(data)
})

op.DebugServer.Router.Get("/module/resource-monitor.{format:(json|yaml)}", func(writer http.ResponseWriter, request *http.Request) {
Expand Down Expand Up @@ -1395,16 +1393,16 @@ func (op *AddonOperator) SetupDebugServerHandles() {
}
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(writer, "Error: %s", err)
_, _ = fmt.Fprintf(writer, "Error: %s", err)
}
writer.Write(outBytes)
_, _ = writer.Write(outBytes)
})

}

func (op *AddonOperator) SetupHttpServerHandles() {
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte(`<html>
_, _ = writer.Write([]byte(`<html>
<head><title>Addon-operator</title></head>
<body>
<h1>Addon-operator</h1>
Expand Down
4 changes: 1 addition & 3 deletions pkg/addon-operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func Test_Operator_Startup(t *testing.T) {
op.WithKubernetesClient(kubeClient)
op.WithGlobalHooksDir("testdata/global_hooks")

var err error

err = op.Init()
var err = op.Init()
g.Expect(err).ShouldNot(HaveOccurred())

err = op.InitModuleManager()
Expand Down
8 changes: 4 additions & 4 deletions pkg/helm/tiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ func TillerHealthHandler(tillerProbeAddress string, tillerProbePort int32) func(
res, err := http.Get(tillerUrl)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(fmt.Sprintf("Error request tiller: %v", err)))
_, _ = writer.Write([]byte(fmt.Sprintf("Error request tiller: %v", err)))
return
}

tillerLivenessBody, err := ioutil.ReadAll(res.Body)
res.Body.Close()
_ = res.Body.Close()
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
writer.Write([]byte(fmt.Sprintf("Error reading tiller response: %v", err)))
_, _ = writer.Write([]byte(fmt.Sprintf("Error reading tiller response: %v", err)))
return
}

writer.WriteHeader(http.StatusOK)
writer.Write(tillerLivenessBody)
_, _ = writer.Write(tillerLivenessBody)
}
}
2 changes: 1 addition & 1 deletion pkg/helm_resources_manager/resources_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ResourcesMonitor struct {
func NewResourcesMonitor() *ResourcesMonitor {
return &ResourcesMonitor{
paused: false,
logLabels: make(map[string]string, 0),
logLabels: make(map[string]string),
manifests: make([]manifest.Manifest, 0),
}
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/kube_config_manager/kube_config_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,8 @@ param2: val2
wg.Add(1)

go func() {
select {
case newModuleConfigs = <-ModuleConfigsUpdated:
wg.Done()
return
}
newModuleConfigs = <-ModuleConfigsUpdated
wg.Done()
}()

// update cm
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube_config_manager/module_kube_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// GetModulesNamesFromConfigData returns all keys in kube config except global
// modNameEnabled keys are also handled
func GetModulesNamesFromConfigData(configData map[string]string) map[string]bool {
res := make(map[string]bool, 0)
res := make(map[string]bool)

for key := range configData {
if key == utils.GlobalValuesKey {
Expand Down
2 changes: 1 addition & 1 deletion pkg/module_manager/global_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (h *GlobalHook) Run(bindingType BindingType, context []BindingContext, logL

// PrepareTmpFilesForHookRun creates temporary files for hook and returns environment variables with paths
func (h *GlobalHook) PrepareTmpFilesForHookRun(bindingContext []byte) (tmpFiles map[string]string, err error) {
tmpFiles = make(map[string]string, 0)
tmpFiles = make(map[string]string)

tmpFiles["CONFIG_VALUES_PATH"], err = h.prepareConfigValuesJsonFile()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/module_manager/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (mm *moduleManager) RegisterModuleHooks(module *Module, logLabels map[strin
}
logEntry.Debugf("Search and register hooks")

var registeredModuleHooks = make(map[BindingType][]*ModuleHook, 0)
var registeredModuleHooks = make(map[BindingType][]*ModuleHook)

hooks, err := SearchModuleHooks(module)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/module_manager/module_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (h *ModuleHook) Run(bindingType BindingType, context []BindingContext, logL

// PrepareTmpFilesForHookRun creates temporary files for hook and returns environment variables with paths
func (h *ModuleHook) PrepareTmpFilesForHookRun(bindingContext []byte) (tmpFiles map[string]string, err error) {
tmpFiles = make(map[string]string, 0)
tmpFiles = make(map[string]string)

tmpFiles["CONFIG_VALUES_PATH"], err = h.prepareConfigValuesJsonFile()
if err != nil {
Expand Down
11 changes: 1 addition & 10 deletions pkg/module_manager/module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ type moduleManager struct {
// This event leads to module discovery action.
globalValuesChanged chan bool

helm helm.HelmClient
kubeConfigManager kube_config_manager.KubeConfigManager

// Saved values from ConfigMap to handle Ambiguous state.
Expand Down Expand Up @@ -355,7 +354,7 @@ func (mm *moduleManager) handleNewKubeModuleConfigs(moduleConfigs kube_config_ma

// Detect removed module sections for statically enabled modules.
// This removal should be handled like kube config update.
updateAfterRemoval := make(map[string]bool, 0)
updateAfterRemoval := make(map[string]bool)
for moduleName, module := range mm.allModulesByName {
_, hasKubeConfig := moduleConfigs[moduleName]
if !hasKubeConfig && mergeEnabled(module.CommonStaticConfig.IsEnabled, module.StaticConfig.IsEnabled) {
Expand Down Expand Up @@ -929,8 +928,6 @@ func (mm *moduleManager) HandleKubeEvent(kubeEvent KubeEvent, createGlobalTaskFn
}
}
})

return
}

func (mm *moduleManager) HandleGlobalEnableKubernetesBindings(hookName string, createTaskFn func(*GlobalHook, controller.BindingExecutionInfo)) error {
Expand Down Expand Up @@ -979,8 +976,6 @@ func (mm *moduleManager) StartModuleHooks(moduleName string) {
mh := mm.GetModuleHook(hookName)
mh.HookController.EnableScheduleBindings()
}

return
}

func (mm *moduleManager) DisableModuleHooks(moduleName string) {
Expand All @@ -996,8 +991,6 @@ func (mm *moduleManager) DisableModuleHooks(moduleName string) {
mh := mm.GetModuleHook(hookName)
mh.HookController.DisableScheduleBindings()
}

return
}

//func (mm *moduleManager) EnableModuleScheduleBindings(moduleName) {
Expand Down Expand Up @@ -1052,8 +1045,6 @@ func (mm *moduleManager) LoopByBinding(binding BindingType, fn func(gh *GlobalHo
}

}

return
}

// mergeEnabled merges enabled flags. Enabled flag can be nil.
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/fschecksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func CalculateStringsChecksum(stringArr ...string) string {
hasher := md5.New()
sort.Strings(stringArr)
for _, value := range stringArr {
hasher.Write([]byte(value))
_, _ = hasher.Write([]byte(value))
}
return hex.EncodeToString(hasher.Sum(nil))
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/utils/fswalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

// FilesFromRoot returns a map with path and array of files under it
func FilesFromRoot(root string, filterFn func(dir string, name string, info os.FileInfo) bool) (files map[string]map[string]string, err error) {
files = make(map[string]map[string]string, 0)
files = make(map[string]map[string]string)

symlinkedDirs, err := WalkSymlinks(root, "", files, filterFn)
if err != nil {
Expand Down Expand Up @@ -69,9 +69,7 @@ func FilesFromRoot(root string, filterFn func(dir string, name string, info os.F
}

for k := range walkedSymlinks {
if _, has := newSymlinkedDirs[k]; has {
delete(newSymlinkedDirs, k)
}
delete(newSymlinkedDirs, k)
}

if len(newSymlinkedDirs) == 0 {
Expand Down Expand Up @@ -110,6 +108,11 @@ func WalkSymlinks(target string, linkName string, files map[string]map[string]st
symlinkedDirectories = map[string]string{}

err = filepath.Walk(target, func(foundPath string, info os.FileInfo, err error) error {
if err != nil {
fmt.Printf("failure accessing a path '%s': %v\n", foundPath, err)
return err
}

if info.IsDir() {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/module_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (mc *ModuleConfig) GetEnabled() string {
switch {
case mc.IsEnabled == nil:
return "n/d"
case *mc.IsEnabled == true:
case *mc.IsEnabled:
return "true"
default:
return "false"
Expand Down
12 changes: 5 additions & 7 deletions pkg/utils/module_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func SortReverseByReference(in []string, ref []string) []string {
res := make([]string, 0)

inValues := make(map[string]bool, 0)
inValues := make(map[string]bool)
for _, v := range in {
inValues[v] = true
}
Expand All @@ -26,9 +26,7 @@ func SortReverseByReference(in []string, ref []string) []string {
// SortReverse creates a copy of 'in' array and sort it in a reverse order.
func SortReverse(in []string) []string {
res := make([]string, 0)
for _, v := range in {
res = append(res, v)
}
res = append(res, in...)
sort.Sort(sort.Reverse(sort.StringSlice(res)))

return res
Expand All @@ -38,7 +36,7 @@ func SortReverse(in []string) []string {
func SortByReference(in []string, ref []string) []string {
res := make([]string, 0)

inValues := make(map[string]bool, 0)
inValues := make(map[string]bool)
for _, v := range in {
inValues[v] = true
}
Expand All @@ -54,7 +52,7 @@ func SortByReference(in []string, ref []string) []string {
// ListSubtract creates a new array from 'src' array with items that are
// not present in 'ignored' arrays.
func ListSubtract(src []string, ignored ...[]string) (result []string) {
ignoredMap := make(map[string]bool, 0)
ignoredMap := make(map[string]bool)
for _, arr := range ignored {
for _, v := range arr {
ignoredMap[v] = true
Expand Down Expand Up @@ -100,7 +98,7 @@ func ListIntersection(arrs ...[]string) (result []string) {
func ListFullyIn(arr []string, ref []string) bool {
res := true

m := make(map[string]bool, 0)
m := make(map[string]bool)
for _, v := range ref {
m[v] = true
}
Expand Down
Loading

0 comments on commit 227fbe1

Please sign in to comment.