Skip to content

Commit 02876a9

Browse files
committed
Rename term "protected" to "pinned"
see discussion in #23217 Signed-off-by: tobwen <[email protected]>
1 parent 4814224 commit 02876a9

File tree

18 files changed

+160
-160
lines changed

18 files changed

+160
-160
lines changed

cmd/podman/system/prune.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func init() {
5151
flags.BoolVar(&pruneOptions.External, "external", false, "Remove container data in storage not controlled by podman")
5252
flags.BoolVar(&pruneOptions.Build, "build", false, "Remove build containers")
5353
flags.BoolVar(&pruneOptions.Volume, "volumes", false, "Prune volumes")
54-
flags.BoolVar(&includeProtected, "include-protected", false, "Include protected volumes in prune operation")
54+
flags.BoolVar(&includeProtected, "include-pinned", false, "Include pinned volumes in prune operation")
5555
filterFlagName := "filter"
5656
flags.StringArrayVar(&filters, filterFlagName, []string{}, "Provide filter values (e.g. 'label=<key>=<value>')")
5757
_ = pruneCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePruneFilters)
@@ -83,9 +83,9 @@ func prune(cmd *cobra.Command, args []string) error {
8383
}
8484
}
8585

86-
// Set the include protected flag for volume pruning
86+
// Set the include pinned flag for volume pruning
8787
if pruneOptions.Volume {
88-
pruneOptions.VolumePruneOptions.IncludeProtected = includeProtected
88+
pruneOptions.VolumePruneOptions.IncludePinned = includeProtected
8989
}
9090

9191
// Remove all unused pods, containers, images, networks, and volume data.
@@ -94,9 +94,9 @@ func prune(cmd *cobra.Command, args []string) error {
9494
return err
9595
}
9696

97-
// Set the include protected flag for volume pruning
97+
// Set the include pinned flag for volume pruning
9898
if pruneOptions.Volume {
99-
pruneOptions.VolumePruneOptions.IncludeProtected = includeProtected
99+
pruneOptions.VolumePruneOptions.IncludePinned = includeProtected
100100
}
101101

102102
response, err := registry.ContainerEngine().SystemPrune(context.Background(), pruneOptions)
@@ -138,9 +138,9 @@ func prune(cmd *cobra.Command, args []string) error {
138138
}
139139

140140
func createPruneWarningMessage(pruneOpts entities.SystemPruneOptions) string {
141-
protectedNote := ""
142-
if pruneOpts.Volume && !pruneOpts.VolumePruneOptions.IncludeProtected {
143-
protectedNote = " (excluding protected volumes)"
141+
pinnedNote := ""
142+
if pruneOpts.Volume && !pruneOpts.VolumePruneOptions.IncludePinned {
143+
pinnedNote = " (excluding pinned volumes)"
144144
}
145145

146146
if pruneOpts.All {
@@ -154,7 +154,7 @@ func createPruneWarningMessage(pruneOpts entities.SystemPruneOptions) string {
154154
}
155155
return `WARNING! This command removes:
156156
- all stopped containers
157-
- all networks not used by at least one container%s%s` + protectedNote + `
157+
- all networks not used by at least one container%s%s` + pinnedNote + `
158158
- all dangling images
159159
- all dangling build cache
160160

cmd/podman/volumes/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ func init() {
7070
flags.IntVar(&opts.GID, gidFlagName, 0, "Set the GID of the volume owner")
7171
_ = createCommand.RegisterFlagCompletionFunc(gidFlagName, completion.AutocompleteNone)
7272

73-
protectedFlagName := "protected"
74-
flags.BoolVar(&opts.Protected, protectedFlagName, false, "Mark volume as protected (excluded from system prune by default)")
75-
_ = createCommand.RegisterFlagCompletionFunc(protectedFlagName, completion.AutocompleteNone)
73+
pinnedFlagName := "pinned"
74+
flags.BoolVar(&opts.Protected, pinnedFlagName, false, "Mark volume as pinned (excluded from system prune by default)")
75+
_ = createCommand.RegisterFlagCompletionFunc(pinnedFlagName, completion.AutocompleteNone)
7676
}
7777

7878
func create(cmd *cobra.Command, args []string) error {
@@ -99,7 +99,7 @@ func create(cmd *cobra.Command, args []string) error {
9999
if cmd.Flags().Changed("gid") {
100100
createOpts.GID = &opts.GID
101101
}
102-
createOpts.Protected = opts.Protected
102+
createOpts.Pinned = opts.Protected
103103
response, err := registry.ContainerEngine().VolumeCreate(context.Background(), createOpts)
104104
if err != nil {
105105
return err

cmd/podman/volumes/pin.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package volumes
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/containers/podman/v5/cmd/podman/common"
8+
"github.com/containers/podman/v5/cmd/podman/registry"
9+
"github.com/containers/podman/v5/pkg/domain/entities"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var (
14+
pinDescription = `Mark or unmark a volume as pinned.
15+
16+
Pinned volumes are excluded from system prune operations by default.`
17+
18+
pinCommand = &cobra.Command{
19+
Use: "pin [options] VOLUME [VOLUME...]",
20+
Short: "Mark or unmark volume as pinned",
21+
Long: pinDescription,
22+
RunE: pin,
23+
ValidArgsFunction: common.AutocompleteVolumes,
24+
Example: `podman volume pin myvol
25+
podman volume pin --unpin myvol
26+
podman volume pin vol1 vol2 vol3`,
27+
}
28+
)
29+
30+
var (
31+
pinOptions = entities.VolumePinOptions{}
32+
)
33+
34+
func init() {
35+
registry.Commands = append(registry.Commands, registry.CliCommand{
36+
Command: pinCommand,
37+
Parent: volumeCmd,
38+
})
39+
flags := pinCommand.Flags()
40+
flags.BoolVar(&pinOptions.Unpin, "unpin", false, "Remove pinning from volume")
41+
}
42+
43+
func pin(cmd *cobra.Command, args []string) error {
44+
if len(args) < 1 {
45+
return fmt.Errorf("must specify at least one volume name")
46+
}
47+
48+
responses, err := registry.ContainerEngine().VolumePin(context.Background(), args, pinOptions)
49+
if err != nil {
50+
return err
51+
}
52+
53+
for _, r := range responses {
54+
if r.Err != nil {
55+
fmt.Printf("Error pinning volume %s: %v\n", r.Id, r.Err)
56+
} else {
57+
if pinOptions.Unpin {
58+
fmt.Printf("Volume %s is now unpinned\n", r.Id)
59+
} else {
60+
fmt.Printf("Volume %s is now pinned\n", r.Id)
61+
}
62+
}
63+
}
64+
65+
return nil
66+
}

cmd/podman/volumes/protect.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

cmd/podman/volumes/rm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func init() {
4646
flags := rmCommand.Flags()
4747
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all volumes")
4848
flags.BoolVarP(&rmOptions.Force, "force", "f", false, "Remove a volume by force, even if it is being used by a container")
49-
flags.BoolVar(&includeProtected, "include-protected", false, "Include protected volumes in removal operation")
49+
flags.BoolVar(&includeProtected, "include-pinned", false, "Include pinned volumes in removal operation")
5050
timeFlagName := "time"
5151
flags.IntVarP(&stopTimeout, timeFlagName, "t", int(containerConfig.Engine.StopTimeout), "Seconds to wait for running containers to stop before killing the container")
5252
_ = rmCommand.RegisterFlagCompletionFunc(timeFlagName, completion.AutocompleteNone)
@@ -66,7 +66,7 @@ func rm(cmd *cobra.Command, args []string) error {
6666
timeout := uint(stopTimeout)
6767
rmOptions.Timeout = &timeout
6868
}
69-
rmOptions.IncludeProtected = includeProtected
69+
rmOptions.IncludePinned = includeProtected
7070
responses, err := registry.ContainerEngine().VolumeRm(context.Background(), args, rmOptions)
7171
if err != nil {
7272
if rmOptions.Force && strings.Contains(err.Error(), define.ErrNoSuchVolume.Error()) {

libpod/define/volume_inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ type InspectVolumeData struct {
6363
StorageID string `json:"StorageID,omitempty"`
6464
// LockNumber is the number of the volume's Libpod lock.
6565
LockNumber uint32
66-
// Protected indicates that this volume should be excluded from
66+
// Pinned indicates that this volume should be excluded from
6767
// system prune operations by default.
68-
Protected bool `json:"Protected,omitempty"`
68+
Pinned bool `json:"Pinned,omitempty"`
6969
}
7070

7171
type VolumeReload struct {

libpod/options.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,15 +1753,15 @@ func withSetAnon() VolumeCreateOption {
17531753
}
17541754
}
17551755

1756-
// WithVolumeProtected sets the protected flag for the volume.
1757-
// Protected volumes are excluded from system prune operations by default.
1758-
func WithVolumeProtected() VolumeCreateOption {
1756+
// WithVolumePinned sets the pinned flag for the volume.
1757+
// Pinned volumes are excluded from system prune operations by default.
1758+
func WithVolumePinned() VolumeCreateOption {
17591759
return func(volume *Volume) error {
17601760
if volume.valid {
17611761
return define.ErrVolumeFinalized
17621762
}
17631763

1764-
volume.config.Protected = true
1764+
volume.config.Pinned = true
17651765

17661766
return nil
17671767
}

libpod/runtime_volume.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ func (r *Runtime) PruneVolumes(ctx context.Context, filterFuncs []VolumeFilter)
143143
}
144144

145145
// PruneVolumesWithOptions removes unused volumes from the system with options
146-
func (r *Runtime) PruneVolumesWithOptions(ctx context.Context, filterFuncs []VolumeFilter, includeProtected bool) ([]*reports.PruneReport, error) {
146+
func (r *Runtime) PruneVolumesWithOptions(ctx context.Context, filterFuncs []VolumeFilter, includePinned bool) ([]*reports.PruneReport, error) {
147147
preports := make([]*reports.PruneReport, 0)
148148
vols, err := r.Volumes(filterFuncs...)
149149
if err != nil {
150150
return nil, err
151151
}
152152

153153
for _, vol := range vols {
154-
// Skip protected volumes unless explicitly requested
155-
if vol.Protected() && !includeProtected {
154+
// Skip pinned volumes unless explicitly requested
155+
if vol.Pinned() && !includePinned {
156156
continue
157157
}
158158

@@ -179,9 +179,9 @@ func (r *Runtime) PruneVolumesWithOptions(ctx context.Context, filterFuncs []Vol
179179
return preports, nil
180180
}
181181

182-
// SetVolumeProtected sets the protected status of a volume by name.
183-
// Protected volumes are excluded from system prune operations by default.
184-
func (r *Runtime) SetVolumeProtected(volumeName string, protected bool) error {
182+
// SetVolumePinned sets the pinned status of a volume by name.
183+
// Pinned volumes are excluded from system prune operations by default.
184+
func (r *Runtime) SetVolumePinned(volumeName string, pinned bool) error {
185185
if !r.valid {
186186
return define.ErrRuntimeStopped
187187
}
@@ -191,5 +191,5 @@ func (r *Runtime) SetVolumeProtected(volumeName string, protected bool) error {
191191
return err
192192
}
193193

194-
return vol.SetProtected(protected)
194+
return vol.SetPinned(pinned)
195195
}

libpod/volume.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ type VolumeConfig struct {
7676
StorageImageID string `json:"storageImageID,omitempty"`
7777
// MountLabel is the SELinux label to assign to mount points
7878
MountLabel string `json:"mountlabel,omitempty"`
79-
// Protected indicates that this volume should be excluded from
79+
// Pinned indicates that this volume should be excluded from
8080
// system prune operations by default
81-
Protected bool `json:"protected,omitempty"`
81+
Pinned bool `json:"pinned,omitempty"`
8282
}
8383

8484
// VolumeState holds the volume's mutable state.
@@ -286,15 +286,15 @@ func (v *Volume) UsesVolumeDriver() bool {
286286
return v.config.Driver != define.VolumeDriverLocal && v.config.Driver != ""
287287
}
288288

289-
// Protected returns whether this volume is marked as protected.
290-
// Protected volumes are excluded from system prune operations by default.
291-
func (v *Volume) Protected() bool {
292-
return v.config.Protected
289+
// Pinned returns whether this volume is marked as pinned.
290+
// Pinned volumes are excluded from system prune operations by default.
291+
func (v *Volume) Pinned() bool {
292+
return v.config.Pinned
293293
}
294294

295-
// SetProtected sets the protected status of the volume.
296-
// Protected volumes are excluded from system prune operations by default.
297-
func (v *Volume) SetProtected(protected bool) error {
295+
// SetPinned sets the pinned status of the volume.
296+
// Pinned volumes are excluded from system prune operations by default.
297+
func (v *Volume) SetPinned(pinned bool) error {
298298
if !v.valid {
299299
return define.ErrVolumeRemoved
300300
}
@@ -306,7 +306,7 @@ func (v *Volume) SetProtected(protected bool) error {
306306
return err
307307
}
308308

309-
v.config.Protected = protected
309+
v.config.Pinned = pinned
310310

311311
return v.save()
312312
}

libpod/volume_inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (v *Volume) Inspect() (*define.InspectVolumeData, error) {
7575
data.Timeout = v.runtime.config.Engine.VolumePluginTimeout
7676
}
7777

78-
data.Protected = v.config.Protected
78+
data.Pinned = v.config.Pinned
7979

8080
return data, nil
8181
}

0 commit comments

Comments
 (0)