Created
August 14, 2020 08:12
-
-
Save Duologic/584a2a41f8e5ebacf38c55cc7f5b0fe6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"encoding/json" | |
"fmt" | |
"log" | |
"os" | |
"github.com/grafana/tanka/pkg/kubernetes/manifest" | |
"github.com/grafana/tanka/pkg/process" | |
) | |
// usage: cat file.json | go run . | |
// roughly mimics https://github.com/grafana/tanka/blob/dfa544ada0beb6c56bc93af68eec8632b7f72c6a/pkg/process/process.go#L21 | |
// but without the config/environment/namespace stuff | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
var input []byte | |
for scanner.Scan() { | |
input = append(input, scanner.Bytes()...) | |
} | |
var raw interface{} | |
if err := json.Unmarshal(input, &raw); err != nil { | |
log.Fatal(err) | |
} | |
// Scan for everything that looks like a Kubernetes object | |
extracted, err := process.Extract(raw) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Unwrap *List types | |
if err := process.Unwrap(extracted); err != nil { | |
log.Fatal(err) | |
} | |
out := make(manifest.List, 0, len(extracted)) | |
for _, m := range extracted { | |
out = append(out, m) | |
} | |
// Best-effort dependency sort | |
process.Sort(out) | |
fmt.Print(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment