Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --export flag from kubectl get command. #88649

Merged
merged 1 commit into from Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 1 addition & 11 deletions staging/src/k8s.io/cli-runtime/pkg/resource/builder.go
Expand Up @@ -100,8 +100,6 @@ type Builder struct {

singleItemImplied bool

export bool

schema ContentValidator

// fakeClientFn is used for testing
Expand Down Expand Up @@ -461,12 +459,6 @@ func (b *Builder) FieldSelectorParam(s string) *Builder {
return b
}

// ExportParam accepts the export boolean for these resources
func (b *Builder) ExportParam(export bool) *Builder {
b.export = export
return b
}

// NamespaceParam accepts the namespace that these resources should be
// considered under from - used by DefaultNamespace() and RequireNamespace()
func (b *Builder) NamespaceParam(namespace string) *Builder {
Expand Down Expand Up @@ -870,7 +862,7 @@ func (b *Builder) visitBySelector() *Result {
if mapping.Scope.Name() != meta.RESTScopeNameNamespace {
selectorNamespace = ""
}
visitors = append(visitors, NewSelector(client, mapping, selectorNamespace, labelSelector, fieldSelector, b.export, b.limitChunks))
visitors = append(visitors, NewSelector(client, mapping, selectorNamespace, labelSelector, fieldSelector, b.limitChunks))
}
if b.continueOnError {
result.visitor = EagerVisitorList(visitors)
Expand Down Expand Up @@ -970,7 +962,6 @@ func (b *Builder) visitByResource() *Result {
Mapping: mapping,
Namespace: selectorNamespace,
Name: tuple.Name,
Export: b.export,
}
items = append(items, info)
}
Expand Down Expand Up @@ -1035,7 +1026,6 @@ func (b *Builder) visitByName() *Result {
Mapping: mapping,
Namespace: selectorNamespace,
Name: name,
Export: b.export,
}
visitors = append(visitors, info)
}
Expand Down
13 changes: 2 additions & 11 deletions staging/src/k8s.io/cli-runtime/pkg/resource/helper.go
Expand Up @@ -18,7 +18,6 @@ package resource

import (
"context"
"strconv"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -75,27 +74,19 @@ func (m *Helper) WithFieldManager(fieldManager string) *Helper {
return m
}

func (m *Helper) Get(namespace, name string, export bool) (runtime.Object, error) {
func (m *Helper) Get(namespace, name string) (runtime.Object, error) {
req := m.RESTClient.Get().
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
Name(name)
if export {
// TODO: I should be part of GetOptions
req.Param("export", strconv.FormatBool(export))
}
return req.Do(context.TODO()).Get()
}

func (m *Helper) List(namespace, apiVersion string, export bool, options *metav1.ListOptions) (runtime.Object, error) {
func (m *Helper) List(namespace, apiVersion string, options *metav1.ListOptions) (runtime.Object, error) {
req := m.RESTClient.Get().
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
VersionedParams(options, metav1.ParameterCodec)
if export {
// TODO: I should be part of ListOptions
req.Param("export", strconv.FormatBool(export))
}
return req.Do(context.TODO()).Get()
}

Expand Down
5 changes: 2 additions & 3 deletions staging/src/k8s.io/cli-runtime/pkg/resource/helper_test.go
Expand Up @@ -312,7 +312,7 @@ func TestHelperGet(t *testing.T) {
RESTClient: client,
NamespaceScoped: true,
}
obj, err := modifier.Get("bar", "foo", false)
obj, err := modifier.Get("bar", "foo")

if (err != nil) != tt.Err {
t.Errorf("unexpected error: %d %t %v", i, tt.Err, err)
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestHelperList(t *testing.T) {
RESTClient: client,
NamespaceScoped: true,
}
obj, err := modifier.List("bar", corev1GV.String(), false, &metav1.ListOptions{LabelSelector: "foo=baz"})
obj, err := modifier.List("bar", corev1GV.String(), &metav1.ListOptions{LabelSelector: "foo=baz"})
if (err != nil) != tt.Err {
t.Errorf("unexpected error: %t %v", tt.Err, err)
}
Expand Down Expand Up @@ -464,7 +464,6 @@ func TestHelperListSelectorCombination(t *testing.T) {
t.Run(tt.Name, func(t *testing.T) {
_, err := modifier.List("bar",
corev1GV.String(),
false,
&metav1.ListOptions{LabelSelector: tt.LabelSelector, FieldSelector: tt.FieldSelector})
if tt.Err {
if err == nil {
Expand Down
5 changes: 1 addition & 4 deletions staging/src/k8s.io/cli-runtime/pkg/resource/selector.go
Expand Up @@ -32,19 +32,17 @@ type Selector struct {
Namespace string
LabelSelector string
FieldSelector string
Export bool
LimitChunks int64
}

// NewSelector creates a resource selector which hides details of getting items by their label selector.
func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace, labelSelector, fieldSelector string, export bool, limitChunks int64) *Selector {
func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace, labelSelector, fieldSelector string, limitChunks int64) *Selector {
return &Selector{
Client: client,
Mapping: mapping,
Namespace: namespace,
LabelSelector: labelSelector,
FieldSelector: fieldSelector,
Export: export,
LimitChunks: limitChunks,
}
}
Expand All @@ -56,7 +54,6 @@ func (r *Selector) Visit(fn VisitorFunc) error {
list, err := NewHelper(r.Client, r.Mapping).List(
r.Namespace,
r.ResourceMapping().GroupVersionKind.GroupVersion().String(),
r.Export,
&metav1.ListOptions{
LabelSelector: r.LabelSelector,
FieldSelector: r.FieldSelector,
Expand Down
4 changes: 1 addition & 3 deletions staging/src/k8s.io/cli-runtime/pkg/resource/visitor.go
Expand Up @@ -88,8 +88,6 @@ type Info struct {
// but if set it should be equal to or newer than the resource version of the
// object (however the server defines resource version).
ResourceVersion string
// Optional, should this resource be exported, stripped of cluster-specific and instance specific fields
Export bool
}

// Visit implements Visitor
Expand All @@ -99,7 +97,7 @@ func (i *Info) Visit(fn VisitorFunc) error {

// Get retrieves the object from the Namespace and Name fields
func (i *Info) Get() (err error) {
obj, err := NewHelper(i.Client, i.Mapping).Get(i.Namespace, i.Name, i.Export)
obj, err := NewHelper(i.Client, i.Mapping).Get(i.Namespace, i.Name)
if err != nil {
if errors.IsNotFound(err) && len(i.Namespace) > 0 && i.Namespace != metav1.NamespaceDefault && i.Namespace != metav1.NamespaceAll {
err2 := i.Client.Get().AbsPath("api", "v1", "namespaces", i.Namespace).Do(context.TODO()).Error()
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/kubectl/pkg/cmd/apply/patcher.go
Expand Up @@ -191,7 +191,7 @@ func (p *Patcher) Patch(current runtime.Object, modified []byte, source, namespa
if i > triesBeforeBackOff {
p.BackOff.Sleep(backOffPeriod)
}
current, getErr = p.Helper.Get(namespace, name, false)
current, getErr = p.Helper.Get(namespace, name)
if getErr != nil {
return nil, nil, getErr
}
Expand All @@ -209,7 +209,7 @@ func (p *Patcher) deleteAndCreate(original runtime.Object, modified []byte, name
}
// TODO: use wait
if err := wait.PollImmediate(1*time.Second, p.Timeout, func() (bool, error) {
if _, err := p.Helper.Get(namespace, name, false); !errors.IsNotFound(err) {
if _, err := p.Helper.Get(namespace, name); !errors.IsNotFound(err) {
return false, err
}
return true, nil
Expand Down
7 changes: 1 addition & 6 deletions staging/src/k8s.io/kubectl/pkg/cmd/get/get.go
Expand Up @@ -80,7 +80,6 @@ type GetOptions struct {
NoHeaders bool
Sort bool
IgnoreNotFound bool
Export bool

genericclioptions.IOStreams
}
Expand Down Expand Up @@ -183,8 +182,6 @@ func NewCmdGet(parent string, f cmdutil.Factory, streams genericclioptions.IOStr
cmd.Flags().BoolVarP(&o.AllNamespaces, "all-namespaces", "A", o.AllNamespaces, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
addOpenAPIPrintColumnFlags(cmd, o)
addServerPrintColumnFlags(cmd, o)
cmd.Flags().BoolVar(&o.Export, "export", o.Export, "If true, use 'export' for the resources. Exported resources are stripped of cluster-specific information.")
cmd.Flags().MarkDeprecated("export", "This flag is deprecated and will be removed in future.")
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, "identifying the resource to get from a server.")
return cmd
}
Expand Down Expand Up @@ -301,7 +298,7 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
// Validate checks the set of flags provided by the user.
func (o *GetOptions) Validate(cmd *cobra.Command) error {
if len(o.Raw) > 0 {
if o.Watch || o.WatchOnly || len(o.LabelSelector) > 0 || o.Export {
if o.Watch || o.WatchOnly || len(o.LabelSelector) > 0 {
return fmt.Errorf("--raw may not be specified with other flags that filter the server request or alter the output")
}
if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
Expand Down Expand Up @@ -473,7 +470,6 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
FilenameParam(o.ExplicitNamespace, &o.FilenameOptions).
LabelSelectorParam(o.LabelSelector).
FieldSelectorParam(o.FieldSelector).
ExportParam(o.Export).
RequestChunksOf(chunkSize).
ResourceTypeOrNameArgs(true, args...).
ContinueOnError().
Expand Down Expand Up @@ -632,7 +628,6 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string)
FilenameParam(o.ExplicitNamespace, &o.FilenameOptions).
LabelSelectorParam(o.LabelSelector).
FieldSelectorParam(o.FieldSelector).
ExportParam(o.Export).
RequestChunksOf(o.ChunkSize).
ResourceTypeOrNameArgs(true, args...).
SingleResourceType().
Expand Down
2 changes: 0 additions & 2 deletions test/cmd/core.sh
Expand Up @@ -105,8 +105,6 @@ run_pod_tests() {
kube::test::describe_resource_events_assert pods false
# Describe command should print events information when show-events=true
kube::test::describe_resource_events_assert pods true
### Validate Export ###
kube::test::get_object_assert 'pods/valid-pod' "{{.metadata.namespace}} {{.metadata.name}}" '<no value> valid-pod' "--export=true"

### Dump current valid-pod POD
output_pod=$(kubectl get pod valid-pod -o yaml "${kube_flags[@]}")
Expand Down