Skip to content

Commit 00db30d

Browse files
Merge pull request #20139 from soltysh/the_new_oc
Update set commands
2 parents cc0ecf6 + 02b6c04 commit 00db30d

37 files changed

+1563
-2113
lines changed

contrib/completions/bash/oc

Lines changed: 47 additions & 329 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

Lines changed: 47 additions & 329 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/cli.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,35 +449,35 @@ For example, to edit the service `docker-registry` in JSON using the `v1` API fo
449449
$ oc edit svc/docker-registry --output-version=v1 -o json
450450
```
451451

452-
### oc env
452+
### oc set env
453453

454454
This updates the environment on a resource with a pod template.
455455
The general form is:
456456

457457
```bash
458-
$ oc env <resource-type>/<name> <k1>=<v1> <k2>=<v2>
458+
$ oc set env <resource-type>/<name> <k1>=<v1> <k2>=<v2>
459459
```
460460

461461
For example:
462462

463463
```bash
464-
$ oc env dc/app DB_USER=user DB_PASS=pass
464+
$ oc set env dc/app DB_USER=user DB_PASS=pass
465465
```
466466

467-
### oc volume
467+
### oc set volume
468468

469469
This controls the storage associated with various resources.
470470
The general form is:
471471

472472
```bash
473-
$ oc volume <resource-type>/<name> --<action> <options>
473+
$ oc set volume <resource-type>/<name> --<action> <options>
474474
```
475475

476476
where *action* is one of `add`, `remove`, `list` and *options* depends on *action*.
477477
For example, to arrange for the deployment configuration `registry` to access the host *_/opt_* directory, use:
478478

479479
```bash
480-
$ oc volume dc/registry --add --mount-path=/opt
480+
$ oc set volume dc/registry --add --mount-path=/opt
481481
```
482482

483483
### oc label

docs/man/man1/.files_generated_oc

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/man/man1/oc-env.1

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/man/man1/oc-volumes.1

Lines changed: 0 additions & 3 deletions
This file was deleted.

hack/lib/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ function os::start::registry() {
631631
# For testing purposes, ensure the quota objects are always up to date in the registry by
632632
# disabling project cache.
633633
oc adm registry --config="${ADMIN_KUBECONFIG}" --images="${USE_IMAGES}" --enforce-quota -o json | \
634-
oc env --config="${ADMIN_KUBECONFIG}" -f - --output json "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_PROJECTCACHETTL=0" | \
634+
oc set env --config="${ADMIN_KUBECONFIG}" --local -f - --output json "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_PROJECTCACHETTL=0" | \
635635
oc create --config="${ADMIN_KUBECONFIG}" -f -
636636
}
637637
readonly -f os::start::registry

pkg/oc/admin/router/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func NewCmdRouter(f kcmdutil.Factory, parentName, name string, out, errout io.Wr
279279
cmd.Flags().StringVar(&cfg.ForceSubdomain, "force-subdomain", "", "A router path format to force on all routes used by this router (will ignore the route host value)")
280280
cmd.Flags().StringVar(&cfg.ImageTemplate.Format, "images", cfg.ImageTemplate.Format, "The image to base this router on - ${component} will be replaced with --type")
281281
cmd.Flags().BoolVar(&cfg.ImageTemplate.Latest, "latest-images", cfg.ImageTemplate.Latest, "If true, attempt to use the latest images for the router instead of the latest release.")
282-
cmd.Flags().StringVar(&cfg.Ports, "ports", cfg.Ports, "A comma delimited list of ports or port pairs that set the port in the router pod containerPort and hostPort. It also sets service port and targetPort to expose on the router pod. This does not modify the env variables. That can be done using oc env or by editing the router's dc. This is used when host-network=false.")
282+
cmd.Flags().StringVar(&cfg.Ports, "ports", cfg.Ports, "A comma delimited list of ports or port pairs that set the port in the router pod containerPort and hostPort. It also sets service port and targetPort to expose on the router pod. This does not modify the env variables. That can be done using oc set env or by editing the router's dc. This is used when host-network=false.")
283283
cmd.Flags().StringVar(&cfg.RouterCanonicalHostname, "router-canonical-hostname", cfg.RouterCanonicalHostname, "CanonicalHostname is the external host name for the router that can be used as a CNAME for the host requested for this route. This value is optional and may not be set in all cases.")
284284
cmd.Flags().Int32Var(&cfg.Replicas, "replicas", cfg.Replicas, "The replication factor of the router; commonly 2 when high availability is desired.")
285285
cmd.Flags().StringVar(&cfg.Labels, "labels", cfg.Labels, "A set of labels to uniquely identify the router and its components.")

pkg/oc/cli/cli.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
211211
"options",
212212
"deploy",
213213
// These commands are deprecated and should not appear in help
214-
moved(fullName, "set env", cmds, set.NewCmdEnv(fullName, f, ioStreams)),
215-
moved(fullName, "set volume", cmds, set.NewCmdVolume(fullName, f, ioStreams)),
216214
moved(fullName, "logs", cmds, cmd.NewCmdBuildLogs(fullName, f, ioStreams)),
217215
moved(fullName, "secrets link", secretcmds, secrets.NewCmdLinkSecret("add", fullName, f, ioStreams)),
218216
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateSecret(secrets.NewSecretRecommendedCommandName, fullName, f, ioStreams)),

pkg/oc/cli/cmd/example.go

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package cmd
22

33
import (
44
"fmt"
5-
"io"
6-
"os"
75

86
"github.com/spf13/cobra"
97

108
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
119
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
10+
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
11+
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
12+
13+
"github.com/openshift/origin/pkg/oc/util/ocscheme"
1214
)
1315

1416
var (
@@ -21,39 +23,56 @@ var (
2123
)
2224

2325
type TYPEOptions struct {
24-
In io.Reader
25-
Out, ErrOut io.Writer
26+
PrintFlags *genericclioptions.PrintFlags
27+
28+
Printer printers.ResourcePrinter
29+
DryRun bool
30+
31+
genericclioptions.IOStreams
2632
}
2733

28-
// NewCmdTYPE implements a TYPE command
34+
// NewTYPEOptions returns a TYPEOptions with proper defaults.
2935
// This is an example type for templating.
30-
func NewCmdTYPE(fullName string, f kcmdutil.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
31-
options := &TYPEOptions{
32-
In: in,
33-
Out: out,
34-
ErrOut: errout,
36+
func NewTYPEOptions(streams genericclioptions.IOStreams) *TYPEOptions {
37+
return &TYPEOptions{
38+
PrintFlags: genericclioptions.NewPrintFlags("action performed").WithTypeSetter(ocscheme.PrintingInternalScheme),
39+
IOStreams: streams,
3540
}
41+
}
42+
43+
// NewCmdTYPE implements a TYPE command
44+
// This is an example type for templating.
45+
func NewCmdTYPE(fullName string, f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
46+
o := NewTYPEOptions(streams)
3647
cmd := &cobra.Command{
3748
Use: "NAME [...]",
3849
Short: "A short description",
3950
Long: internalTYPELong,
4051
Example: fmt.Sprintf(internalTYPEExample, fullName),
4152
Run: func(cmd *cobra.Command, args []string) {
42-
kcmdutil.CheckErr(options.Complete(f, cmd, args))
43-
kcmdutil.CheckErr(options.Validate())
44-
if err := options.Run(); err != nil {
45-
// TODO: move me to kcmdutil
46-
if err == kcmdutil.ErrExit {
47-
os.Exit(1)
48-
}
49-
kcmdutil.CheckErr(err)
50-
}
53+
kcmdutil.CheckErr(o.Complete(f, cmd, args))
54+
kcmdutil.CheckErr(o.Validate())
55+
kcmdutil.CheckErr(o.Run())
5156
},
5257
}
58+
59+
o.PrintFlags.AddFlags(cmd)
60+
kcmdutil.AddDryRunFlag(cmd)
61+
5362
return cmd
5463
}
5564

56-
func (o *TYPEOptions) Complete(f kcmdutil.Factory, c *cobra.Command, args []string) error {
65+
func (o *TYPEOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error {
66+
var err error
67+
o.DryRun = kcmdutil.GetDryRunFlag(cmd)
68+
if o.DryRun {
69+
o.PrintFlags.Complete("%s (dry run)")
70+
}
71+
o.Printer, err = o.PrintFlags.ToPrinter()
72+
if err != nil {
73+
return err
74+
}
75+
5776
return nil
5877
}
5978

pkg/oc/cli/cmd/helper.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"strings"
56

67
"github.com/golang/glog"
78
"github.com/spf13/cobra"
9+
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
810
)
911

1012
// parseNamespaceResourceName parses the value and returns namespace, resource and the
@@ -35,3 +37,14 @@ func getFlagStringArray(cmd *cobra.Command, flag string) []string {
3537
}
3638
return s
3739
}
40+
41+
func GetObjectName(info *resource.Info) string {
42+
if info.Mapping != nil {
43+
return fmt.Sprintf("%s/%s", info.Mapping.Resource.Resource, info.Name)
44+
}
45+
gvk := info.Object.GetObjectKind().GroupVersionKind()
46+
if len(gvk.Group) == 0 {
47+
return fmt.Sprintf("%s/%s", strings.ToLower(gvk.Kind), info.Name)
48+
}
49+
return fmt.Sprintf("%s.%s/%s\n", strings.ToLower(gvk.Kind), gvk.Group, info.Name)
50+
}

0 commit comments

Comments
 (0)