Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Neumann <aneumann@mesosphere.com>
  • Loading branch information
vemelin-epm and ANeumann82 authored May 12, 2020
1 parent ff2ee05 commit d160a0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions pkg/kudoctl/cmd/diagnostics/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ func (p *PrintableRuntimeObject) print(fs afero.Fs) error {
dir += "/" + p.relToParentDir()
err := fs.MkdirAll(dir, 0700)
if err != nil {
return err
return fmt.Errorf("failed to create directory %s: %v", dir, err)
}
}
file, err := fs.Create(dir + "/" + name)
fileWithPath := fmt.SPrintf("%s/%s", dir, name)
file, err := fs.Create(fileWithPath)
if err != nil {
return err
return fmt.Errorf("failed to create %s: %v", fileWithPath, err)
}
printer := printers.YAMLPrinter{}
return printer.PrintObj(p.o, file)
Expand All @@ -156,9 +157,10 @@ func (p *PrintableYaml) Collect() (Printable, error) {
func (p *PrintableYaml) print(fs afero.Fs) error {
b, err := yaml.Marshal(p.v)
if err != nil {
return err
return fmt.Errorf("failed to marshal object to %s/%s.yaml: %v", p.dir(), p.name, err)
}
return printBytes(fs, b, p.dir()+"/"+p.name+".yaml")
fileNameWithPath := fmt.Sprintf("%s/%s.yaml", p.dir(), p.name)
return printBytes(fs, b, fileNameWithPath)
}

type PrintableError struct {
Expand All @@ -177,11 +179,11 @@ func (p *PrintableError) print(fs afero.Fs) error {
func printBytes(fs afero.Fs, b []byte, fileName string) error {
file, err := fs.Create(fileName)
if err != nil {
return err
return fmt.Errorf("failed to create file %s: %v", fileName, err)
}
_, err = file.Write(b)
if err != nil {
return err
return fmt.Errorf("failed to write to file %s: %v, fileName, err)
}
return nil
}
8 changes: 4 additions & 4 deletions pkg/kudoctl/cmd/diagnostics/resource_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func NewInstanceResources(opts *Options, s *env.Settings) (*ResourceFuncsConfig,

kc, err := kudo.NewClient(s.KubeConfig, s.RequestTimeout, s.Validate)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create kudo client: %v", err)
}
c, err := kube.GetKubeClient(s.KubeConfig)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to create kube client: %v", err)
}
instance, err := kc.GetInstance(opts.Instance, s.Namespace)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get instance %s/%s: %v", s.Namespace, opts.Instance, err)
}

return &ResourceFuncsConfig{
Expand Down Expand Up @@ -91,7 +91,7 @@ func OperatorVersion(r *ResourceFuncsConfig, ctx *processingContext) (runtime.Ob
ovName := ctx.operatorVersionName
obj, err := r.kc.GetOperatorVersion(ovName, r.ns)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get operatorversion %s/%s: %v", r.ns, ovName, err)
}
if obj == nil {
return nil, fmt.Errorf("operator version not found")
Expand Down
2 changes: 1 addition & 1 deletion pkg/kudoctl/util/kudo/kudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (c *Client) GetOperator(name, namespace string) (*v1beta1.Operator, error)
return nil, nil
}
if err != nil {
return o, err
return o, fmt.Errorf("failed to get operator %/%s: %v", namespace, name, err)
}
err = setGVKFromScheme(o)
return o, err
Expand Down

0 comments on commit d160a0a

Please sign in to comment.