gcrcleaner

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package gcrcleaner cleans up stale images from a container registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTimerCache added in v0.3.0

func NewTimerCache(lifetime time.Duration) *timerCache

NewTimerCache creates a new timer-based cache.

Types

type Cache

type Cache interface {
	// Insert inserts the item into the cache. If the item already exists, this
	// method returns true.
	Insert(string) bool

	// Stop stops the cache. When Stop returns, the cache must not perform any
	// additionally processing.
	Stop()
}

Cache is an interface used by the PubSub() function to prevent duplicate messages from being processed.

type Cleaner

type Cleaner struct {
	// contains filtered or unexported fields
}

Cleaner is a gcr cleaner.

func NewCleaner

func NewCleaner(auther gcrauthn.Authenticator, logger *Logger, c int) (*Cleaner, error)

NewCleaner creates a new GCR cleaner with the given token provider and concurrency.

func (*Cleaner) Clean

func (c *Cleaner) Clean(ctx context.Context, repo string, since time.Time, keep int, tagFilter TagFilter, dryRun bool) ([]string, error)

Clean deletes old images from GCR that are (un)tagged and older than "since" and higher than the "keep" amount.

func (*Cleaner) ListChildRepositories added in v0.5.0

func (c *Cleaner) ListChildRepositories(ctx context.Context, roots []string) ([]string, error)

ListChildRepositories lists all child repositores for the given roots. Roots can be entire registries (e.g. us-docker.pkg.dev) or a subpath within a registry (e.g. gcr.io/my-project/my-container).

type LogEntry added in v0.6.0

type LogEntry struct {
	Time     *time.Time
	Severity Severity
	Message  string
	Data     map[string]interface{}
}

func (*LogEntry) MarshalJSON added in v0.6.0

func (l *LogEntry) MarshalJSON() ([]byte, error)

type Logger added in v0.6.0

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger added in v0.6.0

func NewLogger(level string, outw, errw io.Writer) *Logger

func (*Logger) Debug added in v0.6.0

func (l *Logger) Debug(msg string, fields ...interface{})

func (*Logger) Error added in v0.6.0

func (l *Logger) Error(msg string, fields ...interface{})

func (*Logger) Fatal added in v0.6.0

func (l *Logger) Fatal(msg string, fields ...interface{})

func (*Logger) Info added in v0.6.0

func (l *Logger) Info(msg string, fields ...interface{})

func (*Logger) Warn added in v0.6.0

func (l *Logger) Warn(msg string, fields ...interface{})

type Payload

type Payload struct {
	// Repo is the name of the repo to clean.
	//
	// Deprecated: Use Repos instead.
	Repo string `json:"repo"`

	// Repos is the list of repositories to clean.
	Repos sortedStringSlice `json:"repos"`

	// Grace is a time.Duration value indicating how much grade period should be
	// given to new, untagged layers. The default is no grace.
	Grace duration `json:"grace"`

	// Keep is the minimum number of images to keep.
	Keep int `json:"keep"`

	// TagFilterAny is the tags pattern to be allowed removing. If given, any
	// image with at least one tag that matches this given regular expression will
	// be deleted. The image will be deleted even if it has other tags that do not
	// match the given regular expression.
	TagFilterAny string `json:"tag_filter_any"`

	// TagFilterAll is the tags pattern to be allowed removing. If given, any
	// image where all tags match this given regular expression will be deleted.
	// The image will not be delete if it has other tags that do not match the
	// given regular expression.
	TagFilterAll string `json:"tag_filter_all"`

	// DryRun instructs the server to not perform actual cleaning. The response
	// will include repositories that would have been deleted.
	DryRun bool `json:"dry_run"`

	// Recursive enables cleaning all child repositories.
	Recursive bool `json:"recursive"`

	// TagFilterFirst is the tags pattern to be allowed removing. If specified, any
	// images where the first tag matches the given regular expression will be
	// deleted.
	//
	// Deprecated: Use tag_filter_all or tag_filter_any instead.
	TagFilterFirst string `json:"tag_filter"`

	// AllowTagged is a Boolean value determine if tagged images are allowed to be
	// deleted.
	//
	// Deprecated: Use tag_filter_all or tag_filter_any instead. Setting either of
	// these values enables deleting tagged images.
	AllowTagged bool `json:"allow_tagged"`
}

Payload is the expected incoming payload format.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a cleaning server.

func NewServer

func NewServer(cleaner *Cleaner) (*Server, error)

NewServer creates a new server for handler functions.

func (*Server) HTTPHandler

func (s *Server) HTTPHandler() http.HandlerFunc

HTTPHandler is an http handler that invokes the cleaner with the given parameters.

func (*Server) PubSubHandler

func (s *Server) PubSubHandler(cache Cache) http.HandlerFunc

PubSubHandler is an http handler that invokes the cleaner from a pubsub request. Unlike an HTTP request, the pubsub endpoint always returns a success unless the pubsub message is malformed.

type Severity added in v0.6.0

type Severity uint8
const (
	SeverityDebug Severity = iota
	SeverityInfo
	SeverityWarn
	SeverityError
	SeverityFatal
)

type TagFilter added in v0.7.0

type TagFilter interface {
	Name() string
	Matches(tags []string) bool
}

TagFilter is an interface which defines whether a given set of tags matches the filter.

func BuildTagFilter added in v0.7.0

func BuildTagFilter(first, any, all string) (TagFilter, error)

BuildTagFilter builds and compiles a new tag filter for the given inputs. All inputs are strings to be compiled to regular expressions and are mutually exclusive.

type TagFilterAll added in v0.7.0

type TagFilterAll struct {
	// contains filtered or unexported fields
}

TagFilterAll filters based on the entire list. If all tags in the last match, it returns true. If one more more tags do not match, it returns false.

func (*TagFilterAll) Matches added in v0.7.0

func (f *TagFilterAll) Matches(tags []string) bool

func (*TagFilterAll) Name added in v0.7.2

func (f *TagFilterAll) Name() string

type TagFilterAny added in v0.7.0

type TagFilterAny struct {
	// contains filtered or unexported fields
}

TagFilterAny filters based on the entire list. If any tag in the list matches, it returns true. If no tags match, it returns false.

func (*TagFilterAny) Matches added in v0.7.0

func (f *TagFilterAny) Matches(tags []string) bool

func (*TagFilterAny) Name added in v0.7.2

func (f *TagFilterAny) Name() string

type TagFilterFirst added in v0.7.0

type TagFilterFirst struct {
	// contains filtered or unexported fields
}

TagFilterFirst filters based on the first item in the list. If the list is empty or if the first item does not match the regex, it returns false.

func (*TagFilterFirst) Matches added in v0.7.0

func (f *TagFilterFirst) Matches(tags []string) bool

func (*TagFilterFirst) Name added in v0.7.2

func (f *TagFilterFirst) Name() string

type TagFilterNull added in v0.7.0

type TagFilterNull struct{}

TagFilterNull always returns false.

func (*TagFilterNull) Matches added in v0.7.0

func (f *TagFilterNull) Matches(tags []string) bool

func (*TagFilterNull) Name added in v0.7.2

func (f *TagFilterNull) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL