Clean up pre-ControllerRef compatibility logic
This commit is contained in:
@@ -513,25 +513,6 @@ func GetAllReplicaSets(deployment *extensions.Deployment, c clientset.Interface)
|
||||
return oldRSes, allOldRSes, newRS, nil
|
||||
}
|
||||
|
||||
// GetAllReplicaSetsV15 is a compatibility function that emulates the behavior
|
||||
// from v1.5.x (list matching objects by selector) except that it leaves out
|
||||
// objects that are explicitly marked as being controlled by something else.
|
||||
func GetAllReplicaSetsV15(deployment *extensions.Deployment, c clientset.Interface) ([]*extensions.ReplicaSet, []*extensions.ReplicaSet, *extensions.ReplicaSet, error) {
|
||||
rsList, err := ListReplicaSetsV15(deployment, rsListFromClient(c))
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
oldRSes, allOldRSes, err := FindOldReplicaSets(deployment, rsList)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
newRS, err := FindNewReplicaSet(deployment, rsList)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
return oldRSes, allOldRSes, newRS, nil
|
||||
}
|
||||
|
||||
// GetOldReplicaSets returns the old replica sets targeted by the given Deployment; get PodList and ReplicaSetList from client interface.
|
||||
// Note that the first set of old replica sets doesn't include the ones with no pods, and the second set of old replica sets include all old replica sets.
|
||||
func GetOldReplicaSets(deployment *extensions.Deployment, c clientset.Interface) ([]*extensions.ReplicaSet, []*extensions.ReplicaSet, error) {
|
||||
@@ -552,17 +533,6 @@ func GetNewReplicaSet(deployment *extensions.Deployment, c clientset.Interface)
|
||||
return FindNewReplicaSet(deployment, rsList)
|
||||
}
|
||||
|
||||
// GetNewReplicaSetV15 is a compatibility function that emulates the behavior
|
||||
// from v1.5.x (list matching objects by selector) except that it leaves out
|
||||
// objects that are explicitly marked as being controlled by something else.
|
||||
func GetNewReplicaSetV15(deployment *extensions.Deployment, c clientset.Interface) (*extensions.ReplicaSet, error) {
|
||||
rsList, err := ListReplicaSetsV15(deployment, rsListFromClient(c))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return FindNewReplicaSet(deployment, rsList)
|
||||
}
|
||||
|
||||
// rsListFromClient returns an rsListFunc that wraps the given client.
|
||||
func rsListFromClient(c clientset.Interface) rsListFunc {
|
||||
return func(namespace string, options metav1.ListOptions) ([]*extensions.ReplicaSet, error) {
|
||||
@@ -617,10 +587,9 @@ func ListReplicaSets(deployment *extensions.Deployment, getRSList rsListFunc) ([
|
||||
return owned, nil
|
||||
}
|
||||
|
||||
// ListReplicaSetsV15 is a compatibility function that emulates the behavior
|
||||
// from v1.5.x (list matching objects by selector) except that it leaves out
|
||||
// objects that are explicitly marked as being controlled by something else.
|
||||
func ListReplicaSetsV15(deployment *extensions.Deployment, getRSList rsListFunc) ([]*extensions.ReplicaSet, error) {
|
||||
// ListReplicaSetsInternal is ListReplicaSets for internalextensions.
|
||||
// TODO: Remove the duplicate when call sites are updated to ListReplicaSets.
|
||||
func ListReplicaSetsInternal(deployment *internalextensions.Deployment, getRSList func(string, metav1.ListOptions) ([]*internalextensions.ReplicaSet, error)) ([]*internalextensions.ReplicaSet, error) {
|
||||
namespace := deployment.Namespace
|
||||
selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector)
|
||||
if err != nil {
|
||||
@@ -631,45 +600,13 @@ func ListReplicaSetsV15(deployment *extensions.Deployment, getRSList rsListFunc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Since this function maintains compatibility with v1.5, the objects we want
|
||||
// do not necessarily have ControllerRefs pointing to us.
|
||||
// However, we can at least avoid interfering with other controllers that do
|
||||
// use ControllerRef.
|
||||
filtered := make([]*extensions.ReplicaSet, 0, len(all))
|
||||
for _, rs := range all {
|
||||
controllerRef := controller.GetControllerOf(rs)
|
||||
if controllerRef != nil && controllerRef.UID != deployment.UID {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, rs)
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
// ListReplicaSetsInternalV15 is ListReplicaSetsV15 for internalextensions.
|
||||
// TODO: Remove the duplicate when call sites are updated to ListReplicaSetsV15.
|
||||
func ListReplicaSetsInternalV15(deployment *internalextensions.Deployment, getRSList func(string, metav1.ListOptions) ([]*internalextensions.ReplicaSet, error)) ([]*internalextensions.ReplicaSet, error) {
|
||||
namespace := deployment.Namespace
|
||||
selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options := metav1.ListOptions{LabelSelector: selector.String()}
|
||||
all, err := getRSList(namespace, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Since this function maintains compatibility with v1.5, the objects we want
|
||||
// do not necessarily have ControllerRefs pointing to us.
|
||||
// However, we can at least avoid interfering with other controllers that do
|
||||
// use ControllerRef.
|
||||
// Only include those whose ControllerRef matches the Deployment.
|
||||
filtered := make([]*internalextensions.ReplicaSet, 0, len(all))
|
||||
for _, rs := range all {
|
||||
controllerRef := controller.GetControllerOf(rs)
|
||||
if controllerRef != nil && controllerRef.UID != deployment.UID {
|
||||
continue
|
||||
if controllerRef != nil && controllerRef.UID == deployment.UID {
|
||||
filtered = append(filtered, rs)
|
||||
}
|
||||
filtered = append(filtered, rs)
|
||||
}
|
||||
return filtered, nil
|
||||
}
|
||||
@@ -708,41 +645,6 @@ func ListPods(deployment *extensions.Deployment, rsList []*extensions.ReplicaSet
|
||||
return owned, nil
|
||||
}
|
||||
|
||||
// ListPodsV15 is a compatibility function that emulates the behavior
|
||||
// from v1.5.x (list matching objects by selector) except that it leaves out
|
||||
// objects that are explicitly marked as being controlled by something else.
|
||||
func ListPodsV15(deployment *extensions.Deployment, rsList []*extensions.ReplicaSet, getPodList podListFunc) (*v1.PodList, error) {
|
||||
namespace := deployment.Namespace
|
||||
selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options := metav1.ListOptions{LabelSelector: selector.String()}
|
||||
podList, err := getPodList(namespace, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Since this function maintains compatibility with v1.5, the objects we want
|
||||
// do not necessarily have ControllerRefs pointing to one of our ReplicaSets.
|
||||
// However, we can at least avoid interfering with other controllers that do
|
||||
// use ControllerRef.
|
||||
rsMap := make(map[types.UID]bool, len(rsList))
|
||||
for _, rs := range rsList {
|
||||
rsMap[rs.UID] = true
|
||||
}
|
||||
filtered := make([]v1.Pod, 0, len(podList.Items))
|
||||
for i := range podList.Items {
|
||||
pod := &podList.Items[i]
|
||||
controllerRef := controller.GetControllerOf(pod)
|
||||
if controllerRef != nil && !rsMap[controllerRef.UID] {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, *pod)
|
||||
}
|
||||
podList.Items = filtered
|
||||
return podList, nil
|
||||
}
|
||||
|
||||
// EqualIgnoreHash returns true if two given podTemplateSpec are equal, ignoring the diff in value of Labels[pod-template-hash]
|
||||
// We ignore pod-template-hash because the hash result would be different upon podTemplateSpec API changes
|
||||
// (e.g. the addition of a new field will cause the hash code to change)
|
||||
|
Reference in New Issue
Block a user