mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
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:
21
pkg/client/cache/listers.go
vendored
21
pkg/client/cache/listers.go
vendored
@@ -236,33 +236,34 @@ func (s *StoreToDeploymentLister) List() (deployments []extensions.Deployment, e
|
||||
return deployments, nil
|
||||
}
|
||||
|
||||
// GetDeploymentsForRC returns a list of deployments managing a replication controller. Returns an error only if no matching deployments are found.
|
||||
func (s *StoreToDeploymentLister) GetDeploymentsForRC(rc *api.ReplicationController) (deployments []extensions.Deployment, err error) {
|
||||
var selector labels.Selector
|
||||
// GetDeploymentsForReplicaSet returns a list of deployments managing a replica set. Returns an error only if no matching deployments are found.
|
||||
func (s *StoreToDeploymentLister) GetDeploymentsForReplicaSet(rs *extensions.ReplicaSet) (deployments []extensions.Deployment, err error) {
|
||||
var d extensions.Deployment
|
||||
|
||||
if len(rc.Labels) == 0 {
|
||||
err = fmt.Errorf("no deployments found for replication controller %v because it has no labels", rc.Name)
|
||||
if len(rs.Labels) == 0 {
|
||||
err = fmt.Errorf("no deployments found for ReplicaSet %v because it has no labels", rs.Name)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: MODIFY THIS METHOD so that it checks for the podTemplateSpecHash label
|
||||
for _, m := range s.Store.List() {
|
||||
d = *m.(*extensions.Deployment)
|
||||
if d.Namespace != rc.Namespace {
|
||||
if d.Namespace != rs.Namespace {
|
||||
continue
|
||||
}
|
||||
labelSet := labels.Set(d.Spec.Selector)
|
||||
selector = labels.Set(d.Spec.Selector).AsSelector()
|
||||
|
||||
selector, err := extensions.LabelSelectorAsSelector(rs.Spec.Selector)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert LabelSelector to Selector: %v", err)
|
||||
}
|
||||
// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
|
||||
if labelSet.AsSelector().Empty() || !selector.Matches(labels.Set(rc.Labels)) {
|
||||
if selector.Empty() || !selector.Matches(labels.Set(rs.Labels)) {
|
||||
continue
|
||||
}
|
||||
deployments = append(deployments, d)
|
||||
}
|
||||
if len(deployments) == 0 {
|
||||
err = fmt.Errorf("could not find deployments set for replication controller %s in namespace %s with labels: %v", rc.Name, rc.Namespace, rc.Labels)
|
||||
err = fmt.Errorf("could not find deployments set for ReplicaSet %s in namespace %s with labels: %v", rs.Name, rs.Namespace, rs.Labels)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user