mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
fix kubectl apply error message
This commit is contained in:
parent
02611149c1
commit
e2dedc76a8
@ -271,12 +271,12 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||||||
// in the patch sent to the server.
|
// in the patch sent to the server.
|
||||||
modified, err := kubectl.GetModifiedConfiguration(info, true, encoder)
|
modified, err := kubectl.GetModifiedConfiguration(info, true, encoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving modified configuration from:\n%v\nfor:", info), info.Source, err)
|
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving modified configuration from:\n%s\nfor:", info.String()), info.Source, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := info.Get(); err != nil {
|
if err := info.Get(); err != nil {
|
||||||
if !errors.IsNotFound(err) {
|
if !errors.IsNotFound(err) {
|
||||||
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%v\nfrom server for:", info), info.Source, err)
|
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%s\nfrom server for:", info.String()), info.Source, err)
|
||||||
}
|
}
|
||||||
// Create the resource if it doesn't exist
|
// Create the resource if it doesn't exist
|
||||||
// First, update the annotation used by kubectl apply
|
// First, update the annotation used by kubectl apply
|
||||||
|
@ -143,12 +143,12 @@ func (o *SetLastAppliedOptions) Validate(f cmdutil.Factory, cmd *cobra.Command)
|
|||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%v\nfrom server for:", info), info.Source, err)
|
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%s\nfrom server for:", info.String()), info.Source, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
originalBuf, err := kubectl.GetOriginalConfiguration(info.Mapping, info.Object)
|
originalBuf, err := kubectl.GetOriginalConfiguration(info.Mapping, info.Object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%v\nfrom server for:", info), info.Source, err)
|
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%s\nfrom server for:", info.String()), info.Source, err)
|
||||||
}
|
}
|
||||||
if originalBuf == nil && !o.CreateAnnotation {
|
if originalBuf == nil && !o.CreateAnnotation {
|
||||||
return cmdutil.UsageErrorf(cmd, "no last-applied-configuration annotation found on resource: %s, to create the annotation, run the command with --create-annotation", info.Name)
|
return cmdutil.UsageErrorf(cmd, "no last-applied-configuration annotation found on resource: %s, to create the annotation, run the command with --create-annotation", info.Name)
|
||||||
|
@ -431,7 +431,7 @@ func RunDiff(f cmdutil.Factory, diff *DiffProgram, options *DiffOptions, from, t
|
|||||||
|
|
||||||
if err := info.Get(); err != nil {
|
if err := info.Get(); err != nil {
|
||||||
if !errors.IsNotFound(err) {
|
if !errors.IsNotFound(err) {
|
||||||
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%v\nfrom server for:", info), info.Source, err)
|
return cmdutil.AddSourceToErr(fmt.Sprintf("retrieving current configuration of:\n%s\nfrom server for:", info.String()), info.Source, err)
|
||||||
}
|
}
|
||||||
info.Object = nil
|
info.Object = nil
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,17 @@ func (i *Info) Refresh(obj runtime.Object, ignoreError bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
if i.Mapping != nil {
|
||||||
|
mappingInfo := fmt.Sprintf("Resource: %q, GroupVersionKind: %q", i.Mapping.Resource,
|
||||||
|
i.Mapping.GroupVersionKind.String())
|
||||||
|
return fmt.Sprint(mappingInfo, "\n", basicInfo)
|
||||||
|
}
|
||||||
|
return basicInfo
|
||||||
|
}
|
||||||
|
|
||||||
// Namespaced returns true if the object belongs to a namespace
|
// Namespaced returns true if the object belongs to a namespace
|
||||||
func (i *Info) Namespaced() bool {
|
func (i *Info) Namespaced() bool {
|
||||||
return i.Mapping != nil && i.Mapping.Scope.Name() == meta.RESTScopeNameNamespace
|
return i.Mapping != nil && i.Mapping.Scope.Name() == meta.RESTScopeNameNamespace
|
||||||
|
Loading…
Reference in New Issue
Block a user