Skip to content

UPSTREAM: 48763: Add Local and Unstructured resource builder attributes and handle <rsrsc> / <name> pairs when --local is set #15140

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/oc/admin/migrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (o *ResourceOptions) Complete(f *clientcmd.Factory, c *cobra.Command) error
break
}

o.Builder = f.NewBuilder(true).
o.Builder = f.NewBuilder().
AllNamespaces(allNamespaces).
FilenameParam(false, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
ContinueOnError().
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/admin/network/project_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (p *ProjectOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args [
return err
}

p.Builder = f.NewBuilder(true)
p.Builder = f.NewBuilder()
p.DefaultNamespace = defaultNamespace
p.Oclient = networkClient
p.Kclient = kc
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/admin/node/node_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (n *NodeOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args []st
}
mapper, typer := f.Object()

n.Builder = f.NewBuilder(true)
n.Builder = f.NewBuilder()
n.DefaultNamespace = defaultNamespace
n.ExternalKubeClient = externalkc
n.KubeClient = kc
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/admin/policy/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (o *sccReviewOptions) Complete(f *clientcmd.Factory, args []string, cmd *co
return fmt.Errorf("unable to obtain client: %v", err)
}
o.client = securityClient.Security()
o.builder = f.NewBuilder(true)
o.builder = f.NewBuilder()
o.RESTClientFactory = f.ClientForMapping

output := kcmdutil.GetFlagString(cmd, "output")
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/admin/policy/subject_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (o *sccSubjectReviewOptions) Complete(f *clientcmd.Factory, args []string,
}
o.sccSubjectReviewClient = securityClient.Security()
o.sccSelfSubjectReviewClient = securityClient.Security()
o.builder = f.NewBuilder(true)
o.builder = f.NewBuilder()
o.RESTClientFactory = f.ClientForMapping

output := kcmdutil.GetFlagString(cmd, "output")
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/bootstrap/docker/openshift/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ImportObjects(f *clientcmd.Factory, ns, location string) error {
return err
}
glog.V(8).Infof("Importing data:\n%s\n", string(data))
r := f.NewBuilder(true).
r := f.NewBuilder().
Schema(schema).
ContinueOnError().
NamespaceParam(ns).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (o *DebugOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args [
}

mapper, _ := f.Object()
b := f.NewBuilder(true).
b := f.NewBuilder().
NamespaceParam(cmdNamespace).DefaultNamespace().
SingleResourceType().
ResourceNames("pods", resources...).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (o *DeployOptions) Complete(f *clientcmd.Factory, args []string, out io.Wri
return err
}

o.builder = f.NewBuilder(true)
o.builder = f.NewBuilder()
o.out = out

if len(args) > 0 {
Expand Down
8 changes: 2 additions & 6 deletions pkg/oc/cli/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,13 @@ func RunExport(f *clientcmd.Factory, exporter Exporter, in io.Reader, out io.Wri
return err
}

builder, err := f.NewUnstructuredBuilder(true)
if err != nil {
return err
}

mapper, typer, err := f.UnstructuredObject()
if err != nil {
return err
}

b := builder.
b := f.NewBuilder().
Unstructured(f.UnstructuredClientForMapping, mapper, typer).
NamespaceParam(cmdNamespace).DefaultNamespace().AllNamespaces(allNamespaces).
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: filenames}).
SelectorParam(selector).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func validate(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
return err
}

r := f.NewBuilder(true).
r := f.NewBuilder().
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().
FilenameParam(enforceNamespace, &resource.FilenameOptions{Recursive: false, Filenames: kcmdutil.GetFlagStringSlice(cmd, "filename")}).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (o *ExtractOptions) Complete(f *clientcmd.Factory, in io.Reader, out io.Wri
return err
}

b := f.NewBuilder(true).
b := f.NewBuilder().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
ResourceNames("", args...).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (o *IdleOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []
return fmt.Errorf("resource names, selectors, and the all flag may not be be specified if a filename is specified")
}

o.svcBuilder = f.NewBuilder(true).
o.svcBuilder = f.NewBuilder().
ContinueOnError().
NamespaceParam(namespace).DefaultNamespace().AllNamespaces(o.allNamespaces).
Flatten().
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (o *OpenShiftLogsOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command

podLogOptions := o.KubeLogOptions.Options.(*kapi.PodLogOptions)

infos, err := f.NewBuilder(true).
infos, err := f.NewBuilder().
NamespaceParam(o.Namespace).DefaultNamespace().
ResourceNames("pods", args...).
SingleResourceType().RequireObject(false).
Expand Down
10 changes: 8 additions & 2 deletions pkg/oc/cli/cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,14 @@ func RunProcess(f *clientcmd.Factory, in io.Reader, out, errout io.Writer, cmd *
templateObj.CreationTimestamp = metav1.Now()
infos = append(infos, &resource.Info{Object: templateObj})
} else {
infos, err = f.NewBuilder(!local).
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: []string{filename}}).
b := f.NewBuilder().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: []string{filename}})

if local {
b = b.Local(f.ClientForMapping)
}

infos, err = b.
Do().
Infos()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (o *RollbackOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, arg

// Set up client based support.
o.getBuilder = func() *resource.Builder {
return f.NewBuilder(true)
return f.NewBuilder()
}

kClient, err := f.ClientSet()
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/rollout/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (o *CancelOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, out i
return err
}

r := f.NewBuilder(true).
r := f.NewBuilder().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, &o.FilenameOptions).
ResourceTypeOrNameArgs(true, args...).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/rollout/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (o *RolloutLatestOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command
o.appsClient = appsClient.Apps()

o.mapper, o.typer = f.Object()
o.infos, err = f.NewBuilder(true).
o.infos, err = f.NewBuilder().
ContinueOnError().
NamespaceParam(namespace).
ResourceNames("deploymentconfigs", args[0]).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/rollout/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (o *RetryOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, out io
return err
}

r := f.NewBuilder(true).
r := f.NewBuilder().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, &o.FilenameOptions).
ResourceTypeOrNameArgs(true, args...).
Expand Down
2 changes: 1 addition & 1 deletion pkg/oc/cli/cmd/rsync/pathspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func resolveResourceKindPath(f kcmdutil.Factory, path, namespace string) (string
podName = podSegs[1]
}

r := f.NewBuilder(true).
r := f.NewBuilder().
NamespaceParam(namespace).
SingleResourceType().
ResourceNames("pods", podName).
Expand Down
11 changes: 10 additions & 1 deletion pkg/oc/cli/cmd/set/buildhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (o *BuildHookOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, ar
o.Cmd = cmd

mapper, _ := f.Object()
o.Builder = f.NewBuilder(!o.Local).
o.Builder = f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -152,6 +152,15 @@ func (o *BuildHookOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, ar
if o.All {
o.Builder.ResourceTypes("buildconfigs").SelectAllParam(o.All)
}
} else {
// if a --local flag was provided, and a resource was specified in the form
// <resource>/<name>, fail immediately as --local cannot query the api server
// for the specified resource.
if len(resources) > 0 {
return resource.LocalResourceError
}

o.Builder = o.Builder.Local(f.ClientForMapping)
}

o.Output = kcmdutil.GetFlagString(cmd, "output")
Expand Down
13 changes: 11 additions & 2 deletions pkg/oc/cli/cmd/set/buildsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewCmdBuildSecret(fullName string, f *clientcmd.Factory, out, errOut io.Wri
var supportedBuildTypes = []string{"buildconfigs"}

func (o *BuildSecretOptions) secretFromArg(f *clientcmd.Factory, mapper meta.RESTMapper, typer runtime.ObjectTyper, namespace, arg string) (string, error) {
builder := f.NewBuilder(!o.Local).
builder := f.NewBuilder().
NamespaceParam(namespace).DefaultNamespace().
RequireObject(false).
ContinueOnError().
Expand Down Expand Up @@ -173,7 +173,7 @@ func (o *BuildSecretOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
return err
}
}
o.Builder = f.NewBuilder(!o.Local).
o.Builder = f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -188,6 +188,15 @@ func (o *BuildSecretOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
if o.All {
o.Builder.ResourceTypes(supportedBuildTypes...).SelectAllParam(o.All)
}
} else {
// if a --local flag was provided, and a resource was specified in the form
// <resource>/<name>, fail immediately as --local cannot query the api server
// for the specified resource.
if len(resources) > 0 {
return resource.LocalResourceError
}

o.Builder = o.Builder.Local(f.ClientForMapping)
}

o.Output = kcmdutil.GetFlagString(cmd, "output")
Expand Down
11 changes: 10 additions & 1 deletion pkg/oc/cli/cmd/set/deploymenthook.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (o *DeploymentHookOptions) Complete(f *clientcmd.Factory, cmd *cobra.Comman
o.Cmd = cmd

mapper, _ := f.Object()
o.Builder = f.NewBuilder(!o.Local).
o.Builder = f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -170,6 +170,15 @@ func (o *DeploymentHookOptions) Complete(f *clientcmd.Factory, cmd *cobra.Comman
o.Builder.ResourceTypes("deploymentconfigs").SelectAllParam(o.All)
}

} else {
// if a --local flag was provided, and a resource was specified in the form
// <resource>/<name>, fail immediately as --local cannot query the api server
// for the specified resource.
if len(resources) > 0 {
return resource.LocalResourceError
}

o.Builder = o.Builder.Local(f.ClientForMapping)
}

o.Output = kcmdutil.GetFlagString(cmd, "output")
Expand Down
15 changes: 13 additions & 2 deletions pkg/oc/cli/cmd/set/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (o *EnvOptions) RunEnv(f *clientcmd.Factory) error {
}

if len(o.From) != 0 {
b := f.NewBuilder(!o.Local).
b := f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -235,6 +235,8 @@ func (o *EnvOptions) RunEnv(f *clientcmd.Factory) error {
b = b.
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, o.From)
} else {
b = b.Local(f.ClientForMapping)
}

one := false
Expand Down Expand Up @@ -287,7 +289,7 @@ func (o *EnvOptions) RunEnv(f *clientcmd.Factory) error {
}
}

b := f.NewBuilder(!o.Local).
b := f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -297,6 +299,15 @@ func (o *EnvOptions) RunEnv(f *clientcmd.Factory) error {
b = b.
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, o.Resources...)
} else {
// if a --local flag was provided, and a resource was specified in the form
// <resource>/<name>, fail immediately as --local cannot query the api server
// for the specified resource.
if len(o.Resources) > 0 {
return resource.LocalResourceError
}

b = b.Local(f.ClientForMapping)
}

one := false
Expand Down
4 changes: 2 additions & 2 deletions pkg/oc/cli/cmd/set/imagelookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (o *ImageLookupOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
o.PrintTable = (len(args) == 0 && !o.All) || o.List

mapper, _ := f.Object()
o.Builder = f.NewBuilder(!o.Local).
o.Builder = f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -175,7 +175,7 @@ func (o *ImageLookupOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command,
return kcmdutil.UsageErrorf(cmd, "Pass files with -f when using --local")
case o.Local:
// perform no lookups on the server
// TODO: discovery still requires a running server, doesn't fall back correctly
o.Builder = o.Builder.Local(f.ClientForMapping)
case len(args) == 0 && len(o.Filenames) == 0:
o.Builder = o.Builder.
SelectorParam(o.Selector).
Expand Down
11 changes: 10 additions & 1 deletion pkg/oc/cli/cmd/set/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (o *ProbeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args [
o.Cmd = cmd

mapper, _ := f.Object()
o.Builder = f.NewBuilder(!o.Local).
o.Builder = f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -191,6 +191,15 @@ func (o *ProbeOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args [
o.Builder = o.Builder.
SelectorParam(o.Selector).
ResourceTypeOrNameArgs(o.All, resources...)
} else {
// if a --local flag was provided, and a resource was specified in the form
// <resource>/<name>, fail immediately as --local cannot query the api server
// for the specified resource.
if len(resources) > 0 {
return resource.LocalResourceError
}

o.Builder = o.Builder.Local(f.ClientForMapping)
}

o.Output = kcmdutil.GetFlagString(cmd, "output")
Expand Down
11 changes: 10 additions & 1 deletion pkg/oc/cli/cmd/set/routebackends.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (o *BackendsOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, arg
o.Cmd = cmd

mapper, _ := f.Object()
o.Builder = f.NewBuilder(!o.Local).
o.Builder = f.NewBuilder().
ContinueOnError().
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(explicit, &resource.FilenameOptions{Recursive: false, Filenames: o.Filenames}).
Expand All @@ -175,6 +175,15 @@ func (o *BackendsOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, arg
if len(resources) == 0 {
o.Builder.ResourceTypes("routes")
}
} else {
// if a --local flag was provided, and a resource was specified in the form
// <resource>/<name>, fail immediately as --local cannot query the api server
// for the specified resource.
if len(resources) > 0 {
return resource.LocalResourceError
}

o.Builder = o.Builder.Local(f.ClientForMapping)
}

o.Output = kcmdutil.GetFlagString(cmd, "output")
Expand Down
Loading