Skip to content

Commit

Permalink
miminar-dmage-bparees-1
Browse files Browse the repository at this point in the history
  • Loading branch information
gabemontero committed Nov 28, 2017
1 parent 6b78ba4 commit 4bd003b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
10 changes: 5 additions & 5 deletions pkg/image/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type pruneAlgorithm struct {
pruneOverSizeLimit bool
namespace string
allImages bool
leaveRegistryAlone bool
skipRegistry bool
}

// ImageDeleter knows how to remove images from OpenShift.
Expand Down Expand Up @@ -121,7 +121,7 @@ type PrunerOptions struct {
AllImages *bool
// LeaveRegistryAlone allows for pruning of the API Objects in etcd, but bypass any associated
// updates in the registry
LeaveRegistryAlone *bool
SkipRegistry *bool
// Namespace to be pruned, if specified it should never remove Images.
Namespace string
// Images is the entire list of images in OpenShift. An image must be in this
Expand Down Expand Up @@ -243,8 +243,8 @@ func NewPruner(options PrunerOptions) (Pruner, kerrors.Aggregate) {
if options.AllImages != nil {
algorithm.allImages = *options.AllImages
}
if options.LeaveRegistryAlone != nil {
algorithm.leaveRegistryAlone = *options.LeaveRegistryAlone
if options.SkipRegistry != nil {
algorithm.skipRegistry = *options.SkipRegistry
}
algorithm.namespace = options.Namespace

Expand Down Expand Up @@ -1013,7 +1013,7 @@ func (p *pruner) Prune(

var errs []error

if !p.algorithm.leaveRegistryAlone {
if !p.algorithm.skipRegistry {
errs = append(errs, pruneImageComponents(p.g, p.registryClient, p.registryURL, prunableComponents, layerLinkPruner)...)
errs = append(errs, pruneBlobs(p.g, p.registryClient, p.registryURL, prunableComponents, blobPruner)...)
errs = append(errs, pruneManifests(p.g, p.registryClient, p.registryURL, prunableImageNodes, manifestPruner)...)
Expand Down
48 changes: 24 additions & 24 deletions pkg/image/prune/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestImagePruning(t *testing.T) {
name string
pruneOverSizeLimit *bool
allImages *bool
leaveRegistryAlone *bool
skipRegistry *bool
keepTagRevisions *int
namespace string
images imageapi.ImageList
Expand Down Expand Up @@ -118,10 +118,10 @@ func TestImagePruning(t *testing.T) {
},

{
name: "pod phase succeeded - prune (leave registry alone)",
leaveRegistryAlone: newBool(true),
images: testutil.ImageList(testutil.Image("sha256:0000000000000000000000000000000000000000000000000000000000000000", registryHost+"/foo/bar@sha256:0000000000000000000000000000000000000000000000000000000000000000")),
pods: testutil.PodList(testutil.Pod("foo", "pod1", kapi.PodSucceeded, registryHost+"/foo/bar@sha256:0000000000000000000000000000000000000000000000000000000000000000")),
name: "pod phase succeeded - prune (leave registry alone)",
skipRegistry: newBool(true),
images: testutil.ImageList(testutil.Image("sha256:0000000000000000000000000000000000000000000000000000000000000000", registryHost+"/foo/bar@sha256:0000000000000000000000000000000000000000000000000000000000000000")),
pods: testutil.PodList(testutil.Pod("foo", "pod1", kapi.PodSucceeded, registryHost+"/foo/bar@sha256:0000000000000000000000000000000000000000000000000000000000000000")),
expectedImageDeletions: []string{"sha256:0000000000000000000000000000000000000000000000000000000000000000"},
expectedBlobDeletions: []string{},
},
Expand Down Expand Up @@ -905,8 +905,8 @@ func TestImagePruning(t *testing.T) {
options.KeepYoungerThan = &youngerThan
options.KeepTagRevisions = &tagRevisions
}
if test.leaveRegistryAlone != nil {
options.LeaveRegistryAlone = test.leaveRegistryAlone
if test.skipRegistry != nil {
options.SkipRegistry = test.skipRegistry
}
p, err := NewPruner(options)
if err != nil {
Expand Down Expand Up @@ -1035,7 +1035,7 @@ func TestRegistryPruning(t *testing.T) {
expectedLayerLinkDeletions sets.String
expectedBlobDeletions sets.String
expectedManifestDeletions sets.String
leaveRegistryAlone bool
skipRegistry bool
pingErr error
}{
{
Expand Down Expand Up @@ -1145,8 +1145,8 @@ func TestRegistryPruning(t *testing.T) {
},

{
name: "config used as a layer, but leave registry alone",
leaveRegistryAlone: true,
name: "config used as a layer, but leave registry alone",
skipRegistry: true,
images: testutil.ImageList(
testutil.ImageWithLayers("sha256:0000000000000000000000000000000000000000000000000000000000000001", "registry1.io/foo/bar@sha256:0000000000000000000000000000000000000000000000000000000000000001", &testutil.Config1, "layer1", "layer2", "layer3", testutil.Config1),
testutil.ImageWithLayers("sha256:0000000000000000000000000000000000000000000000000000000000000002", "registry1.io/foo/bar@sha256:0000000000000000000000000000000000000000000000000000000000000002", &testutil.Config2, "layer3", "layer4", "layer5", testutil.Config1),
Expand Down Expand Up @@ -1177,20 +1177,20 @@ func TestRegistryPruning(t *testing.T) {
keepYoungerThan := 60 * time.Minute
keepTagRevisions := 1
options := PrunerOptions{
KeepYoungerThan: &keepYoungerThan,
KeepTagRevisions: &keepTagRevisions,
LeaveRegistryAlone: &test.leaveRegistryAlone,
Images: &test.images,
Streams: &test.streams,
Pods: &kapi.PodList{},
RCs: &kapi.ReplicationControllerList{},
BCs: &buildapi.BuildConfigList{},
Builds: &buildapi.BuildList{},
DSs: &kapisext.DaemonSetList{},
Deployments: &kapisext.DeploymentList{},
DCs: &deployapi.DeploymentConfigList{},
RSs: &kapisext.ReplicaSetList{},
RegistryURL: &url.URL{Scheme: "https", Host: "registry1.io"},
KeepYoungerThan: &keepYoungerThan,
KeepTagRevisions: &keepTagRevisions,
SkipRegistry: &test.skipRegistry,
Images: &test.images,
Streams: &test.streams,
Pods: &kapi.PodList{},
RCs: &kapi.ReplicationControllerList{},
BCs: &buildapi.BuildConfigList{},
Builds: &buildapi.BuildList{},
DSs: &kapisext.DaemonSetList{},
Deployments: &kapisext.DeploymentList{},
DCs: &deployapi.DeploymentConfigList{},
RSs: &kapisext.ReplicaSetList{},
RegistryURL: &url.URL{Scheme: "https", Host: "registry1.io"},
}
p, err := NewPruner(options)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions pkg/oc/admin/prune/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var (
defaultKeepYoungerThan = 60 * time.Minute
defaultKeepTagRevisions = 3
defaultPruneImageOverSizeLimit = false
defaultLeaveRegistryAlone = false
defaultSkipRegistry = false
)

// PruneImagesOptions holds all the required options for pruning images.
Expand All @@ -118,7 +118,7 @@ type PruneImagesOptions struct {
RegistryUrlOverride string
Namespace string
ForceInsecure bool
LeaveRegistryAlone *bool
SkipRegistry *bool

ClientConfig *restclient.Config
AppsClient appsclient.AppsInterface
Expand All @@ -139,7 +139,7 @@ func NewCmdPruneImages(f *clientcmd.Factory, parentName, name string, out io.Wri
KeepYoungerThan: &defaultKeepYoungerThan,
KeepTagRevisions: &defaultKeepTagRevisions,
PruneOverSizeLimit: &defaultPruneImageOverSizeLimit,
LeaveRegistryAlone: &defaultLeaveRegistryAlone,
SkipRegistry: &defaultSkipRegistry,
AllImages: &allImages,
}

Expand All @@ -165,7 +165,7 @@ func NewCmdPruneImages(f *clientcmd.Factory, parentName, name string, out io.Wri
cmd.Flags().StringVar(&opts.CABundle, "certificate-authority", opts.CABundle, "The path to a certificate authority bundle to use when communicating with the managed Docker registries. Defaults to the certificate authority data from the current user's config file. It cannot be used together with --force-insecure.")
cmd.Flags().StringVar(&opts.RegistryUrlOverride, "registry-url", opts.RegistryUrlOverride, "The address to use when contacting the registry, instead of using the default value. This is useful if you can't resolve or reach the registry (e.g.; the default is a cluster-internal URL) but you do have an alternative route that works. Particular transport protocol can be enforced using '<scheme>://' prefix.")
cmd.Flags().BoolVar(&opts.ForceInsecure, "force-insecure", opts.ForceInsecure, "If true, allow an insecure connection to the docker registry that is hosted via HTTP or has an invalid HTTPS certificate. Whenever possible, use --certificate-authority instead of this dangerous option.")
cmd.Flags().BoolVar(opts.LeaveRegistryAlone, "leave-registry-alone", *opts.LeaveRegistryAlone, "If true, the prune operation will clean up image API objects in etcd, but none of the associated content in the registry is removed. This option make most sense there is either a large amount of data in etcd and/or a large number of images or blobs. You would then use this option to clean up etcd, and use the 'hard prune' administrative task (https://docs.openshift.org/latest/admin_guide/pruning_resources.html#hard-pruning-registry) to clean up the registry.")
cmd.Flags().BoolVar(opts.SkipRegistry, "skip-registry", *opts.SkipRegistry, "If true, the prune operation will clean up image API objects, but the none of the associated content in the registry is removed.")

return cmd
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func (o PruneImagesOptions) Run() error {
DryRun: o.Confirm == false,
RegistryClient: registryClient,
RegistryURL: registryURL,
LeaveRegistryAlone: o.LeaveRegistryAlone,
SkipRegistry: o.SkipRegistry,
}
if o.Namespace != metav1.NamespaceAll {
options.Namespace = o.Namespace
Expand Down Expand Up @@ -417,8 +417,8 @@ func (o PruneImagesOptions) Run() error {
fmt.Fprintln(o.ErrOut, "Dry run enabled - no modifications will be made. Add --confirm to remove images")
}

if o.LeaveRegistryAlone != nil && *o.LeaveRegistryAlone {
fmt.Fprintln(o.Out, "Soft prune enabled - only API objects will be removed. No modifications to the image registry will be made.")
if o.SkipRegistry != nil && *o.SkipRegistry {
fmt.Fprintln(o.Out, "Only API objects will be removed. No modifications to the image registry will be made.")
}

return pruner.Prune(imageDeleter, imageStreamDeleter, layerLinkDeleter, blobDeleter, manifestDeleter)
Expand Down
16 changes: 8 additions & 8 deletions test/extended/images/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = g.Describe("[Feature:ImagePrune][registry][Serial] Image prune", func()
g.It("should prune old image with config", func() { testPruneImages(oc, 2) })
})

g.Describe("with --leave-registry-alone", func() {
g.Describe("with --skip-registry", func() {
g.JustBeforeEach(func() {
if !*originalAcceptSchema2 {
g.By("ensure the registry accepts schema 2")
Expand All @@ -102,7 +102,7 @@ var _ = g.Describe("[Feature:ImagePrune][registry][Serial] Image prune", func()
}
})

g.It("should prune old image but leave registry alone", func() { testSoftPruneImages(oc) })
g.It("should prune old image but skip registry", func() { testSoftPruneImages(oc) })
})

g.Describe("with default --all flag", func() {
Expand Down Expand Up @@ -278,18 +278,18 @@ func testSoftPruneImages(oc *exutil.CLI) {
pruneSize, err := GetRegistryStorageSize(oc)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("prune the first image uploaded (confirm, leave-registry-alone)")
output, err := oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm", "--leave-registry-alone").Output()
g.By("prune the first image uploaded (confirm, skip-registry)")
output, err := oc.WithoutNamespace().Run("adm").Args("prune", "images", "--keep-tag-revisions=1", "--keep-younger-than=0", "--confirm", "--skip-registry").Output()

g.By("verify images, layers and configs about to be pruned")
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(output).NotTo(o.ContainSubstring(imgPruneName))
o.Expect(output).To(o.ContainSubstring("Soft prune enabled"))
o.Expect(output).To(o.ContainSubstring("Only API objects will be removed"))

leaveRegistryAloneSize, err := GetRegistryStorageSize(oc)
skipRegistrySize, err := GetRegistryStorageSize(oc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("confirming storage size: sizeAfterPrune=%d == beforePruneSize=%d", leaveRegistryAloneSize, pruneSize))
o.Expect(leaveRegistryAloneSize == pruneSize).To(o.BeTrue())
g.By(fmt.Sprintf("confirming storage size: sizeAfterPrune=%d == beforePruneSize=%d", skipRegistrySize, pruneSize))
o.Expect(skipRegistrySize == pruneSize).To(o.BeTrue())
}

func testPruneAllImages(oc *exutil.CLI, setAllImagesToFalse bool, schemaVersion int) {
Expand Down

0 comments on commit 4bd003b

Please sign in to comment.