@@ -27,6 +27,7 @@ import (
2727 spin "github.com/tj/go-spin"
2828 "go.opentelemetry.io/otel"
2929 "golang.org/x/sync/errgroup"
30+ "gopkg.in/yaml.v2"
3031 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132 "k8s.io/apimachinery/pkg/labels"
3233 "k8s.io/client-go/kubernetes/scheme"
@@ -75,6 +76,12 @@ func RunPreflights(interactive bool, output string, format string, args []string
7576 return err
7677 }
7778
79+ preflightContent = b
80+ } else if v == "-" {
81+ b , err := io .ReadAll (os .Stdin )
82+ if err != nil {
83+ return err
84+ }
7885 preflightContent = b
7986 } else {
8087 u , err := url .Parse (v )
@@ -118,27 +125,48 @@ func RunPreflights(interactive bool, output string, format string, args []string
118125 }
119126 }
120127
121- preflightContent , err = docrewrite .ConvertToV1Beta2 (preflightContent )
122- if err != nil {
123- return errors .Wrap (err , "failed to convert to v1beta2" )
124- }
128+ multidocs := strings .Split (string (preflightContent ), "\n ---\n " )
125129
126- troubleshootclientsetscheme .AddToScheme (scheme .Scheme )
127- decode := scheme .Codecs .UniversalDeserializer ().Decode
128- obj , _ , err := decode ([]byte (preflightContent ), nil , nil )
129- if err != nil {
130- return errors .Wrapf (err , "failed to parse %s" , v )
131- }
130+ for _ , doc := range multidocs {
132131
133- if spec , ok := obj .(* troubleshootv1beta2.Preflight ); ok {
134- if spec .Spec .UploadResultsTo == "" {
135- preflightSpec = ConcatPreflightSpec (preflightSpec , spec )
136- } else {
137- uploadResultSpecs = append (uploadResultSpecs , spec )
132+ type documentHead struct {
133+ Kind string `yaml:"kind"`
134+ }
135+
136+ var parsedDocHead documentHead
137+
138+ err := yaml .Unmarshal ([]byte (doc ), & parsedDocHead )
139+ if err != nil {
140+ return errors .Wrap (err , "failed to parse yaml" )
141+ }
142+
143+ if parsedDocHead .Kind != "Preflight" {
144+ continue
145+ }
146+
147+ preflightContent , err = docrewrite .ConvertToV1Beta2 ([]byte (doc ))
148+ if err != nil {
149+ return errors .Wrap (err , "failed to convert to v1beta2" )
150+ }
151+
152+ troubleshootclientsetscheme .AddToScheme (scheme .Scheme )
153+ decode := scheme .Codecs .UniversalDeserializer ().Decode
154+ obj , _ , err := decode ([]byte (preflightContent ), nil , nil )
155+ if err != nil {
156+ return errors .Wrapf (err , "failed to parse %s" , v )
157+ }
158+
159+ if spec , ok := obj .(* troubleshootv1beta2.Preflight ); ok {
160+ if spec .Spec .UploadResultsTo == "" {
161+ preflightSpec = ConcatPreflightSpec (preflightSpec , spec )
162+ } else {
163+ uploadResultSpecs = append (uploadResultSpecs , spec )
164+ }
165+ } else if spec , ok := obj .(* troubleshootv1beta2.HostPreflight ); ok {
166+ hostPreflightSpec = ConcatHostPreflightSpec (hostPreflightSpec , spec )
138167 }
139- } else if spec , ok := obj .(* troubleshootv1beta2.HostPreflight ); ok {
140- hostPreflightSpec = ConcatHostPreflightSpec (hostPreflightSpec , spec )
141168 }
169+
142170 }
143171
144172 var collectResults []CollectResult
0 commit comments