mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #63258 from deads2k/cli-42-simplify-buidler
Automatic merge from submit-queue (batch tested with PRs 63258, 63398, 63403). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. stop using Info.Mappings when they may not be present On a resource builder, you cannot logically have a RESTMapping or a Client if you're running a local action. Reliance on the `info.Client` and `info.Mapping` is a bug we need to fix. This updates the docs and eliminates unnecessary reliance. Other hits I found didn't have `--local` options, so we're safe or had them and and were already broken. I think we'll be able to help them after making our creation flow obvious. @kubernetes/sig-cli-maintainers ```release-note NONE ```
This commit is contained in:
		@@ -108,6 +108,7 @@ go_library(
 | 
				
			|||||||
        "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
 | 
				
			||||||
 | 
					        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,7 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/util/json"
 | 
						"k8s.io/apimachinery/pkg/util/json"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/validation"
 | 
						"k8s.io/apimachinery/pkg/util/validation"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubectl"
 | 
						"k8s.io/kubernetes/pkg/kubectl"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
 | 
						"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
 | 
				
			||||||
	cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
 | 
						cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
 | 
				
			||||||
@@ -329,7 +330,11 @@ func (o *LabelOptions) RunLabel() error {
 | 
				
			|||||||
			indent := ""
 | 
								indent := ""
 | 
				
			||||||
			if !one {
 | 
								if !one {
 | 
				
			||||||
				indent = " "
 | 
									indent = " "
 | 
				
			||||||
				fmt.Fprintf(o.ErrOut, "Listing labels for %s.%s/%s:\n", info.Mapping.GroupVersionKind.Kind, info.Mapping.GroupVersionKind.Group, info.Name)
 | 
									gvks, _, err := unstructuredscheme.NewUnstructuredObjectTyper().ObjectKinds(info.Object)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										return err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									fmt.Fprintf(o.ErrOut, "Listing labels for %s.%s/%s:\n", gvks[0].Kind, gvks[0].Group, info.Name)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			for k, v := range accessor.GetLabels() {
 | 
								for k, v := range accessor.GetLabels() {
 | 
				
			||||||
				fmt.Fprintf(o.Out, "%s%s=%s\n", indent, k, v)
 | 
									fmt.Fprintf(o.Out, "%s%s=%s\n", indent, k, v)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/api/core/v1"
 | 
						"k8s.io/api/core/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/api/meta"
 | 
						"k8s.io/apimachinery/pkg/api/meta"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
						"k8s.io/apimachinery/pkg/runtime"
 | 
				
			||||||
@@ -253,9 +254,10 @@ func (o TaintOptions) RunTaint() error {
 | 
				
			|||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		obj, err := legacyscheme.Scheme.ConvertToVersion(info.Object, info.Mapping.GroupVersionKind.GroupVersion())
 | 
							obj, err := legacyscheme.Scheme.ConvertToVersion(info.Object, v1.SchemeGroupVersion)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								glog.V(1).Info(err)
 | 
				
			||||||
 | 
								return fmt.Errorf("object was not a node.v1.: %T", info.Object)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		name, namespace := info.Name, info.Namespace
 | 
							name, namespace := info.Name, info.Namespace
 | 
				
			||||||
		oldData, err := json.Marshal(obj)
 | 
							oldData, err := json.Marshal(obj)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,6 @@ import (
 | 
				
			|||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"io/ioutil"
 | 
					 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -435,19 +434,6 @@ type ValidateOptions struct {
 | 
				
			|||||||
	EnableValidation bool
 | 
						EnableValidation bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ReadConfigDataFromReader(reader io.Reader, source string) ([]byte, error) {
 | 
					 | 
				
			||||||
	data, err := ioutil.ReadAll(reader)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(data) == 0 {
 | 
					 | 
				
			||||||
		return nil, fmt.Errorf("Read from %s but no data found", source)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return data, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Merge requires JSON serialization
 | 
					// Merge requires JSON serialization
 | 
				
			||||||
// TODO: merge assumes JSON serialization, and does not properly abstract API retrieval
 | 
					// TODO: merge assumes JSON serialization, and does not properly abstract API retrieval
 | 
				
			||||||
func Merge(codec runtime.Codec, dst runtime.Object, fragment string) (runtime.Object, error) {
 | 
					func Merge(codec runtime.Codec, dst runtime.Object, fragment string) (runtime.Object, error) {
 | 
				
			||||||
@@ -493,26 +479,6 @@ func DumpReaderToFile(reader io.Reader, filename string) error {
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateObject updates resource object with updateFn
 | 
					 | 
				
			||||||
func UpdateObject(info *resource.Info, codec runtime.Codec, updateFn func(runtime.Object) error) (runtime.Object, error) {
 | 
					 | 
				
			||||||
	helper := resource.NewHelper(info.Client, info.Mapping)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err := updateFn(info.Object); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Update the annotation used by kubectl apply
 | 
					 | 
				
			||||||
	if err := kubectl.UpdateApplyAnnotation(info.Object, codec); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if _, err := helper.Replace(info.Namespace, info.Name, true, info.Object); err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return info.Object, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func GetDryRunFlag(cmd *cobra.Command) bool {
 | 
					func GetDryRunFlag(cmd *cobra.Command) bool {
 | 
				
			||||||
	return GetFlagBool(cmd, "dry-run")
 | 
						return GetFlagBool(cmd, "dry-run")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,9 +73,9 @@ type ResourceMapping interface {
 | 
				
			|||||||
// Info contains temporary info to execute a REST call, or show the results
 | 
					// Info contains temporary info to execute a REST call, or show the results
 | 
				
			||||||
// of an already completed REST call.
 | 
					// of an already completed REST call.
 | 
				
			||||||
type Info struct {
 | 
					type Info struct {
 | 
				
			||||||
 | 
						// Client will only be present if this builder was not local
 | 
				
			||||||
	Client RESTClient
 | 
						Client RESTClient
 | 
				
			||||||
	// Mapping may be nil if the object has no available metadata, but is still parseable
 | 
						// Mapping will only be present if this builder was not local
 | 
				
			||||||
	// from disk.
 | 
					 | 
				
			||||||
	Mapping *meta.RESTMapping
 | 
						Mapping *meta.RESTMapping
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Namespace will be set if the object is namespaced and has a specified value.
 | 
						// Namespace will be set if the object is namespaced and has a specified value.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user