Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/crossplane/render/op/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Cmd struct {
IncludeContext bool `help:"Include the context in the rendered output as a resource of kind: Context." short:"c"`
IncludeFullOperation bool `help:"Include a direct copy of the input Operation's spec and metadata fields in the rendered output." short:"o"`
IncludeFunctionResults bool `help:"Include informational and warning messages from functions in the rendered output as resources of kind: Result." short:"r"`
RequiredResources string `help:"A YAML file or directory of YAML files specifying required resources to pass to the function pipeline." placeholder:"PATH" predictor:"yaml_file_or_directory" short:"e" type:"path"`
RequiredResources []string `help:"A YAML file or directory of YAML files specifying required resources to pass to the function pipeline. Provide multiple files by repeating the argument." placeholder:"PATH" predictor:"yaml_file_or_directory" short:"e" type:"path"`
RequiredSchemas string `help:"A directory of JSON files specifying OpenAPI schemas to pass to the function pipeline." placeholder:"DIR" predictor:"directory" type:"path"`
WatchedResource string `help:"A YAML file specifying the watched resource for WatchOperation rendering. The resource is also added to required resources." placeholder:"PATH" predictor:"yaml_file" short:"w" type:"existingfile"`

Expand Down Expand Up @@ -113,11 +113,12 @@ func (c *Cmd) Run(k *kong.Context, log logging.Logger, sp terminal.SpinnerPrinte

// Load required resources
rrs := []unstructured.Unstructured{}
if c.RequiredResources != "" {
rrs, err = render.LoadRequiredResources(c.fs, c.RequiredResources)
for _, path := range c.RequiredResources {
loaded, err := render.LoadRequiredResources(c.fs, path)
if err != nil {
return errors.Wrapf(err, "cannot load required resources from %q", c.RequiredResources)
return errors.Wrapf(err, "cannot load required resources from %q", path)
}
rrs = append(rrs, loaded...)
}

// Load required schemas
Expand Down
17 changes: 16 additions & 1 deletion cmd/crossplane/render/op/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,28 @@ func TestCmdRun(t *testing.T) {
cmd: Cmd{
Operation: "operation.yaml",
Functions: "functions.yaml",
RequiredResources: "missing.yaml",
RequiredResources: []string{"missing.yaml"},
Timeout: time.Minute,
fs: newTestFS(nil),
},
},
want: want{err: cmpopts.AnyError},
},
"MultipleRequiredResourcesFirstMissing": {
reason: "An error loading the first of multiple --required-resources files should propagate, not be silently dropped.",
args: args{
cmd: Cmd{
Operation: "operation.yaml",
Functions: "functions.yaml",
RequiredResources: []string{"missing.yaml", "resources-b.yaml"},
Timeout: time.Minute,
fs: newTestFS(map[string]string{
"resources-b.yaml": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: resource-b\n",
}),
},
},
want: want{err: cmpopts.AnyError},
},
"LoadRequiredSchemasError": {
reason: "Missing required schemas directory should return a wrapped load error.",
args: args{
Expand Down
21 changes: 10 additions & 11 deletions cmd/crossplane/render/xr/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ type Cmd struct {
IncludeFunctionResults bool `help:"Include informational and warning messages from Functions in the rendered output as resources of kind: Result." short:"r"`
IncludeFullXR bool `help:"Include a direct copy of the input XR's spec and metadata fields in the rendered output." short:"x"`
ObservedResources string `help:"A YAML file or directory of YAML files specifying the observed state of composed resources." placeholder:"PATH" predictor:"yaml_file_or_directory" short:"o" type:"path"`
ExtraResources string `help:"A YAML file or directory of YAML files specifying required resources (deprecated, use --required-resources)." placeholder:"PATH" predictor:"yaml_file_or_directory" type:"path"`
RequiredResources string `help:"A YAML file or directory of YAML files specifying required resources to pass to the Function pipeline." placeholder:"PATH" predictor:"yaml_file_or_directory" short:"e" type:"path"`
ExtraResources []string `help:"A YAML file or directory of YAML files specifying required resources (deprecated, use --required-resources). Provide multiple files by repeating the argument." placeholder:"PATH" predictor:"yaml_file_or_directory" type:"path"`
RequiredResources []string `help:"A YAML file or directory of YAML files specifying required resources to pass to the Function pipeline. Provide multiple files by repeating the argument." placeholder:"PATH" predictor:"yaml_file_or_directory" short:"e" type:"path"`
RequiredSchemas string `help:"A directory of JSON files specifying OpenAPI v3 schemas (from kubectl get --raw /openapi/v3/<group-version>)." placeholder:"DIR" predictor:"directory" short:"s" type:"path"`
IncludeContext bool `help:"Include the context in the rendered output as a resource of kind: Context." short:"c"`
FunctionCredentials string `help:"A YAML file or directory of YAML files specifying credentials to use for Functions to render the XR." placeholder:"PATH" predictor:"yaml_file_or_directory" type:"path"`
Expand Down Expand Up @@ -194,21 +194,20 @@ func (c *Cmd) Run(k *kong.Context, log logging.Logger, sp terminal.SpinnerPrinte
}

rrs := []unstructured.Unstructured{}
if c.RequiredResources != "" {
rrs, err = render.LoadRequiredResources(c.fs, c.RequiredResources)
for _, path := range c.RequiredResources {
loaded, err := render.LoadRequiredResources(c.fs, path)
if err != nil {
return errors.Wrapf(err, "cannot load required resources from %q", c.RequiredResources)
return errors.Wrapf(err, "cannot load required resources from %q", path)
}
rrs = append(rrs, loaded...)
}

if c.ExtraResources != "" {
ers, err := render.LoadRequiredResources(c.fs, c.ExtraResources)
for _, path := range c.ExtraResources {
loaded, err := render.LoadRequiredResources(c.fs, path)
if err != nil {
return errors.Wrapf(err, "cannot load extra resources from %q", c.ExtraResources)
return errors.Wrapf(err, "cannot load extra resources from %q", path)
}

// Merge extra resources into required resources.
rrs = append(rrs, ers...)
rrs = append(rrs, loaded...)
}

// Load required schemas
Expand Down
34 changes: 33 additions & 1 deletion cmd/crossplane/render/xr/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,45 @@ func TestCmdRun(t *testing.T) {
CompositeResource: "xr.yaml",
Composition: "composition.yaml",
Functions: "functions.yaml",
RequiredResources: "missing.yaml",
RequiredResources: []string{"missing.yaml"},
Timeout: time.Minute,
fs: newTestFS(nil),
},
},
want: want{err: cmpopts.AnyError},
},
"MultipleRequiredResourcesFirstMissing": {
reason: "An error loading the first of multiple --required-resources files should propagate, not be silently dropped.",
args: args{
cmd: Cmd{
CompositeResource: "xr.yaml",
Composition: "composition.yaml",
Functions: "functions.yaml",
RequiredResources: []string{"missing.yaml", "resources-b.yaml"},
Timeout: time.Minute,
fs: newTestFS(map[string]string{
"resources-b.yaml": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: resource-b\n",
}),
},
},
want: want{err: cmpopts.AnyError},
},
"MultipleExtraResourcesFirstMissing": {
reason: "An error loading the first of multiple --extra-resources files should propagate, not be silently dropped.",
args: args{
cmd: Cmd{
CompositeResource: "xr.yaml",
Composition: "composition.yaml",
Functions: "functions.yaml",
ExtraResources: []string{"missing.yaml", "resources-b.yaml"},
Timeout: time.Minute,
fs: newTestFS(map[string]string{
"resources-b.yaml": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: resource-b\n",
}),
},
},
want: want{err: cmpopts.AnyError},
},
"LoadRequiredSchemasError": {
reason: "Missing required schemas directory should return a wrapped load error.",
args: args{
Expand Down