Merge pull request #280 from monopole/fixntis

Fix some Go nits.
This commit is contained in:
k8s-ci-robot
2018-08-23 10:37:58 -07:00
committed by GitHub
5 changed files with 11 additions and 11 deletions

View File

@@ -109,16 +109,16 @@ func (mf *kustomizationFile) validate() error {
} }
func (mf *kustomizationFile) read() (*types.Kustomization, error) { func (mf *kustomizationFile) read() (*types.Kustomization, error) {
bytes, err := mf.fsys.ReadFile(mf.path) data, err := mf.fsys.ReadFile(mf.path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var kustomization types.Kustomization var kustomization types.Kustomization
err = yaml.Unmarshal(bytes, &kustomization) err = yaml.Unmarshal(data, &kustomization)
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = mf.parseCommentedFields(bytes) err = mf.parseCommentedFields(data)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -129,11 +129,11 @@ func (mf *kustomizationFile) write(kustomization *types.Kustomization) error {
if kustomization == nil { if kustomization == nil {
return errors.New("util: kustomization file arg is nil") return errors.New("util: kustomization file arg is nil")
} }
bytes, err := mf.marshal(kustomization) data, err := mf.marshal(kustomization)
if err != nil { if err != nil {
return err return err
} }
return mf.fsys.WriteFile(mf.path, bytes) return mf.fsys.WriteFile(mf.path, data)
} }
func stringInSlice(str string, list []string) bool { func stringInSlice(str string, list []string) bool {
@@ -173,7 +173,7 @@ func (mf *kustomizationFile) parseCommentedFields(content []byte) error {
} }
func (mf *kustomizationFile) marshal(kustomization *types.Kustomization) ([]byte, error) { func (mf *kustomizationFile) marshal(kustomization *types.Kustomization) ([]byte, error) {
output := []byte{} var output []byte
for _, comment := range mf.originalFields { for _, comment := range mf.originalFields {
output = append(output, comment.comment...) output = append(output, comment.comment...)
content, err := marshalField(comment.field, kustomization) content, err := marshalField(comment.field, kustomization)

View File

@@ -69,13 +69,13 @@ and overwrite the previous newTag if the image name exists.
// Validate validates setImageTag command. // Validate validates setImageTag command.
func (o *setImageTagOptions) Validate(args []string) error { func (o *setImageTagOptions) Validate(args []string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("No image and newTag specified.") return errors.New("no image and newTag specified")
} }
o.imageTagMap = make(map[string]string) o.imageTagMap = make(map[string]string)
for _, arg := range args { for _, arg := range args {
imagetag := pattern.FindStringSubmatch(arg) imagetag := pattern.FindStringSubmatch(arg)
if len(imagetag) != 3 { if len(imagetag) != 3 {
return errors.New("Invalid format of imagetag, must specify it as <image>:<newtag>") return errors.New("invalid format of imagetag, must specify it as <image>:<newtag>")
} }
o.imageTagMap[imagetag[1]] = imagetag[2] o.imageTagMap[imagetag[1]] = imagetag[2]
} }

View File

@@ -93,7 +93,7 @@ func TestSetImageTagsNoArgs(t *testing.T) {
if err == nil { if err == nil {
t.Errorf("expected error: %v", err) t.Errorf("expected error: %v", err)
} }
if err.Error() != "No image and newTag specified." { if err.Error() != "no image and newTag specified" {
t.Errorf("incorrect error: %v", err.Error()) t.Errorf("incorrect error: %v", err.Error())
} }
} }

View File

@@ -272,7 +272,7 @@ func MergeWithOverride(maps ...ResMap) (ResMap, error) {
result[id] = r result[id] = r
} }
} else { } else {
return nil, fmt.Errorf("Merge conflict, found multiple objects %v the Resmap %v can merge into", matchedId, id) return nil, fmt.Errorf("merge conflict, found multiple objects %v the Resmap %v can merge into", matchedId, id)
} }
} }
} }

View File

@@ -60,7 +60,7 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
return fmt.Errorf("failed to find an object with %#v to apply the patch", id.Gvk()) return fmt.Errorf("failed to find an object with %#v to apply the patch", id.Gvk())
} }
if len(matchedIds) > 1 { if len(matchedIds) > 1 {
return fmt.Errorf("Found multiple objects %#v that the patch %#v can apply", matchedIds, id) return fmt.Errorf("found multiple objects %#v targeted by patch %#v (ambiguous)", matchedIds, id)
} }
id = matchedIds[0] id = matchedIds[0]
base := baseResourceMap[id] base := baseResourceMap[id]