warn instead of error, lift logic to main.go

Signed-off-by: Evan Miller <miller.evan815@gmail.com>
This commit is contained in:
Evan Miller
2025-07-02 18:20:35 -07:00
parent 4b1f7bcb9a
commit 31b4efcaec
12 changed files with 46 additions and 27 deletions

View File

@ -574,6 +574,20 @@ func warnIfAmbiguousName(unit *parser.UnitFile, group string) {
}
}
// Warns if the unit has any properties defined in the Service group that are known to cause issues.
// We want to warn instead of erroring to avoid breaking any existing users' units,
// or to allow users to use these properties if they know what they are doing.
// We implement this here instead of in quadlet.initServiceUnitFile to avoid
// having to refactor a large amount of code in the generator just for a warning.
func warnIfUnsupportedServiceKeys(unit *parser.UnitFile) {
for _, key := range quadlet.UnsupportedServiceKeys {
_, hasKey := unit.Lookup(quadlet.ServiceGroup, key)
if hasKey {
Logf("Warning: using key %s in the Service group is not supported - use at your own risk", key)
}
}
}
func generateUnitsInfoMap(units []*parser.UnitFile) map[string]*quadlet.UnitInfo {
unitsInfoMap := make(map[string]*quadlet.UnitInfo)
for _, unit := range units {
@ -722,6 +736,8 @@ func process() bool {
var service *parser.UnitFile
var warnings, err error
warnIfUnsupportedServiceKeys(unit)
switch {
case strings.HasSuffix(unit.Filename, ".container"):
warnIfAmbiguousName(unit, quadlet.ContainerGroup)