Skip to content

Commit 2fd9762

Browse files
committed
feat: update podman quadlet sub-command
Fixes: #28118 Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
1 parent 246016a commit 2fd9762

14 files changed

Lines changed: 514 additions & 648 deletions

File tree

cmd/podman/quadlet/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func installFlags(cmd *cobra.Command) {
3737
flags := cmd.Flags()
3838
flags.BoolVar(&installOptions.ReloadSystemd, "reload-systemd", true, "Reload systemd after installing Quadlets")
3939
flags.BoolVarP(&installOptions.Replace, "replace", "r", false, "Replace the installation even if the quadlet already exists")
40+
flags.StringVar(&installOptions.Application, "application", "", "Group quadlets and associated file in a directory named after the application")
41+
_ = quadletInstallCmd.RegisterFlagCompletionFunc("application", completion.AutocompleteNone)
4042
}
4143

4244
func init() {

cmd/podman/quadlet/remove.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var (
1515
quadletRmDescription = `Remove one or more installed Quadlets from the current user`
1616

1717
quadletRmCmd = &cobra.Command{
18-
Use: "rm [options] QUADLET [QUADLET...]",
18+
Use: "rm [options] [QUADLET] [QUADLET...]",
1919
Short: "Remove Quadlets",
2020
Long: quadletRmDescription,
2121
RunE: rm,
@@ -35,6 +35,7 @@ func rmFlags(cmd *cobra.Command) {
3535
flags.BoolVarP(&removeOptions.All, "all", "a", false, "Remove all Quadlets for the current user")
3636
flags.BoolVarP(&removeOptions.Ignore, "ignore", "i", false, "Do not error for Quadlets that do not exist")
3737
flags.BoolVar(&removeOptions.ReloadSystemd, "reload-systemd", true, "Reload systemd after removal")
38+
flags.BoolVar(&removeOptions.Recursive, "recursive", true, "Used to remove application")
3839
}
3940

4041
func init() {

cmd/quadlet/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func process() bool {
478478
Debugf("Starting quadlet-generator, output to: %s", outputPath)
479479
}
480480

481-
sourcePathsMap := quadlet.GetUnitDirs(isUserFlag)
481+
sourcePathsMap := quadlet.GetUnitDirs(isUserFlag, true)
482482

483483
var units []*parser.UnitFile
484484
for _, d := range sourcePathsMap {

docs/source/markdown/podman-quadlet-install.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Note: In case user wants to install Quadlet application then first path should b
2424

2525
## OPTIONS
2626

27+
#### **--application**
28+
29+
You can specify an application name, all files will be installed under a directory with the application name.
30+
31+
2732
#### **--reload-systemd**
2833

2934
Reload systemd after installing Quadlets (default true).

docs/source/markdown/podman-quadlet-rm.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Remove running quadlets.
2929

3030
Do not error for Quadlets that do not exist.
3131

32+
#### **--recursive**
33+
34+
When an application name is specified, you need to specify --recursive flag to remove all the Quadlets which belongs to that specific application.
35+
3236
#### **--reload-systemd**
3337

3438
Reload systemd after removing Quadlets (default true).

pkg/api/handlers/libpod/quadlets.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ func InstallQuadlets(w http.ResponseWriter, r *http.Request) {
180180

181181
// Parse query parameters
182182
query := struct {
183-
Replace bool `schema:"replace"`
184-
ReloadSystemd bool `schema:"reload-systemd"`
183+
Replace bool `schema:"replace"`
184+
ReloadSystemd bool `schema:"reload-systemd"`
185+
Application string `schema:"application"`
185186
}{
186187
Replace: false,
187188
ReloadSystemd: true, // Default to true like CLI
189+
Application: "",
188190
}
189191

190192
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
@@ -227,18 +229,15 @@ func InstallQuadlets(w http.ResponseWriter, r *http.Request) {
227229
countQuadletFiles++
228230
}
229231
}
230-
switch {
231-
case countQuadletFiles > 1:
232-
utils.Error(w, http.StatusBadRequest, fmt.Errorf("only a single quadlet file is allowed per request"))
233-
return
234-
case countQuadletFiles == 0:
232+
if countQuadletFiles == 0 {
235233
utils.Error(w, http.StatusBadRequest, fmt.Errorf("no quadlet files found in request"))
236234
return
237235
}
238236

239237
containerEngine := abi.ContainerEngine{Libpod: runtime}
240238
installOptions := entities.QuadletInstallOptions{
241239
Replace: query.Replace,
240+
Application: query.Application,
242241
ReloadSystemd: query.ReloadSystemd,
243242
}
244243

@@ -268,6 +267,7 @@ func RemoveQuadlet(w http.ResponseWriter, r *http.Request) {
268267
Force bool `schema:"force"`
269268
Ignore bool `schema:"ignore"`
270269
ReloadSystemd bool `schema:"reload-systemd"`
270+
Recursive bool `schema:"recursive"`
271271
}{
272272
ReloadSystemd: true, // Default to true like CLI
273273
}
@@ -288,6 +288,7 @@ func RemoveQuadlet(w http.ResponseWriter, r *http.Request) {
288288
Force: query.Force,
289289
Ignore: query.Ignore,
290290
ReloadSystemd: query.ReloadSystemd,
291+
Recursive: query.Recursive,
291292
}
292293

293294
removeReport, err := containerEngine.QuadletRemove(r.Context(), []string{name}, removeOptions)
@@ -324,6 +325,7 @@ func RemoveQuadlets(w http.ResponseWriter, r *http.Request) {
324325
Force bool `schema:"force"`
325326
Ignore bool `schema:"ignore"`
326327
ReloadSystemd bool `schema:"reload-systemd"`
328+
Recursive bool `schema:"recursive"`
327329
Quadlets []string `schema:"quadlets"`
328330
}{
329331
ReloadSystemd: true, // Default to true like CLI
@@ -352,6 +354,7 @@ func RemoveQuadlets(w http.ResponseWriter, r *http.Request) {
352354
All: query.All,
353355
Ignore: query.Ignore,
354356
ReloadSystemd: query.ReloadSystemd,
357+
Recursive: query.Recursive,
355358
}
356359

357360
removeReport, err := containerEngine.QuadletRemove(r.Context(), query.Quadlets, removeOptions)

pkg/domain/entities/quadlet.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type QuadletInstallOptions struct {
66
ReloadSystemd bool
77
// Replace the installation even if the quadlet already exists
88
Replace bool
9+
// The application to install the quadlet to
10+
Application string // TODO: validate this is only alphabetical / numerical characters
911
}
1012

1113
// QuadletInstallReport contains the output of the `quadlet install` command
@@ -56,6 +58,8 @@ type QuadletRemoveOptions struct {
5658
Ignore bool
5759
// ReloadSystemd determines whether systemd will be reloaded after the Quadlet is removed.
5860
ReloadSystemd bool
61+
// You can specify recursive when targeting an application
62+
Recursive bool
5963
}
6064

6165
// QuadletRemoveReport contains the results of an operation to remove obe or more quadlets

0 commit comments

Comments
 (0)