Skip to content

Commit

Permalink
Fix DC reaper to deal with invalid resource name. (It was deleting al…
Browse files Browse the repository at this point in the history
…l RCs because apimachinery .AsSelector() ignores errors and returns MatchAll selector in that case.)
  • Loading branch information
tnozicka committed Nov 28, 2017
1 parent 33c21b7 commit b75bee4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions pkg/apps/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func (reaper *DeploymentConfigReaper) Stop(namespace, name string, timeout time.
}

// Delete all deployer and hook pods
options = metav1.ListOptions{LabelSelector: util.DeployerPodSelector(rc.Name).String()}
podList, err := reaper.kc.Core().Pods(rc.Namespace).List(options)
podList, err := reaper.kc.Core().Pods(rc.Namespace).List(metav1.ListOptions{
LabelSelector: util.DeployerPodSelector(rc.Name).String(),
})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apps/registry/deploylog/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (r *REST) waitForExistingDeployment(namespace, name string) (*kapi.Replicat
// returnApplicationPodName returns the best candidate pod for the target deployment in order to
// view its logs.
func (r *REST) returnApplicationPodName(target *kapi.ReplicationController) (string, error) {
selector := labels.Set(target.Spec.Selector).AsSelector()
selector := labels.SelectorFromValidatedSet(labels.Set(target.Spec.Selector))
sortBy := func(pods []*kapiv1.Pod) sort.Interface { return controller.ByLogging(pods) }

pod, _, err := kcmdutil.GetFirstPod(r.pn, target.Namespace, selector, r.timeout, sortBy)
Expand Down
4 changes: 1 addition & 3 deletions pkg/apps/registry/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/watch"
kapi "k8s.io/kubernetes/pkg/api"
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
Expand All @@ -26,8 +25,7 @@ var (
// the deployment became running, complete, or failed within timeout, false if it did not, and an error if any
// other error state occurred. The last observed deployment state is returned.
func WaitForRunningDeployment(rn kcoreclient.ReplicationControllersGetter, observed *kapi.ReplicationController, timeout time.Duration) (*kapi.ReplicationController, bool, error) {
fieldSelector := fields.Set{"metadata.name": observed.Name}.AsSelector()
options := metav1.ListOptions{FieldSelector: fieldSelector.String(), ResourceVersion: observed.ResourceVersion}
options := metav1.SingleObject(observed.ObjectMeta)
w, err := rn.ReplicationControllers(observed.Namespace).Watch(options)
if err != nil {
return observed, false, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/apps/strategy/recreate/recreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (s *RecreateDeploymentStrategy) scaleAndWait(deployment *kapi.ReplicationCo

// waitForTerminatedPods waits until all pods for the provided replication controller are terminated.
func (s *RecreateDeploymentStrategy) waitForTerminatedPods(from *kapi.ReplicationController, timeout time.Duration) {
selector := labels.Set(from.Spec.Selector).AsSelector()
selector := labels.SelectorFromValidatedSet(labels.Set(from.Spec.Selector))
options := metav1.ListOptions{LabelSelector: selector.String()}
podList, err := s.podClient.Pods(from.Namespace).List(options)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apps/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ func DeploymentNameForConfigVersion(name string, version int64) string {
// TODO: Using the annotation constant for now since the value is correct
// but we could consider adding a new constant to the public types.
func ConfigSelector(name string) labels.Selector {
return labels.Set{deployapi.DeploymentConfigAnnotation: name}.AsSelector()
return labels.SelectorFromValidatedSet(labels.Set{deployapi.DeploymentConfigAnnotation: name})
}

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

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

0 comments on commit b75bee4

Please sign in to comment.