Browse code

Bug 1224097: Don't use custom names for route.servicename

kargakis authored on 2015/05/22 18:12:44
Showing 3 changed files
... ...
@@ -199,7 +199,7 @@ the new object will re-use the labels from the object it exposes.
199 199
 # Expose a service as a route
200 200
 $ osc expose service frontend
201 201
 # Expose a deployment config as a service and use the specified port and name
202
-$ osc expose dc ruby-heloo-world --port=8080 --name=myservice --generator=services/v1
202
+$ osc expose dc ruby-hello-world --port=8080 --name=myservice --generator=services/v1
203 203
 ```
204 204
 
205 205
 osc process
... ...
@@ -13,15 +13,20 @@ import (
13 13
 )
14 14
 
15 15
 const (
16
-	exposeLong = `Take a replicated application and expose it as a route.
16
+	exposeLong = `Expose containers internally as services or externally via routes.
17 17
 
18
-Looks up a service by name and derives a route from it.`
18
+There is also the ability to expose a deployment configuration, replication controller, service, or pod
19
+as a new service on a specified port. If no labels are specified, the new object will re-use the 
20
+labels from the object it exposes.`
19 21
 
20
-	exposeExample = `// Create a route based on service nginx. The new route will re-use nginx's labels.
22
+	exposeExample = `// Create a route based on service nginx. The new route will re-use nginx's labels
21 23
 $ %[1]s expose service nginx
22 24
 
23
-// Create a route and specify your own label.
24
-$ %[1]s expose service nginx --labels name=myroute`
25
+// Create a route and specify your own label and route name
26
+$ %[1]s expose service nginx --labels name=myroute --name=fromdowntown
27
+
28
+// Expose a deployment configuration as a service and use the specified port
29
+$ %[1]s expose dc ruby-hello-world --port=8080 --generator=services/v1`
25 30
 )
26 31
 
27 32
 // NewCmdExpose is a wrapper for the Kubernetes cli expose command
... ...
@@ -1,6 +1,8 @@
1 1
 package generator
2 2
 
3 3
 import (
4
+	"fmt"
5
+
4 6
 	kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
5 7
 	"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
6 8
 	"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
... ...
@@ -15,7 +17,8 @@ type RouteGenerator struct{}
15 15
 func (RouteGenerator) ParamNames() []kubectl.GeneratorParam {
16 16
 	return []kubectl.GeneratorParam{
17 17
 		{"labels", false},
18
-		{"name", true},
18
+		{"default-name", true},
19
+		{"name", false},
19 20
 	}
20 21
 }
21 22
 
... ...
@@ -34,12 +37,20 @@ func (RouteGenerator) Generate(params map[string]string) (runtime.Object, error)
34 34
 		}
35 35
 	}
36 36
 
37
+	name, found := params["name"]
38
+	if !found || len(name) == 0 {
39
+		name, found = params["default-name"]
40
+		if !found || len(name) == 0 {
41
+			return nil, fmt.Errorf("'name' is a required parameter.")
42
+		}
43
+	}
44
+
37 45
 	return &api.Route{
38 46
 		ObjectMeta: kapi.ObjectMeta{
39
-			Name:   params["name"],
47
+			Name:   name,
40 48
 			Labels: labels,
41 49
 		},
42
-		ServiceName: params["name"],
50
+		ServiceName: params["default-name"],
43 51
 	}, nil
44 52
 }
45 53