Move Deployments to ReplicaSets and switch the Deployment selector to the new LabelSelector.

Update the Deployments' API types, defaulting code, conversions, helpers
and validation to use ReplicaSets instead of ReplicationControllers and
LabelSelector instead of map[string]string for selectors.

Also update the Deployment controller, registry, kubectl subcommands,
client listers package and e2e tests to use ReplicaSets and
LabelSelector for Deployments.
This commit is contained in:
Madhusudan.C.S
2016-01-19 16:40:18 -08:00
parent fce98f3cf2
commit 518f08aa7c
24 changed files with 853 additions and 735 deletions

View File

@@ -447,11 +447,20 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
switch t := object.(type) {
case *api.ReplicationController:
return GetFirstPod(client, t.Namespace, t.Spec.Selector)
selector := labels.SelectorFromSet(t.Spec.Selector)
return GetFirstPod(client, t.Namespace, selector)
case *extensions.Deployment:
return GetFirstPod(client, t.Namespace, t.Spec.Selector)
selector, err := extensions.LabelSelectorAsSelector(t.Spec.Selector)
if err != nil {
return nil, fmt.Errorf("failed to convert label selector to selector: %v", err)
}
return GetFirstPod(client, t.Namespace, selector)
case *extensions.Job:
return GetFirstPod(client, t.Namespace, t.Spec.Selector.MatchLabels)
selector, err := extensions.LabelSelectorAsSelector(t.Spec.Selector)
if err != nil {
return nil, fmt.Errorf("failed to convert label selector to selector: %v", err)
}
return GetFirstPod(client, t.Namespace, selector)
case *api.Pod:
return t, nil
default:
@@ -469,12 +478,11 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
// GetFirstPod returns the first pod of an object from its namespace and selector
func GetFirstPod(client *client.Client, namespace string, selector map[string]string) (*api.Pod, error) {
func GetFirstPod(client *client.Client, namespace string, selector labels.Selector) (*api.Pod, error) {
var pods *api.PodList
for pods == nil || len(pods.Items) == 0 {
var err error
labelSelector := labels.SelectorFromSet(selector)
options := api.ListOptions{LabelSelector: labelSelector}
options := api.ListOptions{LabelSelector: selector}
if pods, err = client.Pods(namespace).List(options); err != nil {
return nil, err
}