github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/deploy/helm/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 helm
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/pkg/errors"
    23  
    24  	deployerr "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/error"
    25  	sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
    26  	"github.com/GoogleContainerTools/skaffold/proto/v1"
    27  )
    28  
    29  const (
    30  	installLink            = "https://helm.sh/docs/intro/install"
    31  	toolName               = "Helm"
    32  	artifactOverrridesLink = "https://skaffold.dev/docs/references/yaml/#deploy-helm-releases-artifactOverrides"
    33  )
    34  
    35  func versionGetErr(err error) error {
    36  	return sErrors.NewError(err,
    37  		&proto.ActionableErr{
    38  			Message: deployerr.MissingToolErr(toolName, fmt.Errorf(versionErrorString, err)),
    39  			ErrCode: proto.StatusCode_DEPLOY_HELM_VERSION_ERR,
    40  			Suggestions: []*proto.Suggestion{
    41  				{
    42  					SuggestionCode: proto.SuggestionCode_INSTALL_HELM,
    43  					Action:         fmt.Sprintf("Please install helm via %s", installLink),
    44  				},
    45  			},
    46  		})
    47  }
    48  
    49  func minVersionErr() error {
    50  	return sErrors.NewErrorWithStatusCode(
    51  		&proto.ActionableErr{
    52  			Message: "skaffold requires Helm version 3.0.0 or greater",
    53  			ErrCode: proto.StatusCode_DEPLOY_HELM_MIN_VERSION_ERR,
    54  			Suggestions: []*proto.Suggestion{
    55  				{
    56  					SuggestionCode: proto.SuggestionCode_UPGRADE_HELM,
    57  					Action:         fmt.Sprintf("Please upgrade helm to v3.0.0 or higher via %s", installLink),
    58  				},
    59  			},
    60  		})
    61  }
    62  
    63  func helmLabelErr(err error) error {
    64  	return sErrors.NewError(err,
    65  		&proto.ActionableErr{
    66  			Message: err.Error(),
    67  			ErrCode: proto.StatusCode_DEPLOY_HELM_APPLY_LABELS,
    68  		})
    69  }
    70  
    71  func userErr(prefix string, err error) error {
    72  	return deployerr.UserError(errors.Wrap(err, prefix), proto.StatusCode_DEPLOY_HELM_USER_ERR)
    73  }
    74  
    75  func noMatchingBuild(image string) error {
    76  	return sErrors.NewErrorWithStatusCode(
    77  		&proto.ActionableErr{
    78  			Message: fmt.Sprintf("No built image found for `releases.artifactOverrides` value %s", image),
    79  			ErrCode: proto.StatusCode_DEPLOY_NO_MATCHING_BUILD,
    80  			Suggestions: []*proto.Suggestion{
    81  				{
    82  					SuggestionCode: proto.SuggestionCode_FIX_SKAFFOLD_CONFIG_HELM_ARTIFACT_OVERRIDES,
    83  					Action:         fmt.Sprintf("\nPlease verify `%s` is present in `build.artifacts`. See %s for more help", image, artifactOverrridesLink),
    84  				},
    85  			},
    86  		})
    87  }
    88  
    89  func createNamespaceErr(version string) error {
    90  	return sErrors.NewErrorWithStatusCode(
    91  		&proto.ActionableErr{
    92  			Message: fmt.Sprintf("Skaffold config options `createNamespace` is not available in the current Helm version %s", version),
    93  			ErrCode: proto.StatusCode_DEPLOY_HELM_CREATE_NS_NOT_AVAILABLE,
    94  			Suggestions: []*proto.Suggestion{
    95  				{
    96  					SuggestionCode: proto.SuggestionCode_UPGRADE_HELM32,
    97  					Action:         "\nPlease update Helm to version 3.2 or higher",
    98  				},
    99  				{
   100  					SuggestionCode: proto.SuggestionCode_FIX_SKAFFOLD_CONFIG_HELM_CREATE_NAMESPACE,
   101  					Action:         "set `releases.createNamespace` to false and try again",
   102  				},
   103  			},
   104  		})
   105  }