mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Fixes get -oname for unstructured objects
This commit is contained in:
		@@ -1362,6 +1362,8 @@ __EOF__
 | 
			
		||||
  kubectl "${kube_flags[@]}" get foos/test -o "jsonpath={.someField}"          --allow-missing-template-keys=false
 | 
			
		||||
  kubectl "${kube_flags[@]}" get foos      -o "go-template={{range .items}}{{.someField}}{{end}}" --allow-missing-template-keys=false
 | 
			
		||||
  kubectl "${kube_flags[@]}" get foos/test -o "go-template={{.someField}}"                        --allow-missing-template-keys=false
 | 
			
		||||
  output_message=$(kubectl get foos/test -o name)
 | 
			
		||||
  kube::test::if_has_string "${output_message}" 'foos/test'
 | 
			
		||||
 | 
			
		||||
  # Test patching
 | 
			
		||||
  kube::log::status "Testing ThirdPartyResource patching"
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,10 @@ func NewBuilderFactory(clientAccessFactory ClientAccessFactory, objectMappingFac
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (f *ring2Factory) PrinterForCommand(cmd *cobra.Command) (printers.ResourcePrinter, bool, error) {
 | 
			
		||||
	mapper, typer := f.objectMappingFactory.Object()
 | 
			
		||||
	mapper, typer, err := f.objectMappingFactory.UnstructuredObject()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, false, err
 | 
			
		||||
	}
 | 
			
		||||
	// TODO: used by the custom column implementation and the name implementation, break this dependency
 | 
			
		||||
	decoders := []runtime.Decoder{f.clientAccessFactory.Decoder(true), unstructured.UnstructuredJSONScheme}
 | 
			
		||||
	return PrinterForCommand(cmd, mapper, typer, decoders)
 | 
			
		||||
 
 | 
			
		||||
@@ -62,26 +62,24 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	kind := obj.GetObjectKind().GroupVersionKind()
 | 
			
		||||
	if len(kind.Kind) == 0 {
 | 
			
		||||
	groupVersionKind := obj.GetObjectKind().GroupVersionKind()
 | 
			
		||||
	if len(groupVersionKind.Kind) > 0 {
 | 
			
		||||
		if mappings, err := p.Mapper.RESTMappings(groupVersionKind.GroupKind(), groupVersionKind.Version); err == nil && len(mappings) > 0 {
 | 
			
		||||
			fmt.Fprintf(w, "%s/%s\n", mappings[0].Resource, name)
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if gvks, _, err := p.Typer.ObjectKinds(obj); err == nil {
 | 
			
		||||
		for _, gvk := range gvks {
 | 
			
		||||
			if mappings, err := p.Mapper.RESTMappings(gvk.GroupKind(), gvk.Version); err == nil && len(mappings) > 0 {
 | 
			
		||||
				fmt.Fprintf(w, "%s/%s\n", mappings[0].Resource, name)
 | 
			
		||||
				return nil
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		} else {
 | 
			
		||||
			fmt.Fprintf(w, "<unknown>/%s\n", name)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	} else {
 | 
			
		||||
		if mappings, err := p.Mapper.RESTMappings(kind.GroupKind(), kind.Version); err == nil && len(mappings) > 0 {
 | 
			
		||||
			fmt.Fprintf(w, "%s/%s\n", mappings[0].Resource, name)
 | 
			
		||||
		} else {
 | 
			
		||||
			fmt.Fprintf(w, "<unknown>/%s\n", name)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	fmt.Fprintf(w, "<unknown>/%s\n", name)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user