Skip to content
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

config/fcos/v1_5_exp: use array of extension instead of string #316

Merged
merged 1 commit into from
Jan 27, 2022
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
3 changes: 3 additions & 0 deletions config/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ var (
ErrUserFieldSupport = errors.New("fields other than \"name\" and \"ssh_authorized_keys\" are not supported in this spec version")
ErrUserNameSupport = errors.New("users other than \"core\" are not supported in this spec version")
ErrKernelArgumentSupport = errors.New("this field cannot be used for kernel arguments in this spec version; use openshift.kernel_arguments instead")

// Extensions
ErrExtensionNameRequired = errors.New("field \"name\" is required")
)
8 changes: 5 additions & 3 deletions config/fcos/v1_5_exp/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

type Config struct {
base.Config `yaml:",inline"`
BootDevice BootDevice `yaml:"boot_device"`
Extensions Extensions `yaml:"extensions"`
BootDevice BootDevice `yaml:"boot_device"`
Extensions []Extension `yaml:"extensions"`
}

type BootDevice struct {
Expand All @@ -40,4 +40,6 @@ type BootDeviceMirror struct {
Devices []string `yaml:"devices"`
}

type Extensions []string
type Extension struct {
Name string `yaml:"name"`
}
7 changes: 5 additions & 2 deletions config/fcos/v1_5_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,14 @@ func (c Config) processPackages(options common.TranslateOptions) (types.Config,
if len(c.Extensions) == 0 {
return ret, ts, r
}

var extensions []string
for _, ex := range c.Extensions {
extensions = append(extensions, ex.Name)
}
treeFileContents, err := yaml.Marshal(&struct {
Packages []string `yaml:"packages"`
}{
Packages: c.Extensions,
Packages: extensions,
})
if err != nil {
r.AddOnError(yamlPath, err)
Expand Down
9 changes: 8 additions & 1 deletion config/fcos/v1_5_exp/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,14 @@ func TestTranslateExtensions(t *testing.T) {
// config with two extensions/packages
{
Config{
Extensions: []string{"strace", "zsh"},
Extensions: []Extension{
{
Name: "strace",
},
{
Name: "zsh",
},
},
},
types.Config{
Ignition: types.Ignition{
Expand Down
7 changes: 7 additions & 0 deletions config/fcos/v1_5_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ func (m BootDeviceMirror) Validate(c path.ContextPath) (r report.Report) {
}
return
}

func (e Extension) Validate(c path.ContextPath) (r report.Report) {
if e.Name == "" {
r.AddOnError(c.Append("name"), common.ErrExtensionNameRequired)
}
return
}
41 changes: 41 additions & 0 deletions config/fcos/v1_5_exp/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,44 @@ func TestValidateBootDevice(t *testing.T) {
})
}
}

// TestValidateExtension tests extension validation
func TestValidateExtension(t *testing.T) {
tests := []struct {
in Extension
out error
errPath path.ContextPath
}{
// No name field
{
Extension{},
common.ErrExtensionNameRequired,
path.New("yaml", "name"),
},
// complete config
{
Extension{
Name: "strace",
},
nil,
path.New("yaml"),
},
// empty string as name
{
Extension{
Name: "",
},
common.ErrExtensionNameRequired,
path.New("yaml", "name"),
},
}

for i, test := range tests {
t.Run(fmt.Sprintf("validate %d", i), func(t *testing.T) {
actual := test.in.Validate(path.New("yaml"))
expected := report.Report{}
expected.AddOnError(test.errPath, test.out)
assert.Equal(t, expected, actual, "bad validation report")
})
}
}
3 changes: 2 additions & 1 deletion docs/config-fcos-v1_5-exp.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ The Fedora CoreOS configuration is a YAML document conforming to the following s
* **_threshold_** (int): sets the minimum number of pieces required to decrypt the device. Default is 1.
* **_mirror_** (object): describes mirroring of the boot disk for fault tolerance.
* **_devices_** (list of strings): the list of whole-disk devices (not partitions) to include in the disk array, referenced by their absolute path. At least two devices must be specified.
* **_extensions_** (list of strings): a list of packages to layer on top of the OS.
* **_extensions_** (list of objects): the list of additional packages to be installed.
* **name** (string): the name of the package.

[part-types]: http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs
[rfc2397]: https://tools.ietf.org/html/rfc2397
Expand Down
3 changes: 2 additions & 1 deletion docs/config-openshift-v4_11-exp.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ The OpenShift configuration is a YAML document conforming to the following speci
* **_threshold_** (int): sets the minimum number of pieces required to decrypt the device. Default is 1.
* **_mirror_** (object): describes mirroring of the boot disk for fault tolerance.
* **_devices_** (list of strings): the list of whole-disk devices (not partitions) to include in the disk array, referenced by their absolute path. At least two devices must be specified.
* **_extensions_** (list of strings): a list of packages to layer on top of the OS.
* **_extensions_** (list of objects): the list of additional packages to be installed.
* **name** (string): the name of the package.
* **_openshift_** (object): describes miscellaneous OpenShift configuration. Respected when rendering to a MachineConfig, ignored when rendering directly to an Ignition config.
* **_kernel_type_** (string): which kernel to use on the node. Must be `default` or `realtime`.
* **_kernel_arguments_** (list of strings): arguments to be added to the kernel command line.
Expand Down