Rename api.Namespace to api.NamespaceValue to avoid name collision
This commit is contained in:
parent
e27d534b87
commit
151be7773c
@ -379,7 +379,7 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
|
|||||||
glog.Fatalf("usage: kubecfg [OPTIONS] %s <%s>", method, prettyWireStorage())
|
glog.Fatalf("usage: kubecfg [OPTIONS] %s <%s>", method, prettyWireStorage())
|
||||||
}
|
}
|
||||||
case "update":
|
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 {
|
if err != nil {
|
||||||
glog.Fatalf("error obtaining resource version for update: %v", err)
|
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
|
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 {
|
if len(*selector) > 0 {
|
||||||
r.ParseSelectorParam("labels", *selector)
|
r.ParseSelectorParam("labels", *selector)
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,8 @@ func NamespaceFrom(ctx Context) (string, bool) {
|
|||||||
return namespace, ok
|
return namespace, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace returns the value of the namespace key on the ctx, or the empty string if none
|
// NamespaceValue returns the value of the namespace key on the ctx, or the empty string if none
|
||||||
func Namespace(ctx Context) string {
|
func NamespaceValue(ctx Context) string {
|
||||||
namespace, _ := NamespaceFrom(ctx)
|
namespace, _ := NamespaceFrom(ctx)
|
||||||
return namespace
|
return namespace
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ var (
|
|||||||
// update of the image is performed.
|
// update of the image is performed.
|
||||||
func Update(ctx api.Context, name string, client client.Interface, updatePeriod time.Duration, imageName string) error {
|
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'
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
|
|||||||
|
|
||||||
s := labels.Set(controller.Spec.Selector).AsSelector()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ func Update(ctx api.Context, name string, client client.Interface, updatePeriod
|
|||||||
time.Sleep(updatePeriod)
|
time.Sleep(updatePeriod)
|
||||||
}
|
}
|
||||||
return wait.Poll(updatePollInterval, updatePollTimeout, func() (bool, error) {
|
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 {
|
if err != nil {
|
||||||
return false, err
|
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'.
|
// ResizeController resizes a controller named 'name' by setting replicas to 'replicas'.
|
||||||
func ResizeController(ctx api.Context, name string, replicas int, client client.Interface) error {
|
func ResizeController(ctx api.Context, name string, replicas int, client client.Interface) error {
|
||||||
// TODO ctx is not needed, and should just be a namespace
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
controller.Spec.Replicas = replicas
|
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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
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
|
return svc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,12 +318,12 @@ func createService(ctx api.Context, name string, port int, client client.Interfa
|
|||||||
// already be stopped.
|
// already be stopped.
|
||||||
func DeleteController(ctx api.Context, name string, client client.Interface) error {
|
func DeleteController(ctx api.Context, name string, client client.Interface) error {
|
||||||
// TODO remove ctx in favor of just namespace string
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if controller.Spec.Replicas != 0 {
|
if controller.Spec.Replicas != 0 {
|
||||||
return fmt.Errorf("controller has non-zero replicas (%d), please stop it first", controller.Spec.Replicas)
|
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)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan apiserver.RE
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid object type")
|
return nil, fmt.Errorf("invalid object type")
|
||||||
}
|
}
|
||||||
if api.Namespace(ctx) != "" {
|
if api.NamespaceValue(ctx) != "" {
|
||||||
if !api.ValidNamespace(ctx, &event.ObjectMeta) {
|
if !api.ValidNamespace(ctx, &event.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("event", event.Namespace, fmt.Errorf("event.namespace does not match the provided context"))
|
return nil, errors.NewConflict("event", event.Namespace, fmt.Errorf("event.namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ type binder struct {
|
|||||||
func (b *binder) Bind(binding *api.Binding) error {
|
func (b *binder) Bind(binding *api.Binding) error {
|
||||||
glog.V(2).Infof("Attempting to bind %v to %v", binding.PodID, binding.Host)
|
glog.V(2).Infof("Attempting to bind %v to %v", binding.PodID, binding.Host)
|
||||||
ctx := api.WithNamespace(api.NewContext(), binding.Namespace)
|
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 {
|
type clock interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user