From b56fc19f9e56a1e2c22c7154b58782cbef54b653 Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Tue, 11 Feb 2025 08:59:29 -0700 Subject: [PATCH] Added `wwctl image build --syncuser` - #1321 Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 1 + internal/app/wwctl/image/build/main.go | 15 +++++++++++++-- internal/app/wwctl/image/build/root.go | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 537a78e1..042ce38b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added support for comma-separated hostlist patterns. #1635 - Added default value for `warewulf.conf:dhcp.template`. #1725 - Added `UniqueField` template function. #829 +- Added `wwctl image build --syncuser`. #1321 ### Changed diff --git a/internal/app/wwctl/image/build/main.go b/internal/app/wwctl/image/build/main.go index e0ea2e34..5be4171b 100644 --- a/internal/app/wwctl/image/build/main.go +++ b/internal/app/wwctl/image/build/main.go @@ -1,16 +1,27 @@ package build import ( + "fmt" + "github.com/spf13/cobra" - "github.com/warewulf/warewulf/internal/pkg/api/image" + apiimage "github.com/warewulf/warewulf/internal/pkg/api/image" "github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1" + "github.com/warewulf/warewulf/internal/pkg/image" ) func CobraRunE(cmd *cobra.Command, args []string) error { + if SyncUser { + for _, name := range args { + if err := image.SyncUids(name, true); err != nil { + return fmt.Errorf("syncuser error: %w", err) + } + } + } + cbp := &wwapiv1.ImageBuildParameter{ ImageNames: args, Force: BuildForce, All: BuildAll, } - return image.ImageBuild(cbp) + return apiimage.ImageBuild(cbp) } diff --git a/internal/app/wwctl/image/build/root.go b/internal/app/wwctl/image/build/root.go index c66aff54..a5cd53ed 100644 --- a/internal/app/wwctl/image/build/root.go +++ b/internal/app/wwctl/image/build/root.go @@ -23,11 +23,13 @@ var ( } BuildForce bool BuildAll bool + SyncUser bool ) func init() { baseCmd.PersistentFlags().BoolVarP(&BuildAll, "all", "a", false, "(re)Build all images") baseCmd.PersistentFlags().BoolVarP(&BuildForce, "force", "f", false, "Force rebuild, even if it isn't necessary") + baseCmd.PersistentFlags().BoolVar(&SyncUser, "syncuser", false, "Synchronize UIDs/GIDs from host to image") } // GetRootCommand returns the root cobra.Command for the application.