Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: broken reading from stdin (-) #704

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions e2etests/bats-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,7 @@ get_value_from() {
print_info "${status}" "${output}" "${cmd}" "${tmp}"
[ "$status" -eq 0 ]
}

@test "flag-read-from-stdin" {
echo "---" | ${KUBE_LINTER_BIN} lint -
}
6 changes: 5 additions & 1 deletion pkg/command/lint/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ func Command() *cobra.Command {
return err
}

absArgs := []string{}
absArgs := make([]string, 0, len(args))
for _, arg := range args {
if arg == lintcontext.ReadFromStdin {
absArgs = append(absArgs, lintcontext.ReadFromStdin)
continue
}
absArg, err := pathutil.GetAbsolutPath(arg)
if err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions pkg/lintcontext/create_contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

// ReadFromStdin is a path used to indicate reading from os.Stdin
const ReadFromStdin = "-"

var (
knownYAMLExtensions = set.NewFrozenStringSet(".yaml", ".yml")
)
Expand All @@ -41,16 +44,15 @@ func CreateContextsWithOptions(options Options, ignorePaths []string, filesOrDir
contextsByDir := make(map[string]*lintContextImpl)
fileOrDirsLoop:
for _, fileOrDir := range filesOrDirs {
// Stdin
if fileOrDir == "-" {
if _, alreadyExists := contextsByDir["-"]; alreadyExists {
if fileOrDir == ReadFromStdin {
if _, alreadyExists := contextsByDir[ReadFromStdin]; alreadyExists {
continue
}
ctx := newCtx(options)
if err := ctx.loadObjectsFromReader("<standard input>", os.Stdin); err != nil {
return nil, err
}
contextsByDir["-"] = ctx
contextsByDir[ReadFromStdin] = ctx
continue
}

Expand Down
Loading