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

Update set commands #20139

Merged
merged 7 commits into from
Jul 6, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
376 changes: 47 additions & 329 deletions contrib/completions/bash/oc

Large diffs are not rendered by default.

376 changes: 47 additions & 329 deletions contrib/completions/zsh/oc

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,35 +449,35 @@ For example, to edit the service `docker-registry` in JSON using the `v1` API fo
$ oc edit svc/docker-registry --output-version=v1 -o json
```

### oc env
### oc set env

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

```bash
$ oc env <resource-type>/<name> <k1>=<v1> <k2>=<v2>
$ oc set env <resource-type>/<name> <k1>=<v1> <k2>=<v2>
```

For example:

```bash
$ oc env dc/app DB_USER=user DB_PASS=pass
$ oc set env dc/app DB_USER=user DB_PASS=pass
```

### oc volume
### oc set volume

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

```bash
$ oc volume <resource-type>/<name> --<action> <options>
$ oc set volume <resource-type>/<name> --<action> <options>
```

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

```bash
$ oc volume dc/registry --add --mount-path=/opt
$ oc set volume dc/registry --add --mount-path=/opt
```

### oc label
Expand Down
2 changes: 0 additions & 2 deletions docs/man/man1/.files_generated_oc

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

3 changes: 0 additions & 3 deletions docs/man/man1/oc-env.1

This file was deleted.

3 changes: 0 additions & 3 deletions docs/man/man1/oc-volumes.1

This file was deleted.

2 changes: 1 addition & 1 deletion hack/lib/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ function os::start::registry() {
# For testing purposes, ensure the quota objects are always up to date in the registry by
# disabling project cache.
oc adm registry --config="${ADMIN_KUBECONFIG}" --images="${USE_IMAGES}" --enforce-quota -o json | \
oc env --config="${ADMIN_KUBECONFIG}" -f - --output json "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_PROJECTCACHETTL=0" | \
oc set env --config="${ADMIN_KUBECONFIG}" --local -f - --output json "REGISTRY_MIDDLEWARE_REPOSITORY_OPENSHIFT_PROJECTCACHETTL=0" | \
oc create --config="${ADMIN_KUBECONFIG}" -f -
}
readonly -f os::start::registry
2 changes: 1 addition & 1 deletion pkg/oc/admin/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func NewCmdRouter(f kcmdutil.Factory, parentName, name string, out, errout io.Wr
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)")
cmd.Flags().StringVar(&cfg.ImageTemplate.Format, "images", cfg.ImageTemplate.Format, "The image to base this router on - ${component} will be replaced with --type")
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.")
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.")
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.")
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.")
cmd.Flags().Int32Var(&cfg.Replicas, "replicas", cfg.Replicas, "The replication factor of the router; commonly 2 when high availability is desired.")
cmd.Flags().StringVar(&cfg.Labels, "labels", cfg.Labels, "A set of labels to uniquely identify the router and its components.")
Expand Down
2 changes: 0 additions & 2 deletions pkg/oc/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
"options",
"deploy",
// These commands are deprecated and should not appear in help
moved(fullName, "set env", cmds, set.NewCmdEnv(fullName, f, ioStreams)),
moved(fullName, "set volume", cmds, set.NewCmdVolume(fullName, f, ioStreams)),
moved(fullName, "logs", cmds, cmd.NewCmdBuildLogs(fullName, f, ioStreams)),
moved(fullName, "secrets link", secretcmds, secrets.NewCmdLinkSecret("add", fullName, f, ioStreams)),
moved(fullName, "create secret", secretcmds, secrets.NewCmdCreateSecret(secrets.NewSecretRecommendedCommandName, fullName, f, ioStreams)),
Expand Down
59 changes: 39 additions & 20 deletions pkg/oc/cli/cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package cmd

import (
"fmt"
"io"
"os"

"github.com/spf13/cobra"

"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"

"github.com/openshift/origin/pkg/oc/util/ocscheme"
)

var (
Expand All @@ -21,39 +23,56 @@ var (
)

type TYPEOptions struct {
In io.Reader
Out, ErrOut io.Writer
PrintFlags *genericclioptions.PrintFlags

Printer printers.ResourcePrinter
DryRun bool

genericclioptions.IOStreams
}

// NewCmdTYPE implements a TYPE command
// NewTYPEOptions returns a TYPEOptions with proper defaults.
// This is an example type for templating.
func NewCmdTYPE(fullName string, f kcmdutil.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
options := &TYPEOptions{
In: in,
Out: out,
ErrOut: errout,
func NewTYPEOptions(streams genericclioptions.IOStreams) *TYPEOptions {
return &TYPEOptions{
PrintFlags: genericclioptions.NewPrintFlags("action performed").WithTypeSetter(ocscheme.PrintingInternalScheme),
IOStreams: streams,
}
}

// NewCmdTYPE implements a TYPE command
// This is an example type for templating.
func NewCmdTYPE(fullName string, f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewTYPEOptions(streams)
cmd := &cobra.Command{
Use: "NAME [...]",
Short: "A short description",
Long: internalTYPELong,
Example: fmt.Sprintf(internalTYPEExample, fullName),
Run: func(cmd *cobra.Command, args []string) {
kcmdutil.CheckErr(options.Complete(f, cmd, args))
kcmdutil.CheckErr(options.Validate())
if err := options.Run(); err != nil {
// TODO: move me to kcmdutil
if err == kcmdutil.ErrExit {
os.Exit(1)
}
kcmdutil.CheckErr(err)
}
kcmdutil.CheckErr(o.Complete(f, cmd, args))
kcmdutil.CheckErr(o.Validate())
kcmdutil.CheckErr(o.Run())
},
}

o.PrintFlags.AddFlags(cmd)
kcmdutil.AddDryRunFlag(cmd)

return cmd
}

func (o *TYPEOptions) Complete(f kcmdutil.Factory, c *cobra.Command, args []string) error {
func (o *TYPEOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error {
var err error
o.DryRun = kcmdutil.GetDryRunFlag(cmd)
if o.DryRun {
o.PrintFlags.Complete("%s (dry run)")
}
o.Printer, err = o.PrintFlags.ToPrinter()
if err != nil {
return err
}

return nil
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/oc/cli/cmd/helper.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cmd

import (
"fmt"
"strings"

"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
)

// parseNamespaceResourceName parses the value and returns namespace, resource and the
Expand Down Expand Up @@ -35,3 +37,14 @@ func getFlagStringArray(cmd *cobra.Command, flag string) []string {
}
return s
}

func GetObjectName(info *resource.Info) string {
if info.Mapping != nil {
return fmt.Sprintf("%s/%s", info.Mapping.Resource.Resource, info.Name)
}
gvk := info.Object.GetObjectKind().GroupVersionKind()
if len(gvk.Group) == 0 {
return fmt.Sprintf("%s/%s", strings.ToLower(gvk.Kind), info.Name)
}
return fmt.Sprintf("%s.%s/%s\n", strings.ToLower(gvk.Kind), gvk.Group, info.Name)
}
Loading