Skip to content
Merged
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
25 changes: 16 additions & 9 deletions schemas/lab/talos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,32 @@ The CUE schema is the source of truth; Go types are generated from `schema.cue`.

## Example

The minimum valid configuration relies on schema defaults for the Image
Factory URL, schematic ID, platform, architecture, artifact, output format,
output directory, and the boot/cidata artifact filenames:

```cue
package images

import talos "github.com/gilmanlab/platform/schemas/lab/talos"

build: talos.#ImageBuild & {
name: "bootstrap-talos-controlplane"
source: {
version: "v1.13.0"
}
source: version: "v1.13.0"
config: {
userData: path: "controlplane.yaml"
metaData: localHostname: "bootstrap-controlplane-1"
}
output: {
dir: ".state/images/talos-bootstrap"
format: "img"
bootArtifactName: "talos-bootstrap-amd64.img"
configArtifactName: "talos-bootstrap-cidata.img"
}
}
```

Override any default by setting the field explicitly. For example, to land
artifacts in a different directory with bespoke filenames:

```cue
build: output: {
dir: ".state/images/talos-bootstrap"
bootArtifactName: "talos-bootstrap-amd64.img"
configArtifactName: "talos-bootstrap-cidata.img"
}
```
18 changes: 11 additions & 7 deletions schemas/lab/talos/cue_types_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions schemas/lab/talos/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ package talos
#ImageOutput: {
@go(ImageOutput)

// Dir is the output directory for generated artifacts.
dir!: #NonEmptyString
// Dir is the output directory for generated artifacts. Must be a
// repo-relative path; defaults to ".state/images".
dir: *".state/images" | #RelativePath
// Format is the local artifact format.
format: #OutputFormat
// BootArtifactName is the Talos boot disk IMG filename.
bootArtifactName!: #ArtifactName @go(BootArtifactName)
// ConfigArtifactName is the NoCloud cidata IMG filename.
configArtifactName!: #ArtifactName @go(ConfigArtifactName)
// BootArtifactName is the Talos boot disk IMG filename. Defaults to
// "talos-boot.img".
bootArtifactName: *"talos-boot.img" | #ArtifactName @go(BootArtifactName)
// ConfigArtifactName is the NoCloud cidata IMG filename. Defaults to
// "talos-cidata.img".
configArtifactName: *"talos-cidata.img" | #ArtifactName @go(ConfigArtifactName)
}

// ImageBuild is the top-level Talos image download and config packaging contract.
Expand All @@ -117,6 +120,7 @@ package talos
source!: #ImageSource
// Config describes Talos machine configuration delivery.
config!: #MachineConfig
// Output describes the local artifacts produced by the build.
output!: #ImageOutput
// Output describes the local artifacts produced by the build. Every
// field has a default, so authors can omit the block entirely.
output: #ImageOutput
}
14 changes: 14 additions & 0 deletions tools/labctl/cmd/labctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ output:
return err
}

minimalConfig := fmt.Appendf(nil, `name: talos-test
source:
factoryURL: %s
version: v1.13.0
config:
userData:
path: controlplane.yaml
metaData:
localHostname: bootstrap-controlplane-1
`, server.URL)
if err := os.WriteFile(filepath.Join(env.WorkDir, "talos-minimal.yaml"), minimalConfig, 0o600); err != nil {
return err
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ stdout '"arch":"amd64"'
stdout '"format":"img"'
! stderr .

exec labctl bootstrap talos image build talos-minimal.yaml
exists .state/images/talos-boot.img
exists .state/images/talos-cidata.img
! stderr .

-- invalid.yaml --
name: talos-test
source:
Expand Down
19 changes: 19 additions & 0 deletions tools/labctl/internal/adapters/talosconfig/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,22 @@ output:
configArtifactName: talos-cidata.img
`
}

func TestValidateYAMLAppliesOutputDefaults(t *testing.T) {
minimal := `name: talos-test
source:
version: v1.13.0
config:
userData:
path: controlplane.yaml
metaData:
localHostname: bootstrap-controlplane-1
`
config, err := talosconfig.New().ValidateYAML("minimal.yaml", []byte(minimal))

require.NoError(t, err)
assert.Equal(t, ".state/images", config.Output.Dir)
assert.Equal(t, "talos-boot.img", config.Output.BootArtifactName)
assert.Equal(t, "talos-cidata.img", config.Output.ConfigArtifactName)
assert.Equal(t, "img", string(config.Output.Format))
}
6 changes: 3 additions & 3 deletions tools/labctl/internal/app/talosimage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,16 @@ type buildPaths struct {
}

func resolvePaths(baseDir string, output schematalos.ImageOutput) (buildPaths, error) {
outputDir, err := resolvePath(baseDir, string(output.Dir))
outputDir, err := resolvePath(baseDir, output.Dir)
if err != nil {
return buildPaths{}, err
}

return buildPaths{
downloadsDir: filepath.Join(filepath.Dir(outputDir), "downloads", "talos"),
outputDir: outputDir,
bootArtifactPath: filepath.Join(outputDir, string(output.BootArtifactName)),
configArtifactPath: filepath.Join(outputDir, string(output.ConfigArtifactName)),
bootArtifactPath: filepath.Join(outputDir, output.BootArtifactName),
configArtifactPath: filepath.Join(outputDir, output.ConfigArtifactName),
}, nil
}

Expand Down
Loading