-
Notifications
You must be signed in to change notification settings - Fork 128
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
Feat: Support KRM input #170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"runtime" | ||
"runtime/pprof" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" | ||
"github.com/yannh/kubeconform/pkg/config" | ||
"github.com/yannh/kubeconform/pkg/output" | ||
"github.com/yannh/kubeconform/pkg/resource" | ||
|
@@ -46,6 +49,26 @@ func processResults(cancel context.CancelFunc, o output.Output, validationResult | |
return result | ||
} | ||
|
||
func parseStdin(stdin *os.File) *strings.Reader { | ||
var content string | ||
|
||
// Read all stdin lines. | ||
scanner := bufio.NewScanner(stdin) | ||
for scanner.Scan() { | ||
content += fmt.Sprintln(scanner.Text()) | ||
} | ||
|
||
// Check if the stdin input is ResourceList. | ||
rl, err := fn.ParseResourceList([]byte(content)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds support for ResourceLists (I need to read about this) only if passed via stdin? This would not work if I ran kubeconform ./fixtures/krm.yaml? I think we would need some consistency there |
||
// If it's ResourceList, use the items as the new content. | ||
if err == nil { | ||
content = rl.Items.String() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's one part I'm worried about... there are some ridiculous optimisations to ensure we read stdin as a stream, and from previous tickets it looks like some people do indeed pass very large amounts of data via stdin... if we were to do that, this function would have to operate on a stream without buffering the whole thing |
||
} | ||
|
||
// Convert the content which is type "string" to a "Reader" again. | ||
return strings.NewReader(content) | ||
} | ||
|
||
func realMain() int { | ||
cfg, out, err := config.FromFlags(os.Args[0], os.Args[1:]) | ||
if out != "" { | ||
|
@@ -121,7 +144,7 @@ func realMain() int { | |
var resourcesChan <-chan resource.Resource | ||
var errors <-chan error | ||
if useStdin { | ||
resourcesChan, errors = resource.FromStream(ctx, "stdin", os.Stdin) | ||
resourcesChan, errors = resource.FromStream(ctx, "stdin", parseStdin(os.Stdin)) | ||
} else { | ||
resourcesChan, errors = resource.FromFiles(ctx, cfg.Files, cfg.IgnoreFilenamePatterns) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: config.kubernetes.io/v1 | ||
kind: ResourceList | ||
metadata: | ||
name: krm-function-input | ||
items: | ||
- apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: foo | ||
data: | ||
val: foo | ||
- apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: bar | ||
data: | ||
val: bar |
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be awesome if this could take a reader and return a reader