Skip to content

Commit 54efe3e

Browse files
committed
core: pass --extract-yaml flag from platform to component (#376)
Previously holos render platform was not setting the --extract-yaml file when calling holos render component, causing data file instances defined in the Platform spec to be discarded. This patch passes the value along using the flag.
1 parent f693f04 commit 54efe3e

File tree

8 files changed

+63
-42
lines changed

8 files changed

+63
-42
lines changed

api/core/v1alpha5/types.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ type Component struct {
304304
// Injected as the tag variable "holos_component_path".
305305
Path string `json:"path" yaml:"path"`
306306
// Instances represents additional cue instance paths to unify with Path.
307-
// Useful to unify data files into a component BuildPlan.
307+
// Useful to unify data files into a component BuildPlan. Added in holos
308+
// 0.101.7.
308309
Instances []Instance `json:"instances,omitempty" yaml:"instances,omitempty"`
309310
// WriteTo represents the holos render component --write-to flag. If empty,
310311
// the default value for the --write-to flag is used.
@@ -323,18 +324,26 @@ type Component struct {
323324
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
324325
}
325326

326-
// Instance represents a data instance to unify with the configuration. Useful
327-
// to unify json and yaml files with cue configuration files.
327+
// Instance represents a data instance to unify with the configuration.
328+
//
329+
// Useful to unify json and yaml files with cue configuration files for
330+
// integration with other tools. For example, executing holos render platform
331+
// from a pull request workflow after [Kargo] executes the [yaml update] and
332+
// [git wait for pr] promotion steps.
333+
//
334+
// [Kargo]: https://docs.kargo.io/
335+
// [yaml update]: https://docs.kargo.io/references/promotion-steps#yaml-update
336+
// [git wait for pr]: https://docs.kargo.io/references/promotion-steps#git-wait-for-pr
328337
type Instance struct {
329338
// Kind is a discriminator.
330-
Kind string `json:"kind" yaml:"kind" cue:"\"extractYAML\""`
331-
// Ignored unless kind is extractYAML.
332-
ExtractYAML ExtractYAML `json:"extractYAML" yaml:"extractYAML"`
339+
Kind string `json:"kind" yaml:"kind" cue:"\"ExtractYAML\""`
340+
// Ignored unless kind is ExtractYAML.
341+
ExtractYAML ExtractYAML `json:"extractYAML,omitempty" yaml:"extractYAML,omitempty"`
333342
}
334343

335-
// ExtractYAML represents a cue data instance encoded as yaml. If Path refers to
336-
// a directory all files in the directory are extracted non-recursively.
337-
// Otherwise, path must refer to a file.
344+
// ExtractYAML represents a cue data instance encoded as yaml or json. If Path
345+
// refers to a directory all files in the directory are extracted
346+
// non-recursively. Otherwise, path must refer to a file.
338347
type ExtractYAML struct {
339-
Path string `json:"path,omitempty" yaml:"path,omitempty"`
348+
Path string `json:"path" yaml:"path"`
340349
}

doc/md/api/core.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ type Component struct {
172172
// Injected as the tag variable "holos_component_path".
173173
Path string `json:"path" yaml:"path"`
174174
// Instances represents additional cue instance paths to unify with Path.
175-
// Useful to unify data files into a component BuildPlan.
175+
// Useful to unify data files into a component BuildPlan. Added in holos
176+
// 0.101.7.
176177
Instances []Instance `json:"instances,omitempty" yaml:"instances,omitempty"`
177178
// WriteTo represents the holos render component --write-to flag. If empty,
178179
// the default value for the --write-to flag is used.
@@ -195,13 +196,11 @@ type Component struct {
195196
<a name="ExtractYAML"></a>
196197
## type ExtractYAML {#ExtractYAML}
197198

198-
ExtractYAML represents a cue data instance encoded as yaml. Holos extracts data of this kind using cue [encoding/yaml](<https://pkg.go.dev/encoding/yaml/>).
199-
200-
If Path refers to a directory, all files in the directory are extracted non\-recursively. Otherwise, path must refer to a file.
199+
ExtractYAML represents a cue data instance encoded as yaml or json. If Path refers to a directory all files in the directory are extracted non\-recursively. Otherwise, path must refer to a file.
201200

202201
```go
203202
type ExtractYAML struct {
204-
Path string `json:"path,omitempty" yaml:"path,omitempty"`
203+
Path string `json:"path" yaml:"path"`
205204
}
206205
```
207206

@@ -300,14 +299,16 @@ type Helm struct {
300299
<a name="Instance"></a>
301300
## type Instance {#Instance}
302301

303-
Instance represents a data instance to unify with the configuration. Useful to unify json and yaml files with cue configuration files.
302+
Instance represents a data instance to unify with the configuration.
303+
304+
Useful to unify json and yaml files with cue configuration files for integration with other tools. For example, executing holos render platform from a pull request workflow after [Kargo](<https://docs.kargo.io/>) executes the [yaml update](<https://docs.kargo.io/references/promotion-steps#yaml-update>) and [git wait for pr](<https://docs.kargo.io/references/promotion-steps#git-wait-for-pr>) promotion steps.
304305

305306
```go
306307
type Instance struct {
307308
// Kind is a discriminator.
308-
Kind string `json:"kind" yaml:"kind" cue:"\"extractYAML\""`
309-
// Ignored unless kind is extractYAML.
310-
ExtractYAML ExtractYAML `json:"extractYAML" yaml:"extractYAML"`
309+
Kind string `json:"kind" yaml:"kind" cue:"\"ExtractYAML\""`
310+
// Ignored unless kind is ExtractYAML.
311+
ExtractYAML ExtractYAML `json:"extractYAML,omitempty" yaml:"extractYAML,omitempty"`
311312
}
312313
```
313314

internal/builder/v1alpha5/builder.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,15 @@ func (c *Component) Path() string {
107107
return util.DotSlash(c.Component.Path)
108108
}
109109

110-
func (c *Component) Instances() ([]string, error) {
110+
// ExtractYAML returns the path values for the --extract-yaml command line flag.
111+
func (c *Component) ExtractYAML() ([]string, error) {
111112
if c == nil {
112113
return nil, nil
113114
}
114115
instances := make([]string, 0, len(c.Component.Instances))
115116
for _, instance := range c.Component.Instances {
116-
switch instance.Kind {
117-
case "extractYAML":
117+
if instance.Kind == "ExtractYAML" {
118118
instances = append(instances, instance.ExtractYAML.Path)
119-
default:
120-
return nil, errors.Format("unsupported instance kind: %s", instance.Kind)
121119
}
122120
}
123121
return instances, nil

internal/cli/render/render.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ func makeComponentRenderFunc(w io.Writer, prefixArgs, cliTags []string) func(con
150150
if err != nil {
151151
return errors.Wrap(err)
152152
}
153-
args := make([]string, 0, 10+len(prefixArgs)+(len(tags)*2))
153+
filepaths, err := component.ExtractYAML()
154+
if err != nil {
155+
return errors.Wrap(err)
156+
}
157+
args := make([]string, 0, 10+len(prefixArgs)+(len(tags)*2+len(filepaths)*2))
154158
args = append(args, prefixArgs...)
155159
args = append(args, "render", "component")
156160
for _, tag := range cliTags {
@@ -159,6 +163,9 @@ func makeComponentRenderFunc(w io.Writer, prefixArgs, cliTags []string) func(con
159163
for _, tag := range tags {
160164
args = append(args, "--inject", tag)
161165
}
166+
for _, path := range filepaths {
167+
args = append(args, "--extract-yaml", path)
168+
}
162169
args = append(args, component.Path())
163170
if _, err := util.RunCmdA(ctx, w, "holos", args...); err != nil {
164171
return errors.Format("could not render component: %w", err)

internal/cli/show.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ func makeBuildFunc(encoder holos.OrderedEncoder, opts holos.BuildOpts) func(cont
126126
return errors.Wrap(err)
127127
}
128128
tags = append(tags, opts.Tags...)
129-
instances, err := component.Instances()
129+
filepaths, err := component.ExtractYAML()
130130
if err != nil {
131131
return errors.Wrap(err)
132132
}
133-
inst, err := builder.LoadInstance(component.Path(), instances, tags)
133+
inst, err := builder.LoadInstance(component.Path(), filepaths, tags)
134134
if err != nil {
135135
return errors.Wrap(err)
136136
}

internal/generate/platforms/cue.mod/gen/github.com/holos-run/holos/api/core/v1alpha5/types_go_gen.cue

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ package core
335335
path: string @go(Path)
336336

337337
// Instances represents additional cue instance paths to unify with Path.
338-
// Useful to unify data files into a component BuildPlan.
338+
// Useful to unify data files into a component BuildPlan. Added in holos
339+
// 0.101.7.
339340
instances?: [...#Instance] @go(Instances,[]Instance)
340341

341342
// WriteTo represents the holos render component --write-to flag. If empty,
@@ -358,23 +359,27 @@ package core
358359
annotations?: {[string]: string} @go(Annotations,map[string]string)
359360
}
360361

361-
// Instance represents a data instance to unify with the configuration. Useful
362-
// to unify json and yaml files with cue configuration files.
362+
// Instance represents a data instance to unify with the configuration.
363+
//
364+
// Useful to unify json and yaml files with cue configuration files for
365+
// integration with other tools. For example, executing holos render platform
366+
// from a pull request workflow after [Kargo] executes the [yaml update] and
367+
// [git wait for pr] promotion steps.
368+
//
369+
// [Kargo]: https://docs.kargo.io/
370+
// [yaml update]: https://docs.kargo.io/references/promotion-steps#yaml-update
371+
// [git wait for pr]: https://docs.kargo.io/references/promotion-steps#git-wait-for-pr
363372
#Instance: {
364373
// Kind is a discriminator.
365-
kind: string & "extractYAML" @go(Kind)
374+
kind: string & "ExtractYAML" @go(Kind)
366375

367-
// Ignored unless kind is extractYAML.
368-
extractYAML: #ExtractYAML @go(ExtractYAML)
376+
// Ignored unless kind is ExtractYAML.
377+
extractYAML?: #ExtractYAML @go(ExtractYAML)
369378
}
370379

371-
// ExtractYAML represents a cue data instance encoded as yaml. Holos extracts data of
372-
// this kind using cue [encoding/yaml].
373-
//
374-
// If Path refers to a directory, all files in the directory are extracted
380+
// ExtractYAML represents a cue data instance encoded as yaml or json. If Path
381+
// refers to a directory all files in the directory are extracted
375382
// non-recursively. Otherwise, path must refer to a file.
376-
//
377-
// [yaml.Extract]: https://pkg.go.dev/cuelang.org/go@v0.11.0/encoding/yaml#Extract
378383
#ExtractYAML: {
379-
path?: string @go(Path)
384+
path: string @go(Path)
380385
}

internal/holos/interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type Platform interface {
2121
type Component interface {
2222
Describe() string
2323
Path() string
24-
Instances() ([]string, error)
24+
// ExtractYAML represents the values of the --extract-yaml flag
25+
ExtractYAML() ([]string, error)
2526
Tags() ([]string, error)
2627
WriteTo() string
2728
Labels() Labels

version/embedded/patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6
1+
7

0 commit comments

Comments
 (0)