Rename api.Namespace to api.NamespaceValue to avoid name collision

pull/6/head
derekwaynecarr 2015-01-19 14:35:41 -05:00
parent e27d534b87
commit 151be7773c
5 changed files with 15 additions and 15 deletions

View File

@ -379,7 +379,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
glog.Fatalf("usage: kubecfg [OPTIONS] %s <%s>", method, prettyWireStorage())
}
case "update":
obj, err := c.Verb("GET").Namespace(api.Namespace(ctx)).Suffix(path).Do().Get()
obj, err := c.Verb("GET").Namespace(api.NamespaceValue(ctx)).Suffix(path).Do().Get()
if err != nil {
glog.Fatalf("error obtaining resource version for update: %v", err)
}
@ -405,7 +405,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
return false
}
r := c.Verb(verb).Namespace(api.Namespace(ctx)).Suffix(path)
r := c.Verb(verb).Namespace(api.NamespaceValue(ctx)).Suffix(path)
if len(*selector) > 0 {
r.ParseSelectorParam("labels", *selector)
}

View File

@ -63,8 +63,8 @@ func NamespaceFrom(ctx Context) (string, bool) {
return namespace, ok
}
// Namespace returns the value of the namespace key on the ctx, or the empty string if none
func Namespace(ctx Context) string {
// NamespaceValue returns the value of the namespace key on the ctx, or the empty string if none
func NamespaceValue(ctx Context) string {
namespace, _ := NamespaceFrom(ctx)
return namespace
}

View File

@ -123,7 +123,7 @@ var (
// update of the image is performed.
func Update(ctx api.Context, name string, client client.Interface, updatePeriod time.Duration, imageName string) error {
// TODO ctx is not needed as input to this function, should just be 'namespace'
controller, err := client.ReplicationControllers(api.Namespace(ctx)).Get(name)
controller, err := client.ReplicationControllers(api.NamespaceValue(ctx)).Get(name)
if err != nil {
return err
}
@ -138,7 +138,7 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
s := labels.Set(controller.Spec.Selector).AsSelector()
podList, err := client.Pods(api.Namespace(ctx)).List(s)
podList, err := client.Pods(api.NamespaceValue(ctx)).List(s)
if err != nil {
return err
}
@ -156,7 +156,7 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
time.Sleep(updatePeriod)
}
return wait.Poll(updatePollInterval, updatePollTimeout, func() (bool, error) {
podList, err := client.Pods(api.Namespace(ctx)).List(s)
podList, err := client.Pods(api.NamespaceValue(ctx)).List(s)
if err != nil {
return false, err
}
@ -172,12 +172,12 @@ func StopController(ctx api.Context, name string, client client.Interface) error
// ResizeController resizes a controller named 'name' by setting replicas to 'replicas'.
func ResizeController(ctx api.Context, name string, replicas int, client client.Interface) error {
// TODO ctx is not needed, and should just be a namespace
controller, err := client.ReplicationControllers(api.Namespace(ctx)).Get(name)
controller, err := client.ReplicationControllers(api.NamespaceValue(ctx)).Get(name)
if err != nil {
return err
}
controller.Spec.Replicas = replicas
controllerOut, err := client.ReplicationControllers(api.Namespace(ctx)).Update(controller)
controllerOut, err := client.ReplicationControllers(api.NamespaceValue(ctx)).Update(controller)
if err != nil {
return err
}
@ -270,7 +270,7 @@ func RunController(ctx api.Context, image, name string, replicas int, client cli
},
}
controllerOut, err := client.ReplicationControllers(api.Namespace(ctx)).Create(controller)
controllerOut, err := client.ReplicationControllers(api.NamespaceValue(ctx)).Create(controller)
if err != nil {
return err
}
@ -310,7 +310,7 @@ func createService(ctx api.Context, name string, port int, client client.Interfa
},
},
}
svc, err := client.Services(api.Namespace(ctx)).Create(svc)
svc, err := client.Services(api.NamespaceValue(ctx)).Create(svc)
return svc, err
}
@ -318,12 +318,12 @@ func createService(ctx api.Context, name string, port int, client client.Interfa
// already be stopped.
func DeleteController(ctx api.Context, name string, client client.Interface) error {
// TODO remove ctx in favor of just namespace string
controller, err := client.ReplicationControllers(api.Namespace(ctx)).Get(name)
controller, err := client.ReplicationControllers(api.NamespaceValue(ctx)).Get(name)
if err != nil {
return err
}
if controller.Spec.Replicas != 0 {
return fmt.Errorf("controller has non-zero replicas (%d), please stop it first", controller.Spec.Replicas)
}
return client.ReplicationControllers(api.Namespace(ctx)).Delete(name)
return client.ReplicationControllers(api.NamespaceValue(ctx)).Delete(name)
}

View File

@ -47,7 +47,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
if !ok {
return nil, fmt.Errorf("invalid object type")
}
if api.Namespace(ctx) != "" {
if api.NamespaceValue(ctx) != "" {
if !api.ValidNamespace(ctx, &event.ObjectMeta) {
return nil, errors.NewConflict("event", event.Namespace, fmt.Errorf("event.namespace does not match the provided context"))
}

View File

@ -273,7 +273,7 @@ type binder struct {
func (b *binder) Bind(binding *api.Binding) error {
glog.V(2).Infof("Attempting to bind %v to %v", binding.PodID, binding.Host)
ctx := api.WithNamespace(api.NewContext(), binding.Namespace)
return b.Post().Namespace(api.Namespace(ctx)).Resource("bindings").Body(binding).Do().Error()
return b.Post().Namespace(api.NamespaceValue(ctx)).Resource("bindings").Body(binding).Do().Error()
}
type clock interface {