pull/1007/head
fibonacci1729 8 years ago
parent c7e3ec7c46
commit 241cc29883

@ -18,47 +18,59 @@ package storage // import "k8s.io/helm/pkg/storage"
import ( import (
rspb "k8s.io/helm/pkg/proto/hapi/release" rspb "k8s.io/helm/pkg/proto/hapi/release"
"k8s.io/helm/pkg/storage/driver" "k8s.io/helm/pkg/storage/driver"
"log"
) )
type Storage struct { type Storage struct {
driver.Driver driver.Driver
} }
// Create creates a new storage entry holding the release. // Create creates a new storage entry holding the release. An
// An error is returned if storage failed to store the release. // error is returned if the storage driver failed to store the
// // release, or a release with identical an key already exists.
// TODO: Is marking the release as deployed the only task here?
// What happens if an identical release already exists?
func (s *Storage) Create(rls *rspb.Release) error { func (s *Storage) Create(rls *rspb.Release) error {
log.Printf("storage: create: %q\n", rls.Name)
return s.Driver.Create(rls) return s.Driver.Create(rls)
} }
// Update update the release in storage. An error is returned if the // 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. // 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.
func (s *Storage) Update(rls *rspb.Release) error { 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) return s.Driver.Update(rls)
} }
// Delete deletes the release from storage. An error is returned if the // Delete deletes the release from storage. An error is returned if
// storage backend fails to delete the release or if the release does not exist. // 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.
func (s *Storage) Delete(key string) (*rspb.Release, error) { 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) return s.Driver.Delete(key)
} }
// ListReleases returns all releases from storage. An error is returned if the // ListReleases returns all releases from storage. An error is returned if the
// storage backend fails to retrieve the releases. // storage backend fails to retrieve the releases.
func (s *Storage) ListReleases() ([]*rspb.Release, error) { func (s *Storage) ListReleases() ([]*rspb.Release, error) {
log.Println("storage: list all releases")
return s.Driver.List(func(_ *rspb.Release) bool { return true }) return s.Driver.List(func(_ *rspb.Release) bool { return true })
} }
// ListDeleted returns all releases with Status == DELETED. An error is returned // ListDeleted returns all releases with Status == DELETED. An error is returned
// if the storage backend fails to retrieve the releases. // if the storage backend fails to retrieve the releases.
func (s *Storage) ListDeleted() ([]*rspb.Release, error) { func (s *Storage) ListDeleted() ([]*rspb.Release, error) {
log.Println("storage: list deleted releases")
return s.Driver.List(func(rls *rspb.Release) bool { return s.Driver.List(func(rls *rspb.Release) bool {
return StatusFilter(rspb.Status_DELETED).Check(rls) 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 // ListDeployed returns all releases with Status == DEPLOYED. An error is returned
// if the storage backend fails to retrieve the releases. // if the storage backend fails to retrieve the releases.
func (s *Storage) ListDeployed() ([]*rspb.Release, error) { func (s *Storage) ListDeployed() ([]*rspb.Release, error) {
log.Println("storage: list deployed releases")
return s.Driver.List(func(rls *rspb.Release) bool { return s.Driver.List(func(rls *rspb.Release) bool {
return StatusFilter(rspb.Status_DEPLOYED).Check(rls) 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 // (filter0 && filter1 && ... && filterN), i.e. a Release is included in the results
// if and only if all filters return true. // if and only if all filters return true.
func (s *Storage) ListFilterAll(filters ...FilterFunc) ([]*rspb.Release, error) { 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 s.Driver.List(func(rls *rspb.Release) bool {
return All(filters...).Check(rls) 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 // (filter0 || filter1 || ... || filterN), i.e. a Release is included in the results
// if at least one of the filters returns true. // if at least one of the filters returns true.
func (s *Storage) ListFilterAny(filters ...FilterFunc) ([]*rspb.Release, error) { 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 s.Driver.List(func(rls *rspb.Release) bool {
return Any(filters...).Check(rls) return Any(filters...).Check(rls)
}) })

Loading…
Cancel
Save