mantle/platform/conf: Panic on additions to an empty config
Adding anything to an empty config does not make sense and can lead to
subtle bugs.
@@ -92,12 +92,16 @@ type Conf struct {
ignitionV32exp *v32exptypes.Config
}
+// Empty creates a completely empty configuration. Any configuration addition
+// applied to an empty config triggers a panic.
func Empty() *UserData {
return &UserData{
kind: kindEmpty,
}
}
+// ContainerLinuxConfig creates a Container Linux Config Userdata struct from
+// the provided string.
func ContainerLinuxConfig(data string) *UserData {
return &UserData{
kind: kindContainerLinuxConfig,
@@ -596,6 +600,8 @@ func (c *Conf) AddFile(path, filesystem, contents string, mode int) {
c.addFileV23(path, filesystem, contents, mode)
} else if c.ignitionV24 != nil {
c.addFileV24(path, filesystem, contents, mode)
+ } else {
+ panic("Could not find a supported Ignition config version")
}
}
@@ -725,6 +731,8 @@ func (c *Conf) AddSystemdUnit(name, contents string, state systemdUnitState) {
c.addSystemdUnitV31(name, contents, enable, mask)
} else if c.ignitionV32exp != nil {
c.addSystemdUnitV32exp(name, contents, enable, mask)
+ } else {
+ panic("Could not find a supported Ignition config version")
}
}
@@ -921,6 +929,8 @@ func (c *Conf) AddSystemdUnitDropin(service, name, contents string) {
c.addSystemdDropinV31(service, name, contents)
} else if c.ignitionV32exp != nil {
c.addSystemdDropinV32exp(service, name, contents)
+ } else {
+ panic("Could not find a supported Ignition config version")
}
}
@@ -1092,6 +1102,8 @@ func (c *Conf) AddAuthorizedKeys(user string, keys []string) {
c.addAuthorizedKeysV31(user, keys)
} else if c.ignitionV32exp != nil {
c.addAuthorizedKeysV32exp(user, keys)
+ } else {
+ panic("Could not find a supported Ignition config version")
}
}
@@ -1235,6 +1247,8 @@ func (c *Conf) AddConfigSource(source string) {
c.addConfigSourceV31(source)
} else if c.ignitionV32exp != nil {
c.addConfigSourceV32exp(source)
+ } else {
+ panic("Could not find a supported Ignition config version")
}
}
