cleanup debug logs & remove duplicated output (#1348)

* cleanup debug logs

* avoid duplicate error messages

and this makes main.go use os and fmt package instead of log to avoid
touching global state
This commit is contained in:
namusyaka 2020-11-04 23:50:18 +09:00 committed by GitHub
parent 8b06045c70
commit 951b46e3c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 11 deletions

View File

@ -52,11 +52,11 @@ var RootCmd = &cobra.Command{
Use: "kompose", Use: "kompose",
Short: "A tool helping Docker Compose users move to Kubernetes", Short: "A tool helping Docker Compose users move to Kubernetes",
Long: `Kompose is a tool to help users who are familiar with docker-compose move to Kubernetes.`, Long: `Kompose is a tool to help users who are familiar with docker-compose move to Kubernetes.`,
SilenceErrors: true,
// PersistentPreRun will be "inherited" by all children and ran before *every* command unless // PersistentPreRun will be "inherited" by all children and ran before *every* command unless
// the child has overridden the functionality. This functionality was implemented to check / modify // the child has overridden the functionality. This functionality was implemented to check / modify
// all global flag calls regardless of app call. // all global flag calls regardless of app call.
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Add extra logging when verbosity is passed // Add extra logging when verbosity is passed
if GlobalVerbose { if GlobalVerbose {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
@ -81,7 +81,6 @@ var RootCmd = &cobra.Command{
if provider != "kubernetes" && provider != "openshift" { if provider != "kubernetes" && provider != "openshift" {
log.Fatalf("%s is an unsupported provider. Supported providers are: 'kubernetes', 'openshift'.", GlobalProvider) log.Fatalf("%s is an unsupported provider. Supported providers are: 'kubernetes', 'openshift'.", GlobalProvider)
} }
}, },
} }

View File

@ -17,14 +17,15 @@ limitations under the License.
package main package main
import ( import (
"log" "fmt"
"os"
"github.com/kubernetes/kompose/cmd" "github.com/kubernetes/kompose/cmd"
) )
func main() { func main() {
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
log.SetFlags(0) fmt.Fprintln(os.Stderr, err)
log.Fatal(err) os.Exit(1)
} }
} }

View File

@ -139,8 +139,6 @@ func (k *Kubernetes) InitPodSpecWithConfigMap(name string, image string, service
var volumeMounts []api.VolumeMount var volumeMounts []api.VolumeMount
var volumes []api.Volume var volumes []api.Volume
log.Debugf("Configs in InitPodSpecWithConfigMap: %+v", service.Configs)
for _, value := range service.Configs { for _, value := range service.Configs {
cmVolName := FormatFileName(value.Source) cmVolName := FormatFileName(value.Source)
target := value.Target target := value.Target
@ -598,7 +596,6 @@ func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConf
seenPorts := make(map[int]struct{}, len(service.Port)) seenPorts := make(map[int]struct{}, len(service.Port))
var servicePort api.ServicePort var servicePort api.ServicePort
log.Debugf("Ports in ConfigServicePorts: %+v", service.Port)
for _, port := range service.Port { for _, port := range service.Port {
if port.HostPort == 0 { if port.HostPort == 0 {
port.HostPort = port.ContainerPort port.HostPort = port.ContainerPort