Skip to content

Commit a70f279

Browse files
authored
Merge pull request #17344 from openshift/revert-16580-image-exclude-from-prune
Revert "Imagestream tag exclude from pruning"
2 parents 8c5b43d + 38074a3 commit a70f279

File tree

9 files changed

+21
-163
lines changed

9 files changed

+21
-163
lines changed

contrib/completions/bash/oadm

-4
Original file line numberDiff line numberDiff line change
@@ -4746,10 +4746,6 @@ _oadm_prune_images()
47464746
local_nonpersistent_flags+=("--certificate-authority=")
47474747
flags+=("--confirm")
47484748
local_nonpersistent_flags+=("--confirm")
4749-
flags+=("--exclude-imagestreamtag=")
4750-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
4751-
flags+=("--exclude-imagestreamtag-file=")
4752-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
47534749
flags+=("--force-insecure")
47544750
local_nonpersistent_flags+=("--force-insecure")
47554751
flags+=("--keep-tag-revisions=")

contrib/completions/bash/oc

-4
Original file line numberDiff line numberDiff line change
@@ -4911,10 +4911,6 @@ _oc_adm_prune_images()
49114911
local_nonpersistent_flags+=("--certificate-authority=")
49124912
flags+=("--confirm")
49134913
local_nonpersistent_flags+=("--confirm")
4914-
flags+=("--exclude-imagestreamtag=")
4915-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
4916-
flags+=("--exclude-imagestreamtag-file=")
4917-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
49184914
flags+=("--force-insecure")
49194915
local_nonpersistent_flags+=("--force-insecure")
49204916
flags+=("--keep-tag-revisions=")

contrib/completions/bash/openshift

-8
Original file line numberDiff line numberDiff line change
@@ -4746,10 +4746,6 @@ _openshift_admin_prune_images()
47464746
local_nonpersistent_flags+=("--certificate-authority=")
47474747
flags+=("--confirm")
47484748
local_nonpersistent_flags+=("--confirm")
4749-
flags+=("--exclude-imagestreamtag=")
4750-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
4751-
flags+=("--exclude-imagestreamtag-file=")
4752-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
47534749
flags+=("--force-insecure")
47544750
local_nonpersistent_flags+=("--force-insecure")
47554751
flags+=("--keep-tag-revisions=")
@@ -10080,10 +10076,6 @@ _openshift_cli_adm_prune_images()
1008010076
local_nonpersistent_flags+=("--certificate-authority=")
1008110077
flags+=("--confirm")
1008210078
local_nonpersistent_flags+=("--confirm")
10083-
flags+=("--exclude-imagestreamtag=")
10084-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
10085-
flags+=("--exclude-imagestreamtag-file=")
10086-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
1008710079
flags+=("--force-insecure")
1008810080
local_nonpersistent_flags+=("--force-insecure")
1008910081
flags+=("--keep-tag-revisions=")

contrib/completions/zsh/oadm

-4
Original file line numberDiff line numberDiff line change
@@ -4895,10 +4895,6 @@ _oadm_prune_images()
48954895
local_nonpersistent_flags+=("--certificate-authority=")
48964896
flags+=("--confirm")
48974897
local_nonpersistent_flags+=("--confirm")
4898-
flags+=("--exclude-imagestreamtag=")
4899-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
4900-
flags+=("--exclude-imagestreamtag-file=")
4901-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
49024898
flags+=("--force-insecure")
49034899
local_nonpersistent_flags+=("--force-insecure")
49044900
flags+=("--keep-tag-revisions=")

contrib/completions/zsh/oc

-4
Original file line numberDiff line numberDiff line change
@@ -5060,10 +5060,6 @@ _oc_adm_prune_images()
50605060
local_nonpersistent_flags+=("--certificate-authority=")
50615061
flags+=("--confirm")
50625062
local_nonpersistent_flags+=("--confirm")
5063-
flags+=("--exclude-imagestreamtag=")
5064-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
5065-
flags+=("--exclude-imagestreamtag-file=")
5066-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
50675063
flags+=("--force-insecure")
50685064
local_nonpersistent_flags+=("--force-insecure")
50695065
flags+=("--keep-tag-revisions=")

contrib/completions/zsh/openshift

-8
Original file line numberDiff line numberDiff line change
@@ -4895,10 +4895,6 @@ _openshift_admin_prune_images()
48954895
local_nonpersistent_flags+=("--certificate-authority=")
48964896
flags+=("--confirm")
48974897
local_nonpersistent_flags+=("--confirm")
4898-
flags+=("--exclude-imagestreamtag=")
4899-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
4900-
flags+=("--exclude-imagestreamtag-file=")
4901-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
49024898
flags+=("--force-insecure")
49034899
local_nonpersistent_flags+=("--force-insecure")
49044900
flags+=("--keep-tag-revisions=")
@@ -10229,10 +10225,6 @@ _openshift_cli_adm_prune_images()
1022910225
local_nonpersistent_flags+=("--certificate-authority=")
1023010226
flags+=("--confirm")
1023110227
local_nonpersistent_flags+=("--confirm")
10232-
flags+=("--exclude-imagestreamtag=")
10233-
local_nonpersistent_flags+=("--exclude-imagestreamtag=")
10234-
flags+=("--exclude-imagestreamtag-file=")
10235-
local_nonpersistent_flags+=("--exclude-imagestreamtag-file=")
1023610228
flags+=("--force-insecure")
1023710229
local_nonpersistent_flags+=("--force-insecure")
1023810230
flags+=("--keep-tag-revisions=")

pkg/image/prune/prune.go

+6-33
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77
"net/url"
88
"reflect"
9-
"regexp"
109
"time"
1110

1211
"github.com/docker/distribution/manifest/schema2"
@@ -60,12 +59,11 @@ const (
6059
// pruneAlgorithm contains the various settings to use when evaluating images
6160
// and layers for pruning.
6261
type pruneAlgorithm struct {
63-
keepYoungerThan time.Time
64-
keepTagRevisions int
65-
pruneOverSizeLimit bool
66-
namespace string
67-
allImages bool
68-
excludeImageStreamTagPatterns []*regexp.Regexp
62+
keepYoungerThan time.Time
63+
keepTagRevisions int
64+
pruneOverSizeLimit bool
65+
namespace string
66+
allImages bool
6967
}
7068

7169
// ImageDeleter knows how to remove images from OpenShift.
@@ -155,8 +153,6 @@ type PrunerOptions struct {
155153
RegistryClient *http.Client
156154
// RegistryURL is the URL of the integrated Docker registry.
157155
RegistryURL *url.URL
158-
// ExcludeImageStreamTagPatterns is the list of regular expressions to exclude an imagesteam tag from pruning.
159-
ExcludeImageStreamTagPatterns []*regexp.Regexp
160156
}
161157

162158
// Pruner knows how to prune istags, images, layers and image configs.
@@ -244,7 +240,6 @@ func NewPruner(options PrunerOptions) (Pruner, kerrors.Aggregate) {
244240
algorithm.allImages = *options.AllImages
245241
}
246242
algorithm.namespace = options.Namespace
247-
algorithm.excludeImageStreamTagPatterns = options.ExcludeImageStreamTagPatterns
248243

249244
p := &pruner{
250245
algorithm: algorithm,
@@ -356,30 +351,8 @@ func (p *pruner) addImageStreamsToGraph(streams *imageapi.ImageStreamList, limit
356351
continue
357352
}
358353

359-
istExcluded := false
360-
dockerImageReference := ""
361-
362-
if p.algorithm.excludeImageStreamTagPatterns != nil {
363-
dockerImageReference = imageapi.DockerImageReference{
364-
Namespace: stream.Namespace,
365-
Name: stream.Name,
366-
Tag: tag,
367-
}.Exact()
368-
369-
for _, pattern := range p.algorithm.excludeImageStreamTagPatterns {
370-
if pattern.MatchString(dockerImageReference) {
371-
istExcluded = true
372-
break
373-
}
374-
}
375-
}
376-
377354
kind := oldImageRevisionReferenceKind
378-
379-
if istExcluded {
380-
glog.V(4).Infof("ImageStreamTag %q is excluded by the regular expression", dockerImageReference)
381-
kind = ReferencedImageEdgeKind
382-
} else if p.algorithm.pruneOverSizeLimit {
355+
if p.algorithm.pruneOverSizeLimit {
383356
if exceedsLimits(stream, imageNode.Image, limits) {
384357
kind = WeakReferencedImageEdgeKind
385358
} else {

pkg/oc/admin/prune/images.go

+9-69
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package prune
22

33
import (
4-
"bufio"
54
"crypto/x509"
65
"encoding/json"
76
"errors"
@@ -87,10 +86,6 @@ var (
8786
# To actually perform the prune operation, the confirm flag must be appended
8887
%[1]s %[2]s --keep-tag-revisions=3 --keep-younger-than=60m --confirm
8988
90-
# To exclude an imagestream from pruning you can specify a regular expression
91-
# which will be applied to the '<namespace>/<name>:<tag>' string.
92-
%[1]s %[2]s --exclude-imagestreamtag='^myproject/hello-openshift:.*$'
93-
9489
# See, what the prune command would delete if we're interested in removing images
9590
# exceeding currently set limit ranges ('openshift.io/Image')
9691
%[1]s %[2]s --prune-over-size-limit
@@ -113,17 +108,15 @@ var (
113108

114109
// PruneImagesOptions holds all the required options for pruning images.
115110
type PruneImagesOptions struct {
116-
Confirm bool
117-
KeepYoungerThan *time.Duration
118-
KeepTagRevisions *int
119-
PruneOverSizeLimit *bool
120-
AllImages *bool
121-
CABundle string
122-
RegistryUrlOverride string
123-
Namespace string
124-
ForceInsecure bool
125-
ExcludeImageStreamTag string
126-
ExcludeImageStreamTagFile string
111+
Confirm bool
112+
KeepYoungerThan *time.Duration
113+
KeepTagRevisions *int
114+
PruneOverSizeLimit *bool
115+
AllImages *bool
116+
CABundle string
117+
RegistryUrlOverride string
118+
Namespace string
119+
ForceInsecure bool
127120

128121
ClientConfig *restclient.Config
129122
AppsClient appsclient.AppsInterface
@@ -165,8 +158,6 @@ func NewCmdPruneImages(f *clientcmd.Factory, parentName, name string, out io.Wri
165158
cmd.Flags().BoolVar(opts.AllImages, "all", *opts.AllImages, "Include images that were imported from external registries as candidates for pruning. If pruned, all the mirrored objects associated with them will also be removed from the integrated registry.")
166159
cmd.Flags().DurationVar(opts.KeepYoungerThan, "keep-younger-than", *opts.KeepYoungerThan, "Specify the minimum age of an image and its referrers for it to be considered a candidate for pruning.")
167160
cmd.Flags().IntVar(opts.KeepTagRevisions, "keep-tag-revisions", *opts.KeepTagRevisions, "Specify the number of image revisions for a tag in an image stream that will be preserved.")
168-
cmd.Flags().StringVar(&opts.ExcludeImageStreamTag, "exclude-imagestreamtag", "", "The regular expression matching ImageStreamTags excluded from pruning.")
169-
cmd.Flags().StringVar(&opts.ExcludeImageStreamTagFile, "exclude-imagestreamtag-file", "", "The filename that contains the regular expressions matching ImageStreamTags excluded from pruning.")
170161
cmd.Flags().BoolVar(opts.PruneOverSizeLimit, "prune-over-size-limit", *opts.PruneOverSizeLimit, "Specify if images which are exceeding LimitRanges (see 'openshift.io/Image'), specified in the same namespace, should be considered for pruning. This flag cannot be combined with --keep-younger-than nor --keep-tag-revisions.")
171162
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.")
172163
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.")
@@ -396,19 +387,6 @@ func (o PruneImagesOptions) Run() error {
396387
if o.Namespace != metav1.NamespaceAll {
397388
options.Namespace = o.Namespace
398389
}
399-
if len(o.ExcludeImageStreamTagFile) > 0 {
400-
options.ExcludeImageStreamTagPatterns, err = parsePatternsFile(o.ExcludeImageStreamTagFile)
401-
if err != nil {
402-
return err
403-
}
404-
}
405-
if len(o.ExcludeImageStreamTag) > 0 {
406-
pattern, err := regexp.Compile(o.ExcludeImageStreamTag)
407-
if err != nil {
408-
return fmt.Errorf("bad regular expression %q: %v", o.ExcludeImageStreamTag, err)
409-
}
410-
options.ExcludeImageStreamTagPatterns = append(options.ExcludeImageStreamTagPatterns, pattern)
411-
}
412390
pruner, errs := prune.NewPruner(options)
413391
if errs != nil {
414392
o.printGraphBuildErrors(errs)
@@ -792,41 +770,3 @@ func getClientAndMasterVersions(client discovery.DiscoveryInterface, timeout tim
792770

793771
return
794772
}
795-
796-
func parsePatternsFile(filename string) ([]*regexp.Regexp, error) {
797-
file, err := os.Open(filename)
798-
if err != nil {
799-
return nil, err
800-
}
801-
defer file.Close()
802-
803-
var (
804-
patterns []*regexp.Regexp
805-
line string
806-
readerErr error
807-
)
808-
809-
reader := bufio.NewReader(file)
810-
for readerErr == nil {
811-
line, readerErr = reader.ReadString('\n')
812-
813-
if readerErr != nil && readerErr != io.EOF {
814-
return nil, readerErr
815-
}
816-
817-
line = strings.TrimSuffix(line, "\n")
818-
819-
if len(line) == 0 {
820-
continue
821-
}
822-
823-
pattern, err := regexp.Compile(line)
824-
if err != nil {
825-
return nil, fmt.Errorf("%s: bad regular expression %q: %v", filename, line, err)
826-
}
827-
828-
patterns = append(patterns, pattern)
829-
}
830-
831-
return patterns, nil
832-
}

test/extended/images/prune.go

+6-29
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ var _ = g.Describe("[Feature:ImagePrune][registry][Serial] Image prune", func()
103103
}
104104
})
105105

106-
g.It("should prune both internally managed and external images", func() { testPruneAllImages(oc, true, 2, false) })
106+
g.It("should prune both internally managed and external images", func() { testPruneAllImages(oc, true, 2) })
107107
})
108108

109109
g.Describe("with --all=false flag", func() {
@@ -122,26 +122,7 @@ var _ = g.Describe("[Feature:ImagePrune][registry][Serial] Image prune", func()
122122
}
123123
})
124124

125-
g.It("should prune only internally managed images", func() { testPruneAllImages(oc, false, 2, false) })
126-
})
127-
128-
g.Describe("with --all flag, but exclude external image", func() {
129-
g.JustBeforeEach(func() {
130-
if !*originalAcceptSchema2 {
131-
g.By("ensure the registry accepts schema 2")
132-
err := registryutil.EnsureRegistryAcceptsSchema2(oc, true)
133-
o.Expect(err).NotTo(o.HaveOccurred())
134-
}
135-
})
136-
137-
g.AfterEach(func() {
138-
if !*originalAcceptSchema2 {
139-
err := registryutil.EnsureRegistryAcceptsSchema2(oc, false)
140-
o.Expect(err).NotTo(o.HaveOccurred())
141-
}
142-
})
143-
144-
g.It("should prune only internally managed images and ignore external images", func() { testPruneAllImages(oc, false, 2, true) })
125+
g.It("should prune only internally managed images", func() { testPruneAllImages(oc, false, 2) })
145126
})
146127
})
147128

@@ -259,7 +240,7 @@ func testPruneImages(oc *exutil.CLI, schemaVersion int) {
259240
o.Expect(imgPrune.DockerImageMetadata.Size <= keepSize-confirmSize).To(o.BeTrue())
260241
}
261242

262-
func testPruneAllImages(oc *exutil.CLI, setAllImagesToFalse bool, schemaVersion int, excludeExternalImage bool) {
243+
func testPruneAllImages(oc *exutil.CLI, setAllImagesToFalse bool, schemaVersion int) {
263244
isName := fmt.Sprintf("prune-schema%d-all-images-%t", schemaVersion, setAllImagesToFalse)
264245
repository := oc.Namespace() + "/" + isName
265246

@@ -301,14 +282,14 @@ func testPruneAllImages(oc *exutil.CLI, setAllImagesToFalse bool, schemaVersion
301282
o.Expect(inRepository).To(o.Equal(dryRun))
302283
}
303284

304-
if setAllImagesToFalse || excludeExternalImage {
285+
if setAllImagesToFalse {
305286
o.Expect(output).NotTo(o.ContainSubstring(externalImage.Name))
306287
} else {
307288
o.Expect(output).To(o.ContainSubstring(externalImage.Name))
308289
}
309290

310291
for _, layer := range externalImage.DockerImageLayers {
311-
if setAllImagesToFalse || excludeExternalImage {
292+
if setAllImagesToFalse {
312293
o.Expect(output).NotTo(o.ContainSubstring(layer.Name))
313294
} else {
314295
o.Expect(output).To(o.ContainSubstring(layer.Name))
@@ -319,7 +300,7 @@ func testPruneAllImages(oc *exutil.CLI, setAllImagesToFalse bool, schemaVersion
319300
}
320301
globally, inRepository, err := IsBlobStoredInRegistry(oc, digest.Digest(layer.Name), repository)
321302
o.Expect(err).NotTo(o.HaveOccurred())
322-
o.Expect(globally).To(o.Equal(dryRun || setAllImagesToFalse || excludeExternalImage))
303+
o.Expect(globally).To(o.Equal(dryRun || setAllImagesToFalse))
323304
// mirrored blobs are not linked into any repository/_layers directory
324305
o.Expect(inRepository).To(o.BeFalse())
325306
}
@@ -330,10 +311,6 @@ func testPruneAllImages(oc *exutil.CLI, setAllImagesToFalse bool, schemaVersion
330311
args = append(args, "--all=false")
331312
}
332313

333-
if excludeExternalImage {
334-
args = append(args, "--exclude-imagestreamtag=/origin-release:latest")
335-
}
336-
337314
g.By(fmt.Sprintf("dry-running oc adm %s", strings.Join(args, " ")))
338315
output, err := oc.WithoutNamespace().Run("adm").Args(args...).Output()
339316

0 commit comments

Comments
 (0)