|
|
@ -181,21 +181,37 @@ func (s *Storage) removeLeastRecent(name string, max int) error {
|
|
|
|
if len(h) <= max {
|
|
|
|
if len(h) <= max {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
overage := len(h) - max
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We want oldest to newest
|
|
|
|
// We want oldest to newest
|
|
|
|
relutil.SortByRevision(h)
|
|
|
|
relutil.SortByRevision(h)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastDeployed, err := s.Deployed(name)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var toDelete []*rspb.Release
|
|
|
|
|
|
|
|
for _, rel := range h {
|
|
|
|
|
|
|
|
// once we have enough releases to delete to reach the max, stop
|
|
|
|
|
|
|
|
if len(h)-len(toDelete) == max {
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if lastDeployed != nil {
|
|
|
|
|
|
|
|
if rel.GetVersion() != lastDeployed.GetVersion() {
|
|
|
|
|
|
|
|
toDelete = append(toDelete, rel)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
toDelete = append(toDelete, rel)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Delete as many as possible. In the case of API throughput limitations,
|
|
|
|
// Delete as many as possible. In the case of API throughput limitations,
|
|
|
|
// multiple invocations of this function will eventually delete them all.
|
|
|
|
// multiple invocations of this function will eventually delete them all.
|
|
|
|
toDelete := h[0:overage]
|
|
|
|
|
|
|
|
errors := []error{}
|
|
|
|
errors := []error{}
|
|
|
|
for _, rel := range toDelete {
|
|
|
|
for _, rel := range toDelete {
|
|
|
|
key := makeKey(name, rel.Version)
|
|
|
|
err = s.deleteReleaseVersion(name, rel.GetVersion())
|
|
|
|
_, innerErr := s.Delete(name, rel.Version)
|
|
|
|
if err != nil {
|
|
|
|
if innerErr != nil {
|
|
|
|
errors = append(errors, err)
|
|
|
|
s.Log("error pruning %s from release history: %s", key, innerErr)
|
|
|
|
|
|
|
|
errors = append(errors, innerErr)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -210,6 +226,16 @@ func (s *Storage) removeLeastRecent(name string, max int) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *Storage) deleteReleaseVersion(name string, version int32) error {
|
|
|
|
|
|
|
|
key := makeKey(name, version)
|
|
|
|
|
|
|
|
_, err := s.Delete(name, version)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
s.Log("error pruning %s from release history: %s", key, err)
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Last fetches the last revision of the named release.
|
|
|
|
// Last fetches the last revision of the named release.
|
|
|
|
func (s *Storage) Last(name string) (*rspb.Release, error) {
|
|
|
|
func (s *Storage) Last(name string) (*rspb.Release, error) {
|
|
|
|
s.Log("getting last revision of %q", name)
|
|
|
|
s.Log("getting last revision of %q", name)
|
|
|
|