diff --git a/pkg/storage/driver/driver.go b/pkg/storage/driver/driver.go index 28e19268f..c3b0977a6 100644 --- a/pkg/storage/driver/driver.go +++ b/pkg/storage/driver/driver.go @@ -24,9 +24,9 @@ var ( // ErrReleaseNotFound indicates that a release is not found. ErrReleaseNotFound = errors.New("release: not found") // ErrReleaseExists indicates that a release already exists. - ErrReleaseExists = errors.New("release: already exists") + ErrReleaseExists = errors.New("release: already exists") // ErrDriverAction indicates the storage driver failed to execute the requested action. - ErrDriverAction = errors.New("driver: failed to perform action") + ErrDriverAction = errors.New("driver: failed to perform action") ) // Creator stores a release. @@ -62,4 +62,4 @@ type Driver interface { Updator Deletor Queryor -} \ No newline at end of file +} diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index ce1c6c30c..b691be7f6 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -18,47 +18,59 @@ package storage // import "k8s.io/helm/pkg/storage" import ( rspb "k8s.io/helm/pkg/proto/hapi/release" "k8s.io/helm/pkg/storage/driver" + "log" ) type Storage struct { driver.Driver } -// Create creates a new storage entry holding the release. -// An error is returned if storage failed to store the release. -// -// TODO: Is marking the release as deployed the only task here? -// What happens if an identical release already exists? +// Create creates a new storage entry holding the release. An +// error is returned if the storage driver failed to store the +// release, or a release with identical an key already exists. func (s *Storage) Create(rls *rspb.Release) error { + log.Printf("storage: create: %q\n", rls.Name) return s.Driver.Create(rls) } // Update update the release in storage. An error is returned if the -// storage backend fails to update the release or if the release does not exist. -// -// TODO: Fetch most recent deployed release, if it exists, mark -// as SUPERSEDED, then store both new and old. +// storage backend fails to update the release or if the release +// does not exist. func (s *Storage) Update(rls *rspb.Release) error { + // TODO: + // 1. Fetch most recent deployed release. + // 2. If it exists: + // - Then mark as 'SUPERSEDED' + // - Then store both new and old. + // 3. Else: + // - Create(rls) + log.Printf("storage: update: %q\n", rls.Name) + + // fetch most recent deployed release + // old, err := s.Get(rls.Name) return s.Driver.Update(rls) } -// Delete deletes the release from storage. An error is returned if the -// storage backend fails to delete the release or if the release does not exist. -// -// TODO: The release status should be modified to reflect the DELETED status. +// Delete deletes the release from storage. An error is returned if +// the storage backend fails to delete the release or if the release +// does not exist. func (s *Storage) Delete(key string) (*rspb.Release, error) { + // TODO: Mark the release as DELETED. + log.Printf("storage: delete: %q\n", key) return s.Driver.Delete(key) } // ListReleases returns all releases from storage. An error is returned if the // storage backend fails to retrieve the releases. func (s *Storage) ListReleases() ([]*rspb.Release, error) { + log.Println("storage: list all releases") return s.Driver.List(func(_ *rspb.Release) bool { return true }) } // ListDeleted returns all releases with Status == DELETED. An error is returned // if the storage backend fails to retrieve the releases. func (s *Storage) ListDeleted() ([]*rspb.Release, error) { + log.Println("storage: list deleted releases") return s.Driver.List(func(rls *rspb.Release) bool { return StatusFilter(rspb.Status_DELETED).Check(rls) }) @@ -67,6 +79,7 @@ func (s *Storage) ListDeleted() ([]*rspb.Release, error) { // ListDeployed returns all releases with Status == DEPLOYED. An error is returned // if the storage backend fails to retrieve the releases. func (s *Storage) ListDeployed() ([]*rspb.Release, error) { + log.Println("storage: list deployed releases") return s.Driver.List(func(rls *rspb.Release) bool { return StatusFilter(rspb.Status_DEPLOYED).Check(rls) }) @@ -76,6 +89,7 @@ func (s *Storage) ListDeployed() ([]*rspb.Release, error) { // (filter0 && filter1 && ... && filterN), i.e. a Release is included in the results // if and only if all filters return true. func (s *Storage) ListFilterAll(filters ...FilterFunc) ([]*rspb.Release, error) { + log.Println("storage: list all releases with filter") return s.Driver.List(func(rls *rspb.Release) bool { return All(filters...).Check(rls) }) @@ -85,6 +99,7 @@ func (s *Storage) ListFilterAll(filters ...FilterFunc) ([]*rspb.Release, error) // (filter0 || filter1 || ... || filterN), i.e. a Release is included in the results // if at least one of the filters returns true. func (s *Storage) ListFilterAny(filters ...FilterFunc) ([]*rspb.Release, error) { + log.Println("storage: list any releases with filter") return s.Driver.List(func(rls *rspb.Release) bool { return Any(filters...).Check(rls) })