Replace use of "id" in strings with "name"

This commit is contained in:
Clayton Coleman 2014-10-22 14:46:28 -04:00
parent bb77a5d15f
commit 91d9a90e4e
10 changed files with 28 additions and 25 deletions

View File

@ -333,7 +333,7 @@ func ValidatePodState(podState *api.PodState) errs.ErrorList {
func ValidatePod(pod *api.Pod) errs.ErrorList {
allErrs := errs.ErrorList{}
if len(pod.Name) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("id", pod.Name))
allErrs = append(allErrs, errs.NewFieldRequired("name", pod.Name))
}
if !util.IsDNSSubdomain(pod.Namespace) {
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", pod.Namespace))
@ -347,7 +347,7 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ErrorList {
allErrs := errs.ErrorList{}
if newPod.Name != oldPod.Name {
allErrs = append(allErrs, errs.NewFieldInvalid("ID", newPod.Name))
allErrs = append(allErrs, errs.NewFieldInvalid("name", newPod.Name))
}
if len(newPod.DesiredState.Manifest.Containers) != len(oldPod.DesiredState.Manifest.Containers) {
@ -374,9 +374,9 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) errs.ErrorList {
func ValidateService(service *api.Service) errs.ErrorList {
allErrs := errs.ErrorList{}
if len(service.Name) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("id", service.Name))
allErrs = append(allErrs, errs.NewFieldRequired("name", service.Name))
} else if !util.IsDNS952Label(service.Name) {
allErrs = append(allErrs, errs.NewFieldInvalid("id", service.Name))
allErrs = append(allErrs, errs.NewFieldInvalid("name", service.Name))
}
if !util.IsDNSSubdomain(service.Namespace) {
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", service.Namespace))
@ -399,7 +399,7 @@ func ValidateService(service *api.Service) errs.ErrorList {
func ValidateReplicationController(controller *api.ReplicationController) errs.ErrorList {
allErrs := errs.ErrorList{}
if len(controller.Name) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("id", controller.Name))
allErrs = append(allErrs, errs.NewFieldRequired("name", controller.Name))
}
if !util.IsDNSSubdomain(controller.Namespace) {
allErrs = append(allErrs, errs.NewFieldInvalid("namespace", controller.Namespace))
@ -441,7 +441,7 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) errs.ErrorList {
// ValidateBoundPod tests if required fields on a bound pod are set.
func ValidateBoundPod(pod *api.BoundPod) (errors []error) {
if !util.IsDNSSubdomain(pod.Name) {
errors = append(errors, errs.NewFieldInvalid("id", pod.Name))
errors = append(errors, errs.NewFieldInvalid("name", pod.Name))
}
if !util.IsDNSSubdomain(pod.Namespace) {
errors = append(errors, errs.NewFieldInvalid("namespace", pod.Namespace))

View File

@ -813,7 +813,7 @@ func TestValidateReplicationController(t *testing.T) {
for i := range errs {
field := errs[i].(errors.ValidationError).Field
if !strings.HasPrefix(field, "desiredState.podTemplate.") &&
field != "id" &&
field != "name" &&
field != "namespace" &&
field != "desiredState.replicaSelector" &&
field != "GCEPersistentDisk.ReadOnly" &&

View File

@ -138,9 +138,9 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value)
return nil
}
var podColumns = []string{"ID", "Image(s)", "Host", "Labels", "Status"}
var replicationControllerColumns = []string{"ID", "Image(s)", "Selector", "Replicas"}
var serviceColumns = []string{"ID", "Labels", "Selector", "IP", "Port"}
var podColumns = []string{"Name", "Image(s)", "Host", "Labels", "Status"}
var replicationControllerColumns = []string{"Name", "Image(s)", "Selector", "Replicas"}
var serviceColumns = []string{"Name", "Labels", "Selector", "IP", "Port"}
var minionColumns = []string{"Minion identifier"}
var statusColumns = []string{"Status"}
var eventColumns = []string{"Name", "Kind", "Status", "Reason", "Message"}

View File

@ -50,7 +50,7 @@ Examples:
Run: func(cmd *cobra.Command, args []string) {
// If command line args are passed in, use those preferentially.
if len(args) > 0 && len(args) != 2 {
usageError(cmd, "If passing in command line parameters, must be resource and id")
usageError(cmd, "If passing in command line parameters, must be resource and name")
}
var data []byte

View File

@ -93,14 +93,14 @@ func doUpdate(c *client.RESTClient, resource string, obj runtime.Object) (string
// object.
id, err := getIDFromObj(obj)
if err != nil {
return "", fmt.Errorf("ID not retrievable from object for update: %v", err)
return "", fmt.Errorf("Name not retrievable from object for update: %v", err)
}
// Get the object from the server to find out its current resource
// version to prevent race conditions in updating the object.
serverObj, err := c.Get().Path(resource).Path(id).Do().Get()
if err != nil {
return "", fmt.Errorf("Item ID %s does not exist for update: %v", id, err)
return "", fmt.Errorf("Item Name %s does not exist for update: %v", id, err)
}
version, err := getResourceVersionFromObj(serverObj)
if err != nil {
@ -134,7 +134,10 @@ func doUpdate(c *client.RESTClient, resource string, obj runtime.Object) (string
func doDelete(c *client.RESTClient, resource string, obj runtime.Object) (string, error) {
id, err := getIDFromObj(obj)
if err != nil {
return "", fmt.Errorf("ID not retrievable from object for update: %v", err)
return "", fmt.Errorf("Name not retrievable from object for delete: %v", err)
}
if id == "" {
return "", fmt.Errorf("The supplied resource has no Name and cannot be deleted")
}
err = c.Delete().Path(resource).Path(id).Do().Error()

View File

@ -154,10 +154,10 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value)
return nil
}
var podColumns = []string{"ID", "IMAGE(S)", "HOST", "LABELS", "STATUS"}
var replicationControllerColumns = []string{"ID", "IMAGE(S)", "SELECTOR", "REPLICAS"}
var serviceColumns = []string{"ID", "LABELS", "SELECTOR", "IP", "PORT"}
var minionColumns = []string{"ID"}
var podColumns = []string{"NAME", "IMAGE(S)", "HOST", "LABELS", "STATUS"}
var replicationControllerColumns = []string{"NAME", "IMAGE(S)", "SELECTOR", "REPLICAS"}
var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT"}
var minionColumns = []string{"NAME"}
var statusColumns = []string{"STATUS"}
// addDefaultHandlers adds print handlers for default Kubernetes types.

View File

@ -522,7 +522,7 @@ func (r *Registry) WatchServices(ctx api.Context, label, field labels.Selector,
if !label.Empty() {
return nil, fmt.Errorf("label selectors are not supported on services")
}
if value, found := field.RequiresExactMatch("ID"); found {
if value, found := field.RequiresExactMatch("name"); found {
key, err := makeServiceKey(ctx, value)
if err != nil {
return nil, err
@ -532,7 +532,7 @@ func (r *Registry) WatchServices(ctx api.Context, label, field labels.Selector,
if field.Empty() {
return r.WatchList(makeServiceListKey(ctx), version, tools.Everything)
}
return nil, fmt.Errorf("only the 'ID' and default (everything) field selectors are supported")
return nil, fmt.Errorf("only the 'name' and default (everything) field selectors are supported")
}
// ListEndpoints obtains a list of Services.
@ -567,7 +567,7 @@ func (r *Registry) WatchEndpoints(ctx api.Context, label, field labels.Selector,
if !label.Empty() {
return nil, fmt.Errorf("label selectors are not supported on endpoints")
}
if value, found := field.RequiresExactMatch("ID"); found {
if value, found := field.RequiresExactMatch("name"); found {
key, err := makeServiceEndpointsKey(ctx, value)
if err != nil {
return nil, err

View File

@ -1252,7 +1252,7 @@ func TestEtcdWatchServices(t *testing.T) {
registry := NewTestEtcdRegistry(fakeClient)
watching, err := registry.WatchServices(ctx,
labels.Everything(),
labels.SelectorFromSet(labels.Set{"ID": "foo"}),
labels.SelectorFromSet(labels.Set{"name": "foo"}),
"1",
)
if err != nil {
@ -1306,7 +1306,7 @@ func TestEtcdWatchEndpoints(t *testing.T) {
watching, err := registry.WatchEndpoints(
ctx,
labels.Everything(),
labels.SelectorFromSet(labels.Set{"ID": "foo"}),
labels.SelectorFromSet(labels.Set{"name": "foo"}),
"1",
)
if err != nil {

View File

@ -141,7 +141,7 @@ func (rs *REST) Get(ctx api.Context, id string) (runtime.Object, error) {
func (rs *REST) podToSelectableFields(pod *api.Pod) labels.Set {
return labels.Set{
"ID": pod.Name,
"name": pod.Name,
"DesiredState.Status": string(pod.DesiredState.Status),
"DesiredState.Host": pod.DesiredState.Host,
}

View File

@ -243,7 +243,7 @@ func TestListPodListSelection(t *testing.T) {
{
expectedIDs: util.NewStringSet("foo", "bar", "baz", "qux", "zot"),
}, {
field: "ID=zot",
field: "name=zot",
expectedIDs: util.NewStringSet("zot"),
}, {
label: "label=qux",