github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/deploy/kubectl/errors.go (about) 1 /* 2 Copyright 2020 The Skaffold 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 kubectl 18 19 import ( 20 "fmt" 21 22 deployerr "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/error" 23 sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" 24 "github.com/GoogleContainerTools/skaffold/proto/v1" 25 ) 26 27 const ( 28 toolName = "Kubectl" 29 installLink = "https://kubernetes.io/docs/tasks/tools/install-kubectl" 30 ) 31 32 func versionGetErr(err error) error { 33 return sErrors.NewError(err, 34 &proto.ActionableErr{ 35 Message: deployerr.MissingToolErr(toolName, err), 36 ErrCode: proto.StatusCode_DEPLOY_KUBECTL_VERSION_ERR, 37 Suggestions: []*proto.Suggestion{ 38 { 39 SuggestionCode: proto.SuggestionCode_INSTALL_KUBECTL, 40 Action: fmt.Sprintf("Please install kubectl via %s", installLink), 41 }, 42 }, 43 }) 44 } 45 46 func offlineModeErr() error { 47 return sErrors.NewErrorWithStatusCode( 48 &proto.ActionableErr{ 49 Message: "Cannot use offline mode if URL manifests are configured", 50 ErrCode: proto.StatusCode_DEPLOY_KUBECTL_OFFLINE_MODE_ERR, 51 Suggestions: []*proto.Suggestion{ 52 { 53 SuggestionCode: proto.SuggestionCode_SET_RENDER_FLAG_OFFLINE_FALSE, 54 Action: "Please rerun with --offline=false", 55 }, 56 }, 57 }) 58 } 59 60 func waitForDeletionErr(err error) error { 61 return sErrors.NewError(err, 62 &proto.ActionableErr{ 63 Message: fmt.Sprintf("waiting for deletion: %s", err), 64 ErrCode: proto.StatusCode_DEPLOY_ERR_WAITING_FOR_DELETION, 65 }) 66 } 67 68 func readManifestErr(err error) error { 69 return sErrors.NewError(err, 70 &proto.ActionableErr{ 71 Message: err.Error(), 72 ErrCode: proto.StatusCode_DEPLOY_READ_MANIFEST_ERR, 73 }) 74 } 75 76 func readRemoteManifestErr(err error) error { 77 return sErrors.NewError(err, 78 &proto.ActionableErr{ 79 Message: err.Error(), 80 ErrCode: proto.StatusCode_DEPLOY_READ_REMOTE_MANIFEST_ERR, 81 }) 82 } 83 84 func listManifestErr(err error) error { 85 return sErrors.NewError(err, 86 &proto.ActionableErr{ 87 Message: err.Error(), 88 ErrCode: proto.StatusCode_DEPLOY_LIST_MANIFEST_ERR, 89 }) 90 } 91 92 func userErr(err error) error { 93 return deployerr.UserError(err, proto.StatusCode_DEPLOY_KUBECTL_USER_ERR) 94 }