Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
2
vendor/k8s.io/cli-runtime/pkg/printers/interface.go
generated
vendored
2
vendor/k8s.io/cli-runtime/pkg/printers/interface.go
generated
vendored
@@ -33,7 +33,7 @@ func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
|
||||
|
||||
// ResourcePrinter is an interface that knows how to print runtime objects.
|
||||
type ResourcePrinter interface {
|
||||
// Print receives a runtime object, formats it and prints it to a writer.
|
||||
// PrintObj receives a runtime object, formats it and prints it to a writer.
|
||||
PrintObj(runtime.Object, io.Writer) error
|
||||
}
|
||||
|
||||
|
||||
63
vendor/k8s.io/cli-runtime/pkg/printers/json.go
generated
vendored
63
vendor/k8s.io/cli-runtime/pkg/printers/json.go
generated
vendored
@@ -22,12 +22,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
|
||||
@@ -80,63 +77,3 @@ func (p *JSONPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
||||
_, err = w.Write(data)
|
||||
return err
|
||||
}
|
||||
|
||||
// YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML.
|
||||
// The input object is assumed to be in the internal version of an API and is converted
|
||||
// to the given version first.
|
||||
// If PrintObj() is called multiple times, objects are separated with a '---' separator.
|
||||
type YAMLPrinter struct {
|
||||
printCount int64
|
||||
}
|
||||
|
||||
// PrintObj prints the data as YAML.
|
||||
func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
||||
// we use reflect.Indirect here in order to obtain the actual value from a pointer.
|
||||
// we need an actual value in order to retrieve the package path for an object.
|
||||
// using reflect.Indirect indiscriminately is valid here, as all runtime.Objects are supposed to be pointers.
|
||||
if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) {
|
||||
return fmt.Errorf(InternalObjectPrinterErr)
|
||||
}
|
||||
|
||||
count := atomic.AddInt64(&p.printCount, 1)
|
||||
if count > 1 {
|
||||
if _, err := w.Write([]byte("---\n")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
switch obj := obj.(type) {
|
||||
case *metav1.WatchEvent:
|
||||
if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj.Object.Object)).Type().PkgPath()) {
|
||||
return fmt.Errorf(InternalObjectPrinterErr)
|
||||
}
|
||||
data, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err = yaml.JSONToYAML(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(data)
|
||||
return err
|
||||
case *runtime.Unknown:
|
||||
data, err := yaml.JSONToYAML(obj.Raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(data)
|
||||
return err
|
||||
}
|
||||
|
||||
if obj.GetObjectKind().GroupVersionKind().Empty() {
|
||||
return fmt.Errorf("missing apiVersion or kind; try GetObjectKind().SetGroupVersionKind() if you know the type")
|
||||
}
|
||||
|
||||
output, err := yaml.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprint(w, string(output))
|
||||
return err
|
||||
}
|
||||
|
||||
2
vendor/k8s.io/cli-runtime/pkg/printers/jsonpath.go
generated
vendored
2
vendor/k8s.io/cli-runtime/pkg/printers/jsonpath.go
generated
vendored
@@ -85,7 +85,7 @@ func exists(item interface{}, indices ...interface{}) bool {
|
||||
// We indirect through pointers and empty interfaces (only) because
|
||||
// non-empty interfaces have methods we might need.
|
||||
func indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
|
||||
for ; v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface; v = v.Elem() {
|
||||
for ; v.Kind() == reflect.Pointer || v.Kind() == reflect.Interface; v = v.Elem() {
|
||||
if v.IsNil() {
|
||||
return v, true
|
||||
}
|
||||
|
||||
22
vendor/k8s.io/cli-runtime/pkg/printers/tableprinter.go
generated
vendored
22
vendor/k8s.io/cli-runtime/pkg/printers/tableprinter.go
generated
vendored
@@ -208,7 +208,23 @@ func printTable(table *metav1.Table, output io.Writer, options PrintOptions) err
|
||||
fmt.Fprint(output, "\t")
|
||||
}
|
||||
if cell != nil {
|
||||
fmt.Fprint(output, cell)
|
||||
switch val := cell.(type) {
|
||||
case string:
|
||||
print := val
|
||||
truncated := false
|
||||
// truncate at newlines
|
||||
newline := strings.Index(print, "\n")
|
||||
if newline >= 0 {
|
||||
truncated = true
|
||||
print = print[:newline]
|
||||
}
|
||||
fmt.Fprint(output, print)
|
||||
if truncated {
|
||||
fmt.Fprint(output, "...")
|
||||
}
|
||||
default:
|
||||
fmt.Fprint(output, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(output)
|
||||
@@ -433,7 +449,7 @@ func formatEventType(eventType string) string {
|
||||
if formatted, ok := formattedEventType[eventType]; ok {
|
||||
return formatted
|
||||
}
|
||||
return string(eventType)
|
||||
return eventType
|
||||
}
|
||||
|
||||
// printRows writes the provided rows to output.
|
||||
@@ -483,7 +499,7 @@ func formatLabelHeaders(columnLabels []string) []string {
|
||||
formHead := make([]string, len(columnLabels))
|
||||
for i, l := range columnLabels {
|
||||
p := strings.Split(l, "/")
|
||||
formHead[i] = strings.ToUpper((p[len(p)-1]))
|
||||
formHead[i] = strings.ToUpper(p[len(p)-1])
|
||||
}
|
||||
return formHead
|
||||
}
|
||||
|
||||
55
vendor/k8s.io/cli-runtime/pkg/printers/warningprinter.go
generated
vendored
Normal file
55
vendor/k8s.io/cli-runtime/pkg/printers/warningprinter.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package printers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
yellowColor = "\u001b[33;1m"
|
||||
resetColor = "\u001b[0m"
|
||||
)
|
||||
|
||||
type WarningPrinter struct {
|
||||
// out is the writer to output warnings to
|
||||
out io.Writer
|
||||
// opts contains options controlling warning output
|
||||
opts WarningPrinterOptions
|
||||
}
|
||||
|
||||
// WarningPrinterOptions controls the behavior of a WarningPrinter constructed using NewWarningPrinter()
|
||||
type WarningPrinterOptions struct {
|
||||
// Color indicates that warning output can include ANSI color codes
|
||||
Color bool
|
||||
}
|
||||
|
||||
// NewWarningPrinter returns an implementation of warningPrinter that outputs warnings to the specified writer.
|
||||
func NewWarningPrinter(out io.Writer, opts WarningPrinterOptions) *WarningPrinter {
|
||||
h := &WarningPrinter{out: out, opts: opts}
|
||||
return h
|
||||
}
|
||||
|
||||
// Print prints warnings to the configured writer.
|
||||
func (w *WarningPrinter) Print(message string) {
|
||||
if w.opts.Color {
|
||||
fmt.Fprintf(w.out, "%sWarning:%s %s\n", yellowColor, resetColor, message)
|
||||
} else {
|
||||
fmt.Fprintf(w.out, "Warning: %s\n", message)
|
||||
}
|
||||
}
|
||||
85
vendor/k8s.io/cli-runtime/pkg/printers/yaml.go
generated
vendored
Normal file
85
vendor/k8s.io/cli-runtime/pkg/printers/yaml.go
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package printers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML.
|
||||
// The input object is assumed to be in the internal version of an API and is converted
|
||||
// to the given version first.
|
||||
// If PrintObj() is called multiple times, objects are separated with a '---' separator.
|
||||
type YAMLPrinter struct {
|
||||
printCount int64
|
||||
}
|
||||
|
||||
// PrintObj prints the data as YAML.
|
||||
func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
||||
// we use reflect.Indirect here in order to obtain the actual value from a pointer.
|
||||
// we need an actual value in order to retrieve the package path for an object.
|
||||
// using reflect.Indirect indiscriminately is valid here, as all runtime.Objects are supposed to be pointers.
|
||||
if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj)).Type().PkgPath()) {
|
||||
return fmt.Errorf(InternalObjectPrinterErr)
|
||||
}
|
||||
|
||||
count := atomic.AddInt64(&p.printCount, 1)
|
||||
if count > 1 {
|
||||
if _, err := w.Write([]byte("---\n")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
switch obj := obj.(type) {
|
||||
case *metav1.WatchEvent:
|
||||
if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj.Object.Object)).Type().PkgPath()) {
|
||||
return fmt.Errorf(InternalObjectPrinterErr)
|
||||
}
|
||||
data, err := yaml.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(data)
|
||||
return err
|
||||
case *runtime.Unknown:
|
||||
data, err := yaml.JSONToYAML(obj.Raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(data)
|
||||
return err
|
||||
}
|
||||
|
||||
if obj.GetObjectKind().GroupVersionKind().Empty() {
|
||||
return fmt.Errorf("missing apiVersion or kind; try GetObjectKind().SetGroupVersionKind() if you know the type")
|
||||
}
|
||||
|
||||
output, err := yaml.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprint(w, string(output))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user