mirror of https://github.com/k3s-io/k3s
stop using Info.Mappings when they may not be present
parent
625bce3ff6
commit
abe9e0d25b
|
@ -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"
|
||||||
|
@ -319,7 +320,11 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) 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)
|
||||||
|
|
|
@ -25,6 +25,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/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
@ -234,9 +235,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")
|
||||||
}
|
}
|
||||||
|
@ -576,31 +542,6 @@ func ParsePairs(pairArgs []string, pairType string, supportRemove bool) (newPair
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustPrintWithKinds determines if printer is dealing
|
|
||||||
// with multiple resource kinds, in which case it will
|
|
||||||
// return true, indicating resource kind will be
|
|
||||||
// included as part of printer output
|
|
||||||
func MustPrintWithKinds(objs []runtime.Object, infos []*resource.Info, sorter *kubectl.RuntimeSort) bool {
|
|
||||||
var lastMap *meta.RESTMapping
|
|
||||||
|
|
||||||
for ix := range objs {
|
|
||||||
var mapping *meta.RESTMapping
|
|
||||||
if sorter != nil {
|
|
||||||
mapping = infos[sorter.OriginalPosition(ix)].Mapping
|
|
||||||
} else {
|
|
||||||
mapping = infos[ix].Mapping
|
|
||||||
}
|
|
||||||
|
|
||||||
// display "kind" only if we have mixed resources
|
|
||||||
if lastMap != nil && mapping.Resource != lastMap.Resource {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
lastMap = mapping
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsSiblingCommandExists receives a pointer to a cobra command and a target string.
|
// IsSiblingCommandExists receives a pointer to a cobra command and a target string.
|
||||||
// Returns true if the target string is found in the list of sibling commands.
|
// Returns true if the target string is found in the list of sibling commands.
|
||||||
func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool {
|
func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool {
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue