@@ -183,37 +183,27 @@ func DetermineInputSpec(ctx context.Context, input Input) (*app.SnapshotSpec, *E
183183}
184184
185185func readSnapshotSource (input []byte ) (app.SnapshotSpec , error ) {
186- var v map [string ]interface {}
187-
188- // Since JSON is a subset of YAML, yaml.Unmarshal can be used directly.
189- if err := yaml .Unmarshal (input , & v ); err != nil {
190- log .Debugf ("Problem parsing application snapshot from input: %v" , err )
191- return app.SnapshotSpec {}, fmt .Errorf ("unable to parse Snapshot specification from input: %w" , err )
186+ // Define a temporary struct to capture the wrapped spec
187+ var wrapper struct {
188+ Spec * app.SnapshotSpec `yaml:"spec"`
192189 }
193190
194- // Extract the "spec" key from YAML, if present, to use as the snapshot.
195- if spec , ok := v ["spec" ]; ok {
196- v , ok = spec .(map [string ]interface {})
197- if ! ok {
198- return app.SnapshotSpec {}, fmt .Errorf ("spec is not a valid map structure" )
199- }
200- // Marshal the spec back to bytes for unmarshaling into SnapshotSpec
201- specBytes , err := yaml .Marshal (v )
202- if err != nil {
203- return app.SnapshotSpec {}, fmt .Errorf ("unable to marshal spec: %w" , err )
204- }
205- input = specBytes
191+ // Attempt to unmarshal into the wrapper to check for cluster record format
192+ if err := yaml .Unmarshal (input , & wrapper ); err == nil && wrapper .Spec != nil {
193+ // If successful and spec exists, return it directly
194+ log .Debugf ("Read application snapshot from cluster record format" )
195+ return * wrapper .Spec , nil
206196 }
207197
208- var file app. SnapshotSpec
209- err := yaml . Unmarshal ( input , & file )
210- if err != nil {
198+ // Fallback: unmarshal directly into SnapshotSpec for backward compatibility
199+ var spec app. SnapshotSpec
200+ if err := yaml . Unmarshal ( input , & spec ); err != nil {
211201 log .Debugf ("Problem parsing application snapshot from file %s" , input )
212202 return app.SnapshotSpec {}, fmt .Errorf ("unable to parse Snapshot specification from %s: %w" , input , err )
213203 }
214204
215205 log .Debugf ("Read application snapshot from file %s" , input )
216- return file , nil
206+ return spec , nil
217207}
218208
219209// For an image index, remove the original component and replace it with an expanded component with all its image manifests
0 commit comments