forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
route.go
123 lines (101 loc) · 3.22 KB
/
route.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package create
import (
"fmt"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/meta"
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"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"
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
"github.com/openshift/origin/pkg/oc/util/ocscheme"
)
var (
routeLong = templates.LongDesc(`
Expose containers externally via secured routes
Three types of secured routes are supported: edge, passthrough, and reencrypt.
If you wish to create unsecured routes, see "%[1]s expose -h"`)
)
// NewCmdCreateRoute is a macro command to create a secured route.
func NewCmdCreateRoute(fullName string, f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "route",
Short: "Expose containers externally via secured routes",
Long: fmt.Sprintf(routeLong, fullName),
Run: kcmdutil.DefaultSubCommandRun(streams.ErrOut),
}
cmd.AddCommand(NewCmdCreateEdgeRoute(fullName, f, streams))
cmd.AddCommand(NewCmdCreatePassthroughRoute(fullName, f, streams))
cmd.AddCommand(NewCmdCreateReencryptRoute(fullName, f, streams))
return cmd
}
// CreateRouteSubcommandOptions is an options struct to support create subcommands
type CreateRouteSubcommandOptions struct {
// PrintFlags holds options necessary for obtaining a printer
PrintFlags *genericclioptions.PrintFlags
// Name of resource being created
Name string
ServiceName string
// DryRun is true if the command should be simulated but not run against the server
DryRun bool
Namespace string
EnforceNamespace bool
Mapper meta.RESTMapper
Printer printers.ResourcePrinter
Client routev1client.RoutesGetter
KubeClient kclientset.Interface
genericclioptions.IOStreams
}
func NewCreateRouteSubcommandOptions(ioStreams genericclioptions.IOStreams) *CreateRouteSubcommandOptions {
return &CreateRouteSubcommandOptions{
PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(ocscheme.PrintingInternalScheme),
IOStreams: ioStreams,
}
}
func (o *CreateRouteSubcommandOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error {
var err error
o.Name, err = resolveRouteName(args)
if err != nil {
return err
}
o.KubeClient, err = f.ClientSet()
if err != nil {
return err
}
clientConfig, err := f.ToRESTConfig()
if err != nil {
return err
}
o.Client, err = routev1client.NewForConfig(clientConfig)
if err != nil {
return err
}
o.Mapper, err = f.ToRESTMapper()
if err != nil {
return err
}
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}
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
}
func resolveRouteName(args []string) (string, error) {
switch len(args) {
case 0:
case 1:
return args[0], nil
default:
return "", fmt.Errorf("multiple names provided. Please specify at most one")
}
return "", nil
}