...

Source file src/helm.sh/helm/v3/pkg/storage/driver/driver.go

Documentation: helm.sh/helm/v3/pkg/storage/driver

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package driver // import "helm.sh/helm/v3/pkg/storage/driver"
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/pkg/errors"
    23  
    24  	rspb "helm.sh/helm/v3/pkg/release"
    25  )
    26  
    27  var (
    28  	// ErrReleaseNotFound indicates that a release is not found.
    29  	ErrReleaseNotFound = errors.New("release: not found")
    30  	// ErrReleaseExists indicates that a release already exists.
    31  	ErrReleaseExists = errors.New("release: already exists")
    32  	// ErrInvalidKey indicates that a release key could not be parsed.
    33  	ErrInvalidKey = errors.New("release: invalid key")
    34  	// ErrNoDeployedReleases indicates that there are no releases with the given key in the deployed state
    35  	ErrNoDeployedReleases = errors.New("has no deployed releases")
    36  )
    37  
    38  // StorageDriverError records an error and the release name that caused it
    39  type StorageDriverError struct {
    40  	ReleaseName string
    41  	Err         error
    42  }
    43  
    44  func (e *StorageDriverError) Error() string {
    45  	return fmt.Sprintf("%q %s", e.ReleaseName, e.Err.Error())
    46  }
    47  
    48  func (e *StorageDriverError) Unwrap() error { return e.Err }
    49  
    50  func NewErrNoDeployedReleases(releaseName string) error {
    51  	return &StorageDriverError{
    52  		ReleaseName: releaseName,
    53  		Err:         ErrNoDeployedReleases,
    54  	}
    55  }
    56  
    57  // Creator is the interface that wraps the Create method.
    58  //
    59  // Create stores the release or returns ErrReleaseExists
    60  // if an identical release already exists.
    61  type Creator interface {
    62  	Create(key string, rls *rspb.Release) error
    63  }
    64  
    65  // Updator is the interface that wraps the Update method.
    66  //
    67  // Update updates an existing release or returns
    68  // ErrReleaseNotFound if the release does not exist.
    69  type Updator interface {
    70  	Update(key string, rls *rspb.Release) error
    71  }
    72  
    73  // Deletor is the interface that wraps the Delete method.
    74  //
    75  // Delete deletes the release named by key or returns
    76  // ErrReleaseNotFound if the release does not exist.
    77  type Deletor interface {
    78  	Delete(key string) (*rspb.Release, error)
    79  }
    80  
    81  // Queryor is the interface that wraps the Get and List methods.
    82  //
    83  // Get returns the release named by key or returns ErrReleaseNotFound
    84  // if the release does not exist.
    85  //
    86  // List returns the set of all releases that satisfy the filter predicate.
    87  //
    88  // Query returns the set of all releases that match the provided label set.
    89  type Queryor interface {
    90  	Get(key string) (*rspb.Release, error)
    91  	List(filter func(*rspb.Release) bool) ([]*rspb.Release, error)
    92  	Query(labels map[string]string) ([]*rspb.Release, error)
    93  }
    94  
    95  // Driver is the interface composed of Creator, Updator, Deletor, and Queryor
    96  // interfaces. It defines the behavior for storing, updating, deleted,
    97  // and retrieving Helm releases from some underlying storage mechanism,
    98  // e.g. memory, configmaps.
    99  type Driver interface {
   100  	Creator
   101  	Updator
   102  	Deletor
   103  	Queryor
   104  	Name() string
   105  }
   106  

View as plain text