Skip to content
Permalink
Browse files

lint: fix missing error checks (errcheck)

One minor bug fixed: bash filename autocompletion for shipperctl apply
was not working.

One minor judgement call: if we can't set up /metrics, this is a fatal
error.

Examples:

cmd/shipper-state-metrics/main.go:95:21⚠️ error return value not
checked (srv.ListenAndServe()) (errcheck)

cmd/shipper/main.go:255:20⚠️ error return value not checked
(srv.ListenAndServe()) (errcheck)

cmd/shipperctl/cmd/apply.go:47:27⚠️ error return value not
checked (applyCmd.MarkFlagFilename("config", "yaml")) (errcheck)

cmd/shipperctl/cmd/apply.go:48:27⚠️ error return value not
checked (applyCmd.MarkFlagFilename("kube-config", "yaml")) (errcheck)

cmd/shipperctl/cmd/apply.go:387:16⚠️ error return value not
checked (yaml.Unmarshal(configBytes, configuration)) (errcheck)
  • Loading branch information...
kanatohodets committed Feb 9, 2019
1 parent d96842c commit fdff51440e1241323e48535031c8b43183c16790
Showing with 25 additions and 7 deletions.
  1. +4 −1 cmd/shipper-state-metrics/main.go
  2. +4 −1 cmd/shipper/main.go
  3. +17 −5 cmd/shipperctl/cmd/apply.go
@@ -92,7 +92,10 @@ func main() {
},
),
}
srv.ListenAndServe()
err := srv.ListenAndServe()
if err != nil {
glog.Fatalf("could not start /metrics endpoint: %s", err)
}
}()

<-stopCh
@@ -252,7 +252,10 @@ func runMetrics(cfg *metricsCfg) {
},
),
}
srv.ListenAndServe()
err := srv.ListenAndServe()
if err != nil {
glog.Fatalf("could not start /metrics endpoint: %s", err)
}
}

func buildEnabledControllers(enabledControllers, disabledControllers string) map[string]bool {
@@ -41,11 +41,20 @@ const (
)

func init() {
applyCmd.Flags().StringVarP(&configFile, "file", "f", "clusters.yaml", "config file")
applyCmd.Flags().StringVar(&kubeConfigFile, "kube-config", "~/.kube/config", "the path to the Kubernetes configuration file")
fileFlagName := "file"
kubeConfigFlagName := "kube-config"
applyCmd.Flags().StringVarP(&configFile, fileFlagName, "f", "clusters.yaml", "config file")
applyCmd.Flags().StringVar(&kubeConfigFile, kubeConfigFlagName, "~/.kube/config", "the path to the Kubernetes configuration file")
applyCmd.Flags().StringVarP(&shipperSystemNamespace, "shipper-system-namespace", "n", shipper.ShipperNamespace, "the namespace where Shipper is running")
applyCmd.MarkFlagFilename("config", "yaml")
applyCmd.MarkFlagFilename("kube-config", "yaml")

err := applyCmd.MarkFlagFilename(fileFlagName, "yaml")
if err != nil {
applyCmd.Printf("warning: could not mark %q for filename autocompletion: %s\n", fileFlagName, err)
}
err = applyCmd.MarkFlagFilename(kubeConfigFlagName, "yaml")
if err != nil {
applyCmd.Printf("warning: could not mark %q for filename autocompletion: %s\n", kubeConfigFlagName, err)
}
}

func runApplyClustersCommand(cmd *cobra.Command, args []string) error {
@@ -384,7 +393,10 @@ func loadClustersConfiguration() (*config.ClustersConfiguration, error) {
}

configuration := &config.ClustersConfiguration{}
yaml.Unmarshal(configBytes, configuration)
err = yaml.Unmarshal(configBytes, configuration)
if err != nil {
return nil, err
}

return configuration, nil
}

0 comments on commit fdff514

Please sign in to comment.
You can’t perform that action at this time.