| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
package etcd |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 4 |
+ etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd" |
|
| 5 | 5 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
| 6 | 6 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
| 7 | 7 |
|
| ... | ... |
@@ -45,11 +45,8 @@ func (r *Etcd) ListBuilds(selector labels.Selector) (*api.BuildList, error) {
|
| 45 | 45 |
func (r *Etcd) GetBuild(id string) (*api.Build, error) {
|
| 46 | 46 |
var build api.Build |
| 47 | 47 |
err := r.ExtractObj(makeBuildKey(id), &build, false) |
| 48 |
- if tools.IsEtcdNotFound(err) {
|
|
| 49 |
- return nil, errors.NewNotFound("build", id)
|
|
| 50 |
- } |
|
| 51 | 48 |
if err != nil {
|
| 52 |
- return nil, err |
|
| 49 |
+ return nil, etcderr.InterpretGetError(err, "build", id) |
|
| 53 | 50 |
} |
| 54 | 51 |
return &build, nil |
| 55 | 52 |
} |
| ... | ... |
@@ -57,25 +54,20 @@ func (r *Etcd) GetBuild(id string) (*api.Build, error) {
|
| 57 | 57 |
// CreateBuild creates a new Build. |
| 58 | 58 |
func (r *Etcd) CreateBuild(build *api.Build) error {
|
| 59 | 59 |
err := r.CreateObj(makeBuildKey(build.ID), build) |
| 60 |
- if tools.IsEtcdNodeExist(err) {
|
|
| 61 |
- return errors.NewAlreadyExists("build", build.ID)
|
|
| 62 |
- } |
|
| 63 |
- return err |
|
| 60 |
+ return etcderr.InterpretCreateError(err, "build", build.ID) |
|
| 64 | 61 |
} |
| 65 | 62 |
|
| 66 | 63 |
// UpdateBuild replaces an existing Build. |
| 67 | 64 |
func (r *Etcd) UpdateBuild(build *api.Build) error {
|
| 68 |
- return r.SetObj(makeBuildKey(build.ID), build) |
|
| 65 |
+ err := r.SetObj(makeBuildKey(build.ID), build) |
|
| 66 |
+ return etcderr.InterpretUpdateError(err, "build", build.ID) |
|
| 69 | 67 |
} |
| 70 | 68 |
|
| 71 | 69 |
// DeleteBuild deletes a Build specified by its ID. |
| 72 | 70 |
func (r *Etcd) DeleteBuild(id string) error {
|
| 73 | 71 |
key := makeBuildKey(id) |
| 74 | 72 |
err := r.Delete(key, true) |
| 75 |
- if tools.IsEtcdNotFound(err) {
|
|
| 76 |
- return errors.NewNotFound("build", id)
|
|
| 77 |
- } |
|
| 78 |
- return err |
|
| 73 |
+ return etcderr.InterpretDeleteError(err, "build", id) |
|
| 79 | 74 |
} |
| 80 | 75 |
|
| 81 | 76 |
func makeBuildConfigKey(id string) string {
|
| ... | ... |
@@ -103,11 +95,8 @@ func (r *Etcd) ListBuildConfigs(selector labels.Selector) (*api.BuildConfigList, |
| 103 | 103 |
func (r *Etcd) GetBuildConfig(id string) (*api.BuildConfig, error) {
|
| 104 | 104 |
var config api.BuildConfig |
| 105 | 105 |
err := r.ExtractObj(makeBuildConfigKey(id), &config, false) |
| 106 |
- if tools.IsEtcdNotFound(err) {
|
|
| 107 |
- return nil, errors.NewNotFound("buildConfig", id)
|
|
| 108 |
- } |
|
| 109 | 106 |
if err != nil {
|
| 110 |
- return nil, err |
|
| 107 |
+ return nil, etcderr.InterpretGetError(err, "buildConfig", id) |
|
| 111 | 108 |
} |
| 112 | 109 |
return &config, nil |
| 113 | 110 |
} |
| ... | ... |
@@ -115,23 +104,18 @@ func (r *Etcd) GetBuildConfig(id string) (*api.BuildConfig, error) {
|
| 115 | 115 |
// CreateBuildConfig creates a new BuildConfig. |
| 116 | 116 |
func (r *Etcd) CreateBuildConfig(config *api.BuildConfig) error {
|
| 117 | 117 |
err := r.CreateObj(makeBuildConfigKey(config.ID), config) |
| 118 |
- if tools.IsEtcdNodeExist(err) {
|
|
| 119 |
- return errors.NewAlreadyExists("buildConfig", config.ID)
|
|
| 120 |
- } |
|
| 121 |
- return err |
|
| 118 |
+ return etcderr.InterpretCreateError(err, "buildConfig", config.ID) |
|
| 122 | 119 |
} |
| 123 | 120 |
|
| 124 | 121 |
// UpdateBuildConfig replaces an existing BuildConfig. |
| 125 | 122 |
func (r *Etcd) UpdateBuildConfig(config *api.BuildConfig) error {
|
| 126 |
- return r.SetObj(makeBuildConfigKey(config.ID), config) |
|
| 123 |
+ err := r.SetObj(makeBuildConfigKey(config.ID), config) |
|
| 124 |
+ return etcderr.InterpretUpdateError(err, "buildConfig", config.ID) |
|
| 127 | 125 |
} |
| 128 | 126 |
|
| 129 | 127 |
// DeleteBuildConfig deletes a BuildConfig specified by its ID. |
| 130 | 128 |
func (r *Etcd) DeleteBuildConfig(id string) error {
|
| 131 | 129 |
key := makeBuildConfigKey(id) |
| 132 | 130 |
err := r.Delete(key, true) |
| 133 |
- if tools.IsEtcdNotFound(err) {
|
|
| 134 |
- return errors.NewNotFound("buildConfig", id)
|
|
| 135 |
- } |
|
| 136 |
- return err |
|
| 131 |
+ return etcderr.InterpretDeleteError(err, "buildConfig", id) |
|
| 137 | 132 |
} |
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
package etcd |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 4 |
+ etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd" |
|
| 5 | 5 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
| 6 | 6 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
| 7 | 7 |
|
| ... | ... |
@@ -47,11 +47,8 @@ func (r *Etcd) GetDeployment(id string) (*api.Deployment, error) {
|
| 47 | 47 |
var deployment api.Deployment |
| 48 | 48 |
key := makeDeploymentKey(id) |
| 49 | 49 |
err := r.ExtractObj(key, &deployment, false) |
| 50 |
- if tools.IsEtcdNotFound(err) {
|
|
| 51 |
- return nil, errors.NewNotFound("deployment", id)
|
|
| 52 |
- } |
|
| 53 | 50 |
if err != nil {
|
| 54 |
- return nil, err |
|
| 51 |
+ return nil, etcderr.InterpretGetError(err, "deployment", id) |
|
| 55 | 52 |
} |
| 56 | 53 |
return &deployment, nil |
| 57 | 54 |
} |
| ... | ... |
@@ -59,25 +56,20 @@ func (r *Etcd) GetDeployment(id string) (*api.Deployment, error) {
|
| 59 | 59 |
// CreateDeployment creates a new Deployment. |
| 60 | 60 |
func (r *Etcd) CreateDeployment(deployment *api.Deployment) error {
|
| 61 | 61 |
err := r.CreateObj(makeDeploymentKey(deployment.ID), deployment) |
| 62 |
- if tools.IsEtcdNodeExist(err) {
|
|
| 63 |
- return errors.NewAlreadyExists("deployment", deployment.ID)
|
|
| 64 |
- } |
|
| 65 |
- return err |
|
| 62 |
+ return etcderr.InterpretCreateError(err, "deployment", deployment.ID) |
|
| 66 | 63 |
} |
| 67 | 64 |
|
| 68 | 65 |
// UpdateDeployment replaces an existing Deployment. |
| 69 | 66 |
func (r *Etcd) UpdateDeployment(deployment *api.Deployment) error {
|
| 70 |
- return r.SetObj(makeDeploymentKey(deployment.ID), deployment) |
|
| 67 |
+ err := r.SetObj(makeDeploymentKey(deployment.ID), deployment) |
|
| 68 |
+ return etcderr.InterpretUpdateError(err, "deployment", deployment.ID) |
|
| 71 | 69 |
} |
| 72 | 70 |
|
| 73 | 71 |
// DeleteDeployment deletes a Deployment specified by its ID. |
| 74 | 72 |
func (r *Etcd) DeleteDeployment(id string) error {
|
| 75 | 73 |
key := makeDeploymentKey(id) |
| 76 | 74 |
err := r.Delete(key, false) |
| 77 |
- if tools.IsEtcdNotFound(err) {
|
|
| 78 |
- return errors.NewNotFound("deployment", id)
|
|
| 79 |
- } |
|
| 80 |
- return err |
|
| 75 |
+ return etcderr.InterpretDeleteError(err, "deployment", id) |
|
| 81 | 76 |
} |
| 82 | 77 |
|
| 83 | 78 |
// ListDeploymentConfigs obtains a list of DeploymentConfigs. |
| ... | ... |
@@ -107,11 +99,8 @@ func (r *Etcd) GetDeploymentConfig(id string) (*api.DeploymentConfig, error) {
|
| 107 | 107 |
var deploymentConfig api.DeploymentConfig |
| 108 | 108 |
key := makeDeploymentConfigKey(id) |
| 109 | 109 |
err := r.ExtractObj(key, &deploymentConfig, false) |
| 110 |
- if tools.IsEtcdNotFound(err) {
|
|
| 111 |
- return nil, errors.NewNotFound("deploymentConfig", id)
|
|
| 112 |
- } |
|
| 113 | 110 |
if err != nil {
|
| 114 |
- return nil, err |
|
| 111 |
+ return nil, etcderr.InterpretGetError(err, "deploymentConfig", id) |
|
| 115 | 112 |
} |
| 116 | 113 |
return &deploymentConfig, nil |
| 117 | 114 |
} |
| ... | ... |
@@ -119,23 +108,18 @@ func (r *Etcd) GetDeploymentConfig(id string) (*api.DeploymentConfig, error) {
|
| 119 | 119 |
// CreateDeploymentConfig creates a new DeploymentConfig. |
| 120 | 120 |
func (r *Etcd) CreateDeploymentConfig(deploymentConfig *api.DeploymentConfig) error {
|
| 121 | 121 |
err := r.CreateObj(makeDeploymentConfigKey(deploymentConfig.ID), deploymentConfig) |
| 122 |
- if tools.IsEtcdNodeExist(err) {
|
|
| 123 |
- return errors.NewAlreadyExists("deploymentConfig", deploymentConfig.ID)
|
|
| 124 |
- } |
|
| 125 |
- return err |
|
| 122 |
+ return etcderr.InterpretCreateError(err, "deploymentConfig", deploymentConfig.ID) |
|
| 126 | 123 |
} |
| 127 | 124 |
|
| 128 | 125 |
// UpdateDeploymentConfig replaces an existing DeploymentConfig. |
| 129 | 126 |
func (r *Etcd) UpdateDeploymentConfig(deploymentConfig *api.DeploymentConfig) error {
|
| 130 |
- return r.SetObj(makeDeploymentConfigKey(deploymentConfig.ID), deploymentConfig) |
|
| 127 |
+ err := r.SetObj(makeDeploymentConfigKey(deploymentConfig.ID), deploymentConfig) |
|
| 128 |
+ return etcderr.InterpretUpdateError(err, "deploymentConfig", deploymentConfig.ID) |
|
| 131 | 129 |
} |
| 132 | 130 |
|
| 133 | 131 |
// DeleteDeploymentConfig deletes a DeploymentConfig specified by its ID. |
| 134 | 132 |
func (r *Etcd) DeleteDeploymentConfig(id string) error {
|
| 135 | 133 |
key := makeDeploymentConfigKey(id) |
| 136 | 134 |
err := r.Delete(key, false) |
| 137 |
- if tools.IsEtcdNotFound(err) {
|
|
| 138 |
- return errors.NewNotFound("deploymentConfig", id)
|
|
| 139 |
- } |
|
| 140 |
- return err |
|
| 135 |
+ return etcderr.InterpretDeleteError(err, "deploymentConfig", id) |
|
| 141 | 136 |
} |
| ... | ... |
@@ -3,7 +3,7 @@ package etcd |
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 | 5 |
|
| 6 |
- apierrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" |
|
| 6 |
+ etcderr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors/etcd" |
|
| 7 | 7 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels" |
| 8 | 8 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" |
| 9 | 9 |
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools" |
| ... | ... |
@@ -50,7 +50,7 @@ func makeImageKey(id string) string {
|
| 50 | 50 |
func (r *Etcd) GetImage(id string) (*api.Image, error) {
|
| 51 | 51 |
var image api.Image |
| 52 | 52 |
if err := r.ExtractObj(makeImageKey(id), &image, false); err != nil {
|
| 53 |
- return nil, err |
|
| 53 |
+ return nil, etcderr.InterpretGetError(err, "image", id) |
|
| 54 | 54 |
} |
| 55 | 55 |
return &image, nil |
| 56 | 56 |
} |
| ... | ... |
@@ -58,10 +58,7 @@ func (r *Etcd) GetImage(id string) (*api.Image, error) {
|
| 58 | 58 |
// CreateImage creates a new image |
| 59 | 59 |
func (r *Etcd) CreateImage(image *api.Image) error {
|
| 60 | 60 |
err := r.CreateObj(makeImageKey(image.ID), image) |
| 61 |
- if tools.IsEtcdNodeExist(err) {
|
|
| 62 |
- return apierrors.NewAlreadyExists("image", image.ID)
|
|
| 63 |
- } |
|
| 64 |
- return err |
|
| 61 |
+ return etcderr.InterpretCreateError(err, "image", image.ID) |
|
| 65 | 62 |
} |
| 66 | 63 |
|
| 67 | 64 |
// UpdateImage updates an existing image |
| ... | ... |
@@ -73,10 +70,7 @@ func (r *Etcd) UpdateImage(image *api.Image) error {
|
| 73 | 73 |
func (r *Etcd) DeleteImage(id string) error {
|
| 74 | 74 |
key := makeImageKey(id) |
| 75 | 75 |
err := r.Delete(key, false) |
| 76 |
- if tools.IsEtcdNotFound(err) {
|
|
| 77 |
- return apierrors.NewNotFound("image", id)
|
|
| 78 |
- } |
|
| 79 |
- return err |
|
| 76 |
+ return etcderr.InterpretDeleteError(err, "image", id) |
|
| 80 | 77 |
} |
| 81 | 78 |
|
| 82 | 79 |
// ListImageRepositories retrieves a list of ImageRepositories that match selector. |
| ... | ... |
@@ -104,7 +98,7 @@ func makeImageRepositoryKey(id string) string {
|
| 104 | 104 |
func (r *Etcd) GetImageRepository(id string) (*api.ImageRepository, error) {
|
| 105 | 105 |
var repo api.ImageRepository |
| 106 | 106 |
if err := r.ExtractObj(makeImageRepositoryKey(id), &repo, false); err != nil {
|
| 107 |
- return nil, err |
|
| 107 |
+ return nil, etcderr.InterpretGetError(err, "imageRepository", id) |
|
| 108 | 108 |
} |
| 109 | 109 |
return &repo, nil |
| 110 | 110 |
} |
| ... | ... |
@@ -124,24 +118,18 @@ func (r *Etcd) WatchImageRepositories(resourceVersion uint64, filter func(repo * |
| 124 | 124 |
// CreateImageRepository registers the given ImageRepository. |
| 125 | 125 |
func (r *Etcd) CreateImageRepository(repo *api.ImageRepository) error {
|
| 126 | 126 |
err := r.CreateObj(makeImageRepositoryKey(repo.ID), repo) |
| 127 |
- if err != nil && tools.IsEtcdNodeExist(err) {
|
|
| 128 |
- return apierrors.NewAlreadyExists("imageRepository", repo.ID)
|
|
| 129 |
- } |
|
| 130 |
- |
|
| 131 |
- return err |
|
| 127 |
+ return etcderr.InterpretCreateError(err, "imageRepository", repo.ID) |
|
| 132 | 128 |
} |
| 133 | 129 |
|
| 134 | 130 |
// UpdateImageRepository replaces an existing ImageRepository in the registry with the given ImageRepository. |
| 135 | 131 |
func (r *Etcd) UpdateImageRepository(repo *api.ImageRepository) error {
|
| 136 |
- return r.SetObj(makeImageRepositoryKey(repo.ID), repo) |
|
| 132 |
+ err := r.SetObj(makeImageRepositoryKey(repo.ID), repo) |
|
| 133 |
+ return etcderr.InterpretUpdateError(err, "imageRepository", repo.ID) |
|
| 137 | 134 |
} |
| 138 | 135 |
|
| 139 | 136 |
// DeleteImageRepository deletes an ImageRepository by id. |
| 140 | 137 |
func (r *Etcd) DeleteImageRepository(id string) error {
|
| 141 | 138 |
imageRepositoryKey := makeImageRepositoryKey(id) |
| 142 | 139 |
err := r.Delete(imageRepositoryKey, false) |
| 143 |
- if err != nil && tools.IsEtcdNotFound(err) {
|
|
| 144 |
- return apierrors.NewNotFound("imageRepository", id)
|
|
| 145 |
- } |
|
| 146 |
- return err |
|
| 140 |
+ return etcderr.InterpretDeleteError(err, "imageRepository", id) |
|
| 147 | 141 |
} |