-
Notifications
You must be signed in to change notification settings - Fork 261
OCPBUGS-1272: Add pipe support to "opm alpha render-veneer basic" #1026
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
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 |
---|---|---|
|
@@ -118,7 +118,9 @@ func extractCSV(objs []string) string { | |
return "" | ||
} | ||
|
||
func readYAMLOrJSON(r io.Reader) (*DeclarativeConfig, error) { | ||
// LoadReader reads yaml or json from the passed in io.Reader and unmarshals it into a DeclarativeConfig struct. | ||
// Path references will not be de-referenced so callers are responsible for de-referencing if necessary. | ||
func LoadReader(r io.Reader) (*DeclarativeConfig, error) { | ||
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. What was the benefit of the rename? I may be missing some background but Reading between the lines ... is it because this interface was not exported? 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. I guess the reason I'd lean towards reader vs yaml or json is just because I feel like I'd be more likely to assume that readYAMLOrJSON would take yaml or json as an input vs a reader, but I'm also not super wedded to it. 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. IMO, its because we're going to export it, and since we're exporting it, we're following the pattern of the other exported functions that return |
||
cfg := &DeclarativeConfig{} | ||
dec := yaml.NewYAMLOrJSONDecoder(r, 4096) | ||
for { | ||
|
@@ -173,7 +175,7 @@ func LoadFile(root fs.FS, path string) (*DeclarativeConfig, error) { | |
} | ||
defer file.Close() | ||
|
||
cfg, err := readYAMLOrJSON(file) | ||
cfg, err := LoadReader(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ package basic | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"path/filepath" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/operator-framework/operator-registry/alpha/action" | ||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
|
@@ -15,30 +14,8 @@ type Veneer struct { | |
Registry image.Registry | ||
} | ||
|
||
func (v Veneer) Render(ctx context.Context, ref string) (*declcfg.DeclarativeConfig, error) { | ||
// only taking first argument as file | ||
stat, serr := os.Stat(ref) | ||
if serr != nil { | ||
return nil, serr | ||
} | ||
|
||
if stat.IsDir() { | ||
return nil, errors.New("cannot render veneers by directory reference") | ||
} | ||
return v.renderFile(ctx, ref) | ||
} | ||
|
||
func (v Veneer) renderFile(ctx context.Context, ref string) (*declcfg.DeclarativeConfig, error) { | ||
// xform any relative to absolute paths | ||
abspath, err := filepath.Abs(ref) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// xform to break apart dir/file elements | ||
rpath, fname := filepath.Split(abspath) | ||
root := os.DirFS(rpath) | ||
|
||
cfg, err := declcfg.LoadFile(root, fname) | ||
func (v Veneer) Render(ctx context.Context, reader io.Reader) (*declcfg.DeclarativeConfig, error) { | ||
cfg, err := declcfg.LoadReader(reader) | ||
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. We were originally using declcfg.LoadFile here because we wanted the follow-on call to readBundleObjects. Do we no longer want that? 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.
The root of the problem is essentially that the basic veneer input is not the same as FBC, but we're using FBC loaders because the basic veneer input is "close" to FBC. |
||
if err != nil { | ||
return cfg, err | ||
} | ||
|
@@ -52,8 +29,7 @@ func (v Veneer) renderFile(ctx context.Context, ref string) (*declcfg.Declarativ | |
|
||
for _, b := range cfg.Bundles { | ||
if !isBundleVeneer(&b) { | ||
outb = append(outb, b) | ||
continue | ||
return nil, fmt.Errorf("unexpected fields present in basic veneer bundle") | ||
} | ||
r.Refs = []string{b.Image} | ||
contributor, err := r.Run(ctx) | ||
|
@@ -67,7 +43,8 @@ func (v Veneer) renderFile(ctx context.Context, ref string) (*declcfg.Declarativ | |
return cfg, nil | ||
} | ||
|
||
// isBundleVeneer identifies loaded partial Bundle data from YAML/JSON veneer source as having no properties, | ||
// isBundleVeneer identifies a Bundle veneer source as having a Schema and Image defined | ||
// but no Properties, RelatedImages or Package defined | ||
func isBundleVeneer(b *declcfg.Bundle) bool { | ||
return len(b.Properties) == 0 | ||
return b.Schema != "" && b.Image != "" && b.Package == "" && len(b.Properties) == 0 && len(b.RelatedImages) == 0 | ||
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. We should have the field restrictions for the simple veneer documented, specifically the hard requirement for prohibited fields. The error message isn't very helpful here. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package veneer | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
@@ -16,3 +19,11 @@ func NewCmd() *cobra.Command { | |
|
||
return runCmd | ||
} | ||
|
||
func openFileOrStdin(cmd *cobra.Command, args []string) (io.ReadCloser, string, error) { | ||
if len(args) == 0 || args[0] == "-" { | ||
return io.NopCloser(cmd.InOrStdin()), "stdin", nil | ||
} | ||
reader, err := os.Open(args[0]) | ||
return reader, args[0], err | ||
} | ||
Comment on lines
+23
to
+29
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. yay, re-use! |
Uh oh!
There was an error while loading. Please reload this page.