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

feat: introduce new retain harbor resources labels and deprecate old ones #244

Merged
merged 1 commit into from
Jan 24, 2024
Merged
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
46 changes: 35 additions & 11 deletions internal/utilities/deletions/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,50 @@ func (d *Deletions) ProcessDeletion(ctx context.Context, opLog logr.Logger, name
// being cleaned up in harbor by setting them to `false`
// this is useful for migrating environments, where the source or destination can have these added
// so that when the migration is complete the resulting images aren't also removed
// @deprecate these two labels in favour for the `retain` ones
if val, ok := secret.Labels["harbor.lagoon.sh/cleanup-repositories"]; ok {
opLog.WithName("DeleteNamespace").Info("Secret label 'harbor.lagoon.sh/cleanup-repositories' is deprecated, use 'harbor.lagoon.sh/retain-repositories' instead")
cleanupRepo, _ = strconv.ParseBool(val)
}
if val, ok := secret.Labels["harbor.lagoon.sh/cleanup-robotaccount"]; ok {
opLog.WithName("DeleteNamespace").Info("Secret label 'harbor.lagoon.sh/cleanup-robotaccount' is deprecated, use 'harbor.lagoon.sh/retain-robotaccount' instead")
cleanupRobot, _ = strconv.ParseBool(val)
}
lagoonHarbor, err := harbor.New(d.Harbor)
if err != nil {
return err
// use a retain label for "retain=true", this is clearer than "cleanup"
if val, ok := secret.Labels["harbor.lagoon.sh/retain-repositories"]; ok {
retain, _ := strconv.ParseBool(val)
cleanupRepo = !retain
}
curVer, err := lagoonHarbor.GetHarborVersion(ctx)
if err != nil {
return err
if val, ok := secret.Labels["harbor.lagoon.sh/retain-robotaccount"]; ok {
retain, _ := strconv.ParseBool(val)
cleanupRobot = !retain
}
if lagoonHarbor.UseV2Functions(curVer) {
if cleanupRepo {
lagoonHarbor.DeleteRepository(ctx, project, environment)
// also check the namespace for the retain labels
if val, ok := namespace.Labels["harbor.lagoon.sh/retain-repositories"]; ok {
retain, _ := strconv.ParseBool(val)
cleanupRepo = !retain
}
if val, ok := namespace.Labels["harbor.lagoon.sh/retain-robotaccount"]; ok {
retain, _ := strconv.ParseBool(val)
cleanupRobot = !retain
}
if cleanupRepo || cleanupRobot {
// either of the repo or the robot need cleaning up when the namespace is terminated, then perform the required actions here
lagoonHarbor, err := harbor.New(d.Harbor)
if err != nil {
return err
}
curVer, err := lagoonHarbor.GetHarborVersion(ctx)
if err != nil {
return err
}
if cleanupRobot {
lagoonHarbor.DeleteRobotAccount(ctx, project, environment)
if lagoonHarbor.UseV2Functions(curVer) {
if cleanupRepo {
lagoonHarbor.DeleteRepository(ctx, project, environment)
}
if cleanupRobot {
lagoonHarbor.DeleteRobotAccount(ctx, project, environment)
}
}
}
}
Expand Down
Loading