Skip to content

Commit

Permalink
fix --local panic in set commands
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Feb 7, 2019
1 parent 98de072 commit e8df247
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pkg/kubectl/cmd/set/set_env.go
Expand Up @@ -474,7 +474,8 @@ func (o *EnvOptions) RunEnv() error {
for _, patch := range patches {
info := patch.Info
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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/kubectl/cmd/set/set_image.go
Expand Up @@ -247,7 +247,8 @@ func (o *SetImageOptions) Run() error {
for _, patch := range patches {
info := patch.Info
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
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/kubectl/cmd/set/set_resources.go
Expand Up @@ -260,14 +260,15 @@ func (o *SetResourcesOptions) Run() error {

for _, patch := range patches {
info := patch.Info
name := info.ObjectName()
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
}

//no changes
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
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/kubectl/cmd/set/set_serviceaccount.go
Expand Up @@ -191,8 +191,9 @@ func (o *SetServiceAccountOptions) Run() error {
patches := CalculatePatches(o.infos, scheme.DefaultJSONEncoder(), patchFn)
for _, patch := range patches {
info := patch.Info
name := info.ObjectName()
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
}
if o.local || o.dryRun {
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubectl/cmd/set/set_subject.go
Expand Up @@ -240,14 +240,15 @@ func (o *SubjectOptions) Run(fn updateSubjects) error {
allErrs := []error{}
for _, patch := range patches {
info := patch.Info
name := info.ObjectName()
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
}

//no changes
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
}

Expand Down
Expand Up @@ -24,6 +24,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"time"

"golang.org/x/text/encoding/unicode"
Expand Down Expand Up @@ -141,6 +142,18 @@ func (i *Info) Refresh(obj runtime.Object, ignoreError bool) error {
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
func (i *Info) String() string {
basicInfo := fmt.Sprintf("Name: %q, Namespace: %q\nObject: %+q", i.Name, i.Namespace, i.Object)
Expand Down

0 comments on commit e8df247

Please sign in to comment.