...
|
...
|
@@ -18,6 +18,7 @@ package etcd
|
18
|
18
|
|
19
|
19
|
import (
|
20
|
20
|
"fmt"
|
|
21
|
+ "path"
|
21
|
22
|
|
22
|
23
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
23
|
24
|
kubeerr "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
...
|
...
|
@@ -112,6 +113,19 @@ func NamespaceKeyRootFunc(ctx api.Context, prefix string) string {
|
112
|
112
|
return key
|
113
|
113
|
}
|
114
|
114
|
|
|
115
|
+// NoNamespaceKeyFunc is the default function for constructing etcd paths to a resource relative to prefix enforcing namespace rules.
|
|
116
|
+// If a namespace is on context, it errors.
|
|
117
|
+func NoNamespaceKeyFunc(ctx api.Context, prefix string, name string) (string, error) {
|
|
118
|
+ ns, ok := api.NamespaceFrom(ctx)
|
|
119
|
+ if ok && len(ns) > 0 {
|
|
120
|
+ return "", kubeerr.NewBadRequest(fmt.Sprintf("Namespace parameter is not allowed on %s.", path.Base(prefix)))
|
|
121
|
+ }
|
|
122
|
+ if len(name) == 0 {
|
|
123
|
+ return "", kubeerr.NewBadRequest("Name parameter required.")
|
|
124
|
+ }
|
|
125
|
+ return path.Join(prefix, name), nil
|
|
126
|
+}
|
|
127
|
+
|
115
|
128
|
// NamespaceKeyFunc is the default function for constructing etcd paths to a resource relative to prefix enforcing namespace rules.
|
116
|
129
|
// If no namespace is on context, it errors.
|
117
|
130
|
func NamespaceKeyFunc(ctx api.Context, prefix string, name string) (string, error) {
|