// Get all replication controllers whose selectors would match a given set of // labels. // TODO Move this to pkg/client and ideally implement it server-side (instead // of getting all RC's and searching through them manually). func getReplicationControllersForLabels(c client.ReplicationControllerInterface, labelsToMatch labels.Labels) string { // Get all replication controllers. // TODO this needs a namespace scope as argument rcs, err := c.List(labels.Everything()) if err != nil { glog.Fatalf("Error getting replication controllers: %v\n", err) } // Find the ones that match labelsToMatch. var matchingRCs []api.ReplicationController for _, controller := range rcs.Items { selector := labels.SelectorFromSet(controller.Spec.Selector) if selector.Matches(labelsToMatch) { matchingRCs = append(matchingRCs, controller) } } // Format the matching RC's into strings. var rcStrings []string for _, controller := range matchingRCs { rcStrings = append(rcStrings, fmt.Sprintf("%s (%d/%d replicas created)", controller.Name, controller.Status.Replicas, controller.Spec.Replicas)) } list := strings.Join(rcStrings, ", ") if list == "" { return "<none>" } return list }
// getOverlappingControllers finds rcs that this controller overlaps, as well as rcs overlapping this controller. func getOverlappingControllers(c client.ReplicationControllerInterface, rc *api.ReplicationController) ([]api.ReplicationController, error) { rcs, err := c.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("error getting replication controllers: %v", err) } var matchingRCs []api.ReplicationController rcLabels := labels.Set(rc.Spec.Selector) for _, controller := range rcs.Items { newRCLabels := labels.Set(controller.Spec.Selector) if labels.SelectorFromSet(newRCLabels).Matches(rcLabels) || labels.SelectorFromSet(rcLabels).Matches(newRCLabels) { matchingRCs = append(matchingRCs, controller) } } return matchingRCs, nil }
// Get all replication controllers whose selectors would match a given set of // labels. // TODO Move this to pkg/client and ideally implement it server-side (instead // of getting all RC's and searching through them manually). func getReplicationControllersForLabels(c client.ReplicationControllerInterface, labelsToMatch labels.Labels) ([]api.ReplicationController, error) { // Get all replication controllers. // TODO this needs a namespace scope as argument rcs, err := c.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("error getting replication controllers: %v", err) } // Find the ones that match labelsToMatch. var matchingRCs []api.ReplicationController for _, controller := range rcs.Items { selector := labels.SelectorFromSet(controller.Spec.Selector) if selector.Matches(labelsToMatch) { matchingRCs = append(matchingRCs, controller) } } return matchingRCs, nil }