Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry-pick of #17492 on release-3.7 #17599

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/registry/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestWaitForRunningDeploymentSuccess(t *testing.T) {
fakeController := &kapi.ReplicationController{}
fakeController.Name = "test-1"
fakeController.Namespace = "test"
fakeController.Annotations = map[string]string{deployapi.DeploymentStatusAnnotation: string(deployapi.DeploymentStatusRunning)}

kubeclient := fake.NewSimpleClientset([]runtime.Object{fakeController}...)
fakeWatch := watch.NewFake()
Expand All @@ -38,7 +39,6 @@ func TestWaitForRunningDeploymentSuccess(t *testing.T) {
}
}()

fakeController.Annotations = map[string]string{deployapi.DeploymentStatusAnnotation: string(deployapi.DeploymentStatusRunning)}
fakeWatch.Modify(fakeController)
<-stopChan
}
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 @@ -175,13 +175,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 @@ -837,7 +837,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