Skip to content

Commit

Permalink
Reduce a deployments selector to only match the revision uid (#2818)
Browse files Browse the repository at this point in the history
Prior the selector criteria would include all the revision's labels.
This would cause reconciliation of a revision's deployment to fail
when a revision label was added/removed.
  • Loading branch information
dprotaso authored and knative-prow-robot committed Jan 2, 2019
1 parent ea5983d commit d60628d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pkg/reconciler/v1alpha1/revision/cruds.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (c *Reconciler) checkAndUpdateDeployment(ctx context.Context, rev *v1alpha1
// Preserve the current scale of the Deployment.
deployment.Spec.Replicas = have.Spec.Replicas

// Preserve the label selector since it's immutable
// TODO(dprotaso) Determine other immutable properties
deployment.Spec.Selector = have.Spec.Selector

// If the spec we want is the spec we have, then we're good.
if equality.Semantic.DeepEqual(have.Spec, deployment.Spec) {
return have, Unchanged, nil
Expand Down
16 changes: 4 additions & 12 deletions pkg/reconciler/v1alpha1/revision/resources/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,9 +1160,7 @@ func TestMakeDeployment(t *testing.T) {
Replicas: &one,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
serving.RevisionLabelKey: "bar",
serving.RevisionUID: "1234",
AppLabelKey: "bar",
serving.RevisionUID: "1234",
},
},
ProgressDeadlineSeconds: &ProgressDeadlineSeconds,
Expand Down Expand Up @@ -1232,9 +1230,7 @@ func TestMakeDeployment(t *testing.T) {
Replicas: &one,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
serving.RevisionLabelKey: "bar",
serving.RevisionUID: "1234",
AppLabelKey: "bar",
serving.RevisionUID: "1234",
},
},
ProgressDeadlineSeconds: &ProgressDeadlineSeconds,
Expand Down Expand Up @@ -1299,9 +1295,7 @@ func TestMakeDeployment(t *testing.T) {
Replicas: &one,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
serving.RevisionLabelKey: "bar",
serving.RevisionUID: "1234",
AppLabelKey: "bar",
serving.RevisionUID: "1234",
},
},
ProgressDeadlineSeconds: &ProgressDeadlineSeconds,
Expand Down Expand Up @@ -1372,9 +1366,7 @@ func TestMakeDeployment(t *testing.T) {
Replicas: &one,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
serving.RevisionLabelKey: "bar",
serving.RevisionUID: "1234",
AppLabelKey: "bar",
serving.RevisionUID: "1234",
},
},
ProgressDeadlineSeconds: &ProgressDeadlineSeconds,
Expand Down
6 changes: 5 additions & 1 deletion pkg/reconciler/v1alpha1/revision/resources/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func makeLabels(revision *v1alpha1.Revision) map[string]string {

// makeSelector constructs the Selector we will apply to K8s resources.
func makeSelector(revision *v1alpha1.Revision) *metav1.LabelSelector {
return &metav1.LabelSelector{MatchLabels: makeLabels(revision)}
return &metav1.LabelSelector{
MatchLabels: map[string]string{
serving.RevisionUID: string(revision.UID),
},
}
}

// makeAnnotations creates the annotations we will apply to
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/v1alpha1/revision/resources/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ func TestMakeLabels(t *testing.T) {
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("makeLabels (-want, +got) = %v", diff)
}
wantSelector := &metav1.LabelSelector{MatchLabels: test.want}

wantSelector := &metav1.LabelSelector{
MatchLabels: map[string]string{serving.RevisionUID: "1234"},
}
gotSelector := makeSelector(test.rev)
if diff := cmp.Diff(wantSelector, gotSelector); diff != "" {
t.Errorf("makeLabels (-want, +got) = %v", diff)
Expand Down

0 comments on commit d60628d

Please sign in to comment.