11package render
22
33import (
4+ "encoding/json"
5+ "fmt"
46 "io"
57 "log"
68 "os"
@@ -12,6 +14,7 @@ import (
1214 "github.com/operator-framework/operator-registry/alpha/action"
1315 "github.com/operator-framework/operator-registry/alpha/action/migrations"
1416 "github.com/operator-framework/operator-registry/alpha/declcfg"
17+ "github.com/operator-framework/operator-registry/alpha/property"
1518 "github.com/operator-framework/operator-registry/cmd/opm/internal/util"
1619 "github.com/operator-framework/operator-registry/pkg/sqlite"
1720)
@@ -24,6 +27,7 @@ func NewCmd(showAlphaHelp bool) *cobra.Command {
2427
2528 oldMigrateAllFlag bool
2629 migrateLevel string
30+ includeCsvSpecs bool
2731 )
2832 cmd := & cobra.Command {
2933 Use : "render [catalog-image | catalog-directory | bundle-image | bundle-directory | sqlite-file]..." ,
@@ -84,12 +88,38 @@ database files.
8488 log .Fatal (err )
8589 }
8690
91+ if includeCsvSpecs {
92+ for i , bi := range cfg .Bundles {
93+ if bi .CsvJSON != "" {
94+ cfg .Bundles [i ].Properties = append (cfg .Bundles [i ].Properties , property.Property {Type : "olm.csv.spec" , Value : json .RawMessage (bi .CsvJSON )})
95+ }
96+ fmt .Printf ("no CSV available for bundle %s, attempting to render CSV spec from image reference\n " , bi .Image )
97+ brender := action.Render {
98+ Refs : []string {bi .Image },
99+ Registry : reg ,
100+ AllowedRefMask : action .RefBundleImage ,
101+ Migrations : m ,
102+ }
103+ bfbc , err := brender .Run (cmd .Context ())
104+ if err != nil {
105+ log .Fatal (err )
106+ }
107+ for _ , b := range bfbc .Bundles {
108+ // assumes only the specified bundle is in the results
109+ if b .CsvJSON != "" {
110+ cfg .Bundles [i ].Properties = append (cfg .Bundles [i ].Properties , property.Property {Type : "olm.csv.spec" , Value : json .RawMessage (b .CsvJSON )})
111+ }
112+ }
113+ }
114+ }
115+
87116 if err := write (* cfg , os .Stdout ); err != nil {
88117 log .Fatal (err )
89118 }
90119 },
91120 }
92121 cmd .Flags ().StringVarP (& output , "output" , "o" , "json" , "Output format of the streamed file-based catalog objects (json|yaml)" )
122+ cmd .Flags ().BoolVar (& includeCsvSpecs , "include-csv-specs" , false , "Include CSV specs in the rendered file-based catalog objects" )
93123
94124 cmd .Flags ().StringVar (& migrateLevel , "migrate-level" , "" , "Name of the last migration to run (default: none)\n " + migrations .HelpText ())
95125 cmd .Flags ().BoolVar (& oldMigrateAllFlag , "migrate" , false , "Perform all available schema migrations on the rendered FBC" )
0 commit comments