Skip to content

Commit

Permalink
make manifests.Load return the error too
Browse files Browse the repository at this point in the history
  • Loading branch information
briandealwis committed Sep 28, 2020
1 parent 1469253 commit 3042548
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions cmd/skaffold/app/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"context"
"fmt"
"io"
"os"

Expand Down Expand Up @@ -59,24 +60,27 @@ func NewCmdFilter() *cobra.Command {
// Unlike `skaffold debug`, this filtering affects all images and not just the built artifacts.
func runFilter(ctx context.Context, out io.Writer, debuggingFilters bool, buildArtifacts []build.Artifact) error {
return withRunner(ctx, func(r runner.Runner, cfg *latest.SkaffoldConfig) error {
manifestList := manifest.Load(os.Stdin)
manifestList, err := manifest.Load(os.Stdin)
if err != nil {
return fmt.Errorf("loading manifests: %w", err)
}
if debuggingFilters {
// TODO(bdealwis): refactor this code
debugHelpersRegistry, err := config.GetDebugHelpersRegistry(opts.GlobalConfig)
if err != nil {
return err
return fmt.Errorf("resolving debug helpers: %w", err)
}
insecureRegistries, err := getInsecureRegistries(opts, cfg)
if err != nil {
return err
return fmt.Errorf("retrieving insecure registries: %w", err)
}

manifestList, err = debugging.ApplyDebuggingTransforms(manifestList, buildArtifacts, manifest.Registries{
DebugHelpersRegistry: debugHelpersRegistry,
InsecureRegistries: insecureRegistries,
})
if err != nil {
return err
return fmt.Errorf("transforming manifests: %w", err)
}
}
out.Write([]byte(manifestList.String()))
Expand Down
8 changes: 5 additions & 3 deletions pkg/skaffold/kubernetes/manifest/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ import (
type ManifestList [][]byte

// Load uses the Kubernetes `apimachinery` to split YAML content into a set of YAML documents.
func Load(in io.Reader) ManifestList {
func Load(in io.Reader) (ManifestList, error) {
r := k8syaml.NewYAMLReader(bufio.NewReader(in))
var docs [][]byte
for i := 0; ; i++ {
for {
doc, err := r.Read()
if err == io.EOF {
break
} else {
return nil, err
}
docs = append(docs, doc)
}
return ManifestList(docs)
return ManifestList(docs), nil
}

func (l *ManifestList) String() string {
Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/kubernetes/manifest/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func TestLoad(t *testing.T) {
}
for _, test := range tests {
testutil.Run(t, test.name, func(t *testutil.T) {
result := Load(bytes.NewReader([]byte(test.input)))
result, err := Load(bytes.NewReader([]byte(test.input)))

t.CheckError(false, err)
t.CheckDeepEqual(len(test.expected), len(result))
for i := range test.expected {
t.CheckDeepEqual(test.expected[i], string(result[i]))
Expand Down

0 comments on commit 3042548

Please sign in to comment.