Skip to content

Commit

Permalink
Improve error reporting for gen-kustomize command (#1802)
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek authored Sep 13, 2021
1 parent c88f97a commit 02bf294
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hack/generator/cmd/gen_kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package cmd

import (
"context"
"fmt"
"io/ioutil"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"k8s.io/klog/v2"
Expand All @@ -36,7 +38,7 @@ func NewGenKustomizeCommand() (*cobra.Command, error) {

files, err := ioutil.ReadDir(basesPath)
if err != nil {
return err
return logAndExtractStack(fmt.Sprintf("Unable to scan folder %q", basesPath), err)
}

result := crdKustomizeFile{
Expand All @@ -50,6 +52,11 @@ func NewGenKustomizeCommand() (*cobra.Command, error) {
result.Resources = append(result.Resources, filepath.Join(bases, f.Name()))
}

if len(result.Resources) == 0 {
err = errors.Errorf("no files found in %q", basesPath)
return logAndExtractStack("No CRD files found", err)
}

data, err := yaml.Marshal(result)
if err != nil {
return logAndExtractStack("Error during kustomize.yaml serialization", err)
Expand Down

0 comments on commit 02bf294

Please sign in to comment.