fix --local panic in set commands

pull/564/head
juanvallejo 2018-06-29 10:36:44 -04:00
parent 98de0729cf
commit e8df247597
No known key found for this signature in database
GPG Key ID: 7D2C958002D6448D
6 changed files with 25 additions and 7 deletions

View File

@ -474,7 +474,8 @@ func (o *EnvOptions) RunEnv() error {
for _, patch := range patches { for _, patch := range patches {
info := patch.Info info := patch.Info
if patch.Err != nil { if patch.Err != nil {
allErrs = append(allErrs, fmt.Errorf("error: %s/%s %v", info.Mapping.Resource, info.Name, patch.Err)) name := info.ObjectName()
allErrs = append(allErrs, fmt.Errorf("error: %s %v\n", name, patch.Err))
continue continue
} }

View File

@ -247,7 +247,8 @@ func (o *SetImageOptions) Run() error {
for _, patch := range patches { for _, patch := range patches {
info := patch.Info info := patch.Info
if patch.Err != nil { if patch.Err != nil {
allErrs = append(allErrs, fmt.Errorf("error: %s/%s %v", info.Mapping.Resource, info.Name, patch.Err)) name := info.ObjectName()
allErrs = append(allErrs, fmt.Errorf("error: %s %v\n", name, patch.Err))
continue continue
} }

View File

@ -260,14 +260,15 @@ func (o *SetResourcesOptions) Run() error {
for _, patch := range patches { for _, patch := range patches {
info := patch.Info info := patch.Info
name := info.ObjectName()
if patch.Err != nil { if patch.Err != nil {
allErrs = append(allErrs, fmt.Errorf("error: %s/%s %v", info.Mapping.Resource, info.Name, patch.Err)) allErrs = append(allErrs, fmt.Errorf("error: %s %v\n", name, patch.Err))
continue continue
} }
//no changes //no changes
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 { if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
allErrs = append(allErrs, fmt.Errorf("info: %s %q was not changed", info.Mapping.Resource, info.Name)) allErrs = append(allErrs, fmt.Errorf("info: %s was not changed\n", name))
continue continue
} }

View File

@ -191,8 +191,9 @@ func (o *SetServiceAccountOptions) Run() error {
patches := CalculatePatches(o.infos, scheme.DefaultJSONEncoder(), patchFn) patches := CalculatePatches(o.infos, scheme.DefaultJSONEncoder(), patchFn)
for _, patch := range patches { for _, patch := range patches {
info := patch.Info info := patch.Info
name := info.ObjectName()
if patch.Err != nil { if patch.Err != nil {
patchErrs = append(patchErrs, fmt.Errorf("error: %s/%s %v", info.Mapping.Resource, info.Name, patch.Err)) patchErrs = append(patchErrs, fmt.Errorf("error: %s %v\n", name, patch.Err))
continue continue
} }
if o.local || o.dryRun { if o.local || o.dryRun {

View File

@ -240,14 +240,15 @@ func (o *SubjectOptions) Run(fn updateSubjects) error {
allErrs := []error{} allErrs := []error{}
for _, patch := range patches { for _, patch := range patches {
info := patch.Info info := patch.Info
name := info.ObjectName()
if patch.Err != nil { if patch.Err != nil {
allErrs = append(allErrs, fmt.Errorf("error: %s/%s %v", info.Mapping.Resource, info.Name, patch.Err)) allErrs = append(allErrs, fmt.Errorf("error: %s %v\n", name, patch.Err))
continue continue
} }
//no changes //no changes
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 { if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
allErrs = append(allErrs, fmt.Errorf("info: %s %q was not changed", info.Mapping.Resource, info.Name)) allErrs = append(allErrs, fmt.Errorf("info: %s was not changed\n", name))
continue continue
} }

View File

@ -24,6 +24,7 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"golang.org/x/text/encoding/unicode" "golang.org/x/text/encoding/unicode"
@ -141,6 +142,18 @@ func (i *Info) Refresh(obj runtime.Object, ignoreError bool) error {
return nil return nil
} }
// ObjectName returns an approximate form of the resource's kind/name.
func (i *Info) ObjectName() string {
if i.Mapping != nil {
return fmt.Sprintf("%s/%s", i.Mapping.Resource.Resource, i.Name)
}
gvk := i.Object.GetObjectKind().GroupVersionKind()
if len(gvk.Group) == 0 {
return fmt.Sprintf("%s/%s", strings.ToLower(gvk.Kind), i.Name)
}
return fmt.Sprintf("%s.%s/%s\n", strings.ToLower(gvk.Kind), gvk.Group, i.Name)
}
// String returns the general purpose string representation // String returns the general purpose string representation
func (i *Info) String() string { func (i *Info) String() string {
basicInfo := fmt.Sprintf("Name: %q, Namespace: %q\nObject: %+q", i.Name, i.Namespace, i.Object) basicInfo := fmt.Sprintf("Name: %q, Namespace: %q\nObject: %+q", i.Name, i.Namespace, i.Object)