-
Notifications
You must be signed in to change notification settings - Fork 378
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
feat: add new GC rules for release with version #6469
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6469 +/- ##
==========================================
+ Coverage 15.12% 15.13% +0.01%
==========================================
Files 3675 3675
Lines 377005 377085 +80
==========================================
+ Hits 57018 57072 +54
- Misses 314540 314551 +11
- Partials 5447 5462 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ListReleaseByAppAndProject list release by application_id and project_id, version is not empty | ||
func (client *ReleaseConfigDB) ListReleaseByAppAndProject(projectID int64, appID int64) ([]Release, error) { | ||
var releases []Release | ||
if err := client.Select([]string{"release_id", "cluster_name", "version"}).Where("application_id = ? AND project_id =? AND version != ''", appID, projectID).Order("updated_at ASC").Find(&releases).Error; err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary code Select([]string{"release_id", "cluster_name", "version"})
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format code in fragment link, e.g. Where
, Order
.
// ListExpireReleaseWithVersion list release that has not been referenced before a given point in time and version is not empty | ||
func (client *ReleaseConfigDB) ListExpireReleaseWithVersion(projectID int64, applicationID int64, before time.Time) ([]Release, error) { | ||
var releases []Release | ||
if err := client.Select([]string{"release_id", "cluster_name", "version"}).Where("reference <= ?", 0).Where("updated_at < ?", before).Where("version != ''"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary code fragment Select
.
@@ -1055,6 +1055,59 @@ func (s *ReleaseService) GetLatestReleasesByProjectAndVersion(projectID int64, v | |||
return &latests, nil | |||
} | |||
|
|||
func (s *ReleaseService) FindExpiredReleaseBefore(now time.Time) ([]db.Release, error) { | |||
// 7 days before | |||
d, err := time.ParseDuration(strutil.Concat("-", "168", "h")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard code is not recommend, move to the config file pls.
releaseCount := len(releases) | ||
expiredCount := len(expiredReleases) | ||
|
||
if releaseCount <= 10 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above comment.
if releaseCount <= 10 { | ||
// If the quantity of release is less than 10, there is no need to delete | ||
continue | ||
} else if releaseCount < 30 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as above.
|
||
for i := range deleteRelease { | ||
release := deleteRelease[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, v :=
is more clearly.
@@ -572,3 +574,86 @@ version: "2.0" | |||
}) | |||
} | |||
} | |||
|
|||
func TestReleaseServiceGC(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls use sqlmock
instead SQLite
.
da14758
to
84ef097
Compare
What this PR does / why we need it:
Added a GC rule for releases with version on top of the original GC rule
Which issue(s) this PR fixes:
Specified Reviewers:
/assign @iutx @sfwn
ChangeLog
Need cherry-pick to release versions?
Add comment like
/cherry-pick release/1.0
when this PR is merged.