Merge pull request #1737 from anderbubble/issue-649

Make .ww suffix optional during wwctl overlay show --render
This commit is contained in:
Christian Goll
2025-02-13 15:14:27 +01:00
committed by GitHub
3 changed files with 22 additions and 4 deletions

View File

@@ -26,11 +26,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
overlayFile := overlay_.File(fileName)
if !util.IsFile(overlayFile) {
return fmt.Errorf("file: %s does not exist within overlay", overlayFile)
}
if NodeName == "" {
if !util.IsFile(overlayFile) {
return fmt.Errorf("%s: %s not found", overlayName, overlayFile)
}
f, err := os.ReadFile(overlayFile)
if err != nil {
return err
@@ -39,7 +39,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Output("%s", string(f))
} else {
if !util.IsFile(overlayFile) {
return fmt.Errorf("%s is not a file", overlayFile)
possibleFile := fmt.Sprintf("%s.ww", overlayFile)
if filepath.Ext(overlayFile) != ".ww" && util.IsFile(possibleFile) {
wwlog.Debug("found overlay template: %s", possibleFile)
overlayFile = possibleFile
} else {
return fmt.Errorf("%s: %s not found", overlayName, overlayFile)
}
}
if filepath.Ext(overlayFile) != ".ww" {
wwlog.Warn("%s lacks the '.ww' suffix, will not be rendered in an overlay", fileName)

View File

@@ -127,6 +127,17 @@ nodes:
assert.NoError(t, err)
assert.Contains(t, buf.String(), "testoverlay")
})
t.Run("overlay shows overlay without suffix", func(t *testing.T) {
baseCmd.SetArgs([]string{"-r", "node1", "testoverlay", "overlay"})
baseCmd := GetCommand()
buf := new(bytes.Buffer)
baseCmd.SetOut(buf)
baseCmd.SetErr(buf)
wwlog.SetLogWriter(buf)
err := baseCmd.Execute()
assert.NoError(t, err)
assert.Contains(t, buf.String(), "testoverlay")
})
t.Run("site overlays precede", func(t *testing.T) {
baseCmd.SetArgs([]string{"-r", "node1", "dist", "foo.ww"})
baseCmd := GetCommand()