Skip to content

Commit b75bee4

Browse files
committed
Fix DC reaper to deal with invalid resource name. (It was deleting all RCs because apimachinery .AsSelector() ignores errors and returns MatchAll selector in that case.)
1 parent 33c21b7 commit b75bee4

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

pkg/apps/cmd/delete.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ func (reaper *DeploymentConfigReaper) Stop(namespace, name string, timeout time.
110110
}
111111

112112
// Delete all deployer and hook pods
113-
options = metav1.ListOptions{LabelSelector: util.DeployerPodSelector(rc.Name).String()}
114-
podList, err := reaper.kc.Core().Pods(rc.Namespace).List(options)
113+
podList, err := reaper.kc.Core().Pods(rc.Namespace).List(metav1.ListOptions{
114+
LabelSelector: util.DeployerPodSelector(rc.Name).String(),
115+
})
115116
if err != nil {
116117
return err
117118
}

pkg/apps/registry/deploylog/rest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (r *REST) waitForExistingDeployment(namespace, name string) (*kapi.Replicat
221221
// returnApplicationPodName returns the best candidate pod for the target deployment in order to
222222
// view its logs.
223223
func (r *REST) returnApplicationPodName(target *kapi.ReplicationController) (string, error) {
224-
selector := labels.Set(target.Spec.Selector).AsSelector()
224+
selector := labels.SelectorFromValidatedSet(labels.Set(target.Spec.Selector))
225225
sortBy := func(pods []*kapiv1.Pod) sort.Interface { return controller.ByLogging(pods) }
226226

227227
pod, _, err := kcmdutil.GetFirstPod(r.pn, target.Namespace, selector, r.timeout, sortBy)

pkg/apps/registry/rest.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9-
"k8s.io/apimachinery/pkg/fields"
109
"k8s.io/apimachinery/pkg/watch"
1110
kapi "k8s.io/kubernetes/pkg/api"
1211
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
@@ -26,8 +25,7 @@ var (
2625
// the deployment became running, complete, or failed within timeout, false if it did not, and an error if any
2726
// other error state occurred. The last observed deployment state is returned.
2827
func WaitForRunningDeployment(rn kcoreclient.ReplicationControllersGetter, observed *kapi.ReplicationController, timeout time.Duration) (*kapi.ReplicationController, bool, error) {
29-
fieldSelector := fields.Set{"metadata.name": observed.Name}.AsSelector()
30-
options := metav1.ListOptions{FieldSelector: fieldSelector.String(), ResourceVersion: observed.ResourceVersion}
28+
options := metav1.SingleObject(observed.ObjectMeta)
3129
w, err := rn.ReplicationControllers(observed.Namespace).Watch(options)
3230
if err != nil {
3331
return observed, false, err

pkg/apps/strategy/recreate/recreate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (s *RecreateDeploymentStrategy) scaleAndWait(deployment *kapi.ReplicationCo
255255

256256
// waitForTerminatedPods waits until all pods for the provided replication controller are terminated.
257257
func (s *RecreateDeploymentStrategy) waitForTerminatedPods(from *kapi.ReplicationController, timeout time.Duration) {
258-
selector := labels.Set(from.Spec.Selector).AsSelector()
258+
selector := labels.SelectorFromValidatedSet(labels.Set(from.Spec.Selector))
259259
options := metav1.ListOptions{LabelSelector: selector.String()}
260260
podList, err := s.podClient.Pods(from.Namespace).List(options)
261261
if err != nil {

pkg/apps/util/util.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ func DeploymentNameForConfigVersion(name string, version int64) string {
176176
// TODO: Using the annotation constant for now since the value is correct
177177
// but we could consider adding a new constant to the public types.
178178
func ConfigSelector(name string) labels.Selector {
179-
return labels.Set{deployapi.DeploymentConfigAnnotation: name}.AsSelector()
179+
return labels.SelectorFromValidatedSet(labels.Set{deployapi.DeploymentConfigAnnotation: name})
180180
}
181181

182182
// DeployerPodSelector returns a label Selector which can be used to find all
183183
// deployer pods associated with a deployment with name.
184184
func DeployerPodSelector(name string) labels.Selector {
185-
return labels.Set{deployapi.DeployerPodForDeploymentLabel: name}.AsSelector()
185+
return labels.SelectorFromValidatedSet(labels.Set{deployapi.DeployerPodForDeploymentLabel: name})
186186
}
187187

188188
// AnyDeployerPodSelector returns a label Selector which can be used to find
@@ -802,7 +802,7 @@ func WaitForRunningDeployerPod(podClient kcoreclient.PodsGetter, rc *api.Replica
802802
}
803803
watcher, err := podClient.Pods(rc.Namespace).Watch(
804804
metav1.ListOptions{
805-
FieldSelector: fields.Set{"metadata.name": podName}.AsSelector().String(),
805+
FieldSelector: fields.OneTermEqualSelector("metadata.name", podName).String(),
806806
},
807807
)
808808
if err != nil {

0 commit comments

Comments
 (0)