Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: container retention #42

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/ghpackage/retention.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (a *RetentionManager) findPackages(ctx context.Context, packageName string,
switch a.PackageType {
case "container":
if !a.matchContainer(version) {
a.Logger.V(1).Info("skip package version as version does not match the required match regex", "package", packageName, "version", *version.Name, "id", *version.ID)
continue
}

Expand All @@ -93,17 +94,20 @@ func (a *RetentionManager) findPackages(ctx context.Context, packageName string,
}
default:
if !a.VersionMatch.MatchString(*version.Name) {
a.Logger.V(1).Info("skip package version as version does not match the required match regex", "package", packageName, "version", *version.Name, "id", *version.ID)
continue
}
}
}

if version.UpdatedAt == nil {
a.Logger.V(1).Info("skip package version as no update timestamp exists", "package", packageName, "version", *version.Name, "id", *version.ID)
continue
}

if a.Age != 0 {
if version.UpdatedAt.Time.Add(a.Age).After(time.Now()) {
a.Logger.V(1).Info("skip package version as age is too new", "package", packageName, "version", *version.Name, "id", *version.ID, "age", version.UpdatedAt)
continue
}
}
Expand Down
26 changes: 16 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,24 @@ func main() {
logger: log,
}

containerTransport := &loggingRoundTripper{
next: http.DefaultTransport,
logger: log,
}

ghClient := github.NewClient(tc)

a := ghpackage.RetentionManager{
PackageType: viper.GetString("package-type"),
Token: token,
DryRun: viper.GetBool("dry-run"),
GithubClient: ghClient,
PackageNames: packages,
Age: viper.GetDuration("age"),
OrganizationName: viper.GetString("org-name"),
VersionMatch: versionMatchRegexp,
Logger: log,
ContainerRegistryTransport: containerTransport,
PackageType: strings.ToLower(viper.GetString("package-type")),
Token: token,
DryRun: viper.GetBool("dry-run"),
GithubClient: ghClient,
PackageNames: packages,
Age: viper.GetDuration("age"),
OrganizationName: strings.ToLower(viper.GetString("org-name")),
VersionMatch: versionMatchRegexp,
Logger: log,
}

_, err = a.Run(ctx)
Expand All @@ -126,6 +132,6 @@ type loggingRoundTripper struct {
func (p loggingRoundTripper) RoundTrip(req *http.Request) (res *http.Response, e error) {
p.logger.V(1).Info("http request sent", "method", req.Method, "uri", req.URL.String())
res, err := p.next.RoundTrip(req)
p.logger.V(1).Info("http response received", "method", req.Method, "uri", req.URL.String(), "status", res.StatusCode)
p.logger.V(1).Info("http response received", "method", req.Method, "uri", req.URL.String(), "status", res.StatusCode, "err", err)
return res, err
}
Loading