Skip to content

Commit

Permalink
Use static selector labels for EL svc/deployments
Browse files Browse the repository at this point in the history
Previously, if a user added an extra label, we'd propagate that to the
deployment and services.  However, in addition, we'd also update the selector
fields in both deployments and services to use this additional label. This is
unnecessary since the static set of default labels that we add on each resource
is enough to match and do not need to be updated throughout the lifecycle of
the resources.

Fixes #463

Co-Authored-By: Vincent Tereso <[email protected]>

Signed-off-by: Dibyo Mukherjee <[email protected]>
  • Loading branch information
dibyom committed Apr 1, 2020
1 parent 8497b8c commit fdf0b3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (c *Reconciler) reconcileService(el *v1alpha1.EventListener) error {
service := &corev1.Service{
ObjectMeta: generateObjectMeta(el),
Spec: corev1.ServiceSpec{
Selector: mergeLabels(el.Labels, GenerateResourceLabels(el.Name)),
Selector: GenerateResourceLabels(el.Name),
Type: el.Spec.ServiceType,
Ports: []corev1.ServicePort{
{
Expand Down Expand Up @@ -300,7 +300,7 @@ func (c *Reconciler) reconcileDeployment(el *v1alpha1.EventListener) error {
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: labels,
MatchLabels: GenerateResourceLabels(el.Name),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down
12 changes: 8 additions & 4 deletions pkg/reconciler/v1alpha1/eventlistener/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func Test_reconcileService(t *testing.T) {
}
service2 := service1.DeepCopy()
service2.Labels = mergeLabels(generatedLabels, updateLabel)
service2.Spec.Selector = mergeLabels(generatedLabels, updateLabel)
service2.Spec.Selector = generatedLabels

service3 := service1.DeepCopy()
service3.Spec.Ports[0].NodePort = 30000
Expand Down Expand Up @@ -344,7 +344,7 @@ func Test_reconcileDeployment(t *testing.T) {
// deployment 2 == initial deployment + labels from eventListener
deployment2 := deployment1.DeepCopy()
deployment2.Labels = mergeLabels(generatedLabels, updateLabel)
deployment2.Spec.Selector.MatchLabels = mergeLabels(generatedLabels, updateLabel)
deployment2.Spec.Selector.MatchLabels = generatedLabels
deployment2.Spec.Template.Labels = mergeLabels(generatedLabels, updateLabel)

// deployment 3 == initial deployment + updated replicas
Expand Down Expand Up @@ -604,7 +604,7 @@ func TestReconcile(t *testing.T) {

deployment2 := deployment1.DeepCopy()
deployment2.Labels = mergeLabels(updateLabel, generatedLabels)
deployment2.Spec.Selector.MatchLabels = mergeLabels(updateLabel, generatedLabels)
deployment2.Spec.Selector.MatchLabels = generatedLabels
deployment2.Spec.Template.Labels = mergeLabels(updateLabel, generatedLabels)

deployment3 := deployment2.DeepCopy()
Expand All @@ -630,7 +630,7 @@ func TestReconcile(t *testing.T) {

service2 := service1.DeepCopy()
service2.Labels = mergeLabels(updateLabel, generatedLabels)
service2.Spec.Selector = mergeLabels(updateLabel, generatedLabels)
service2.Spec.Selector = generatedLabels

service3 := service2.DeepCopy()
service3.Spec.Type = corev1.ServiceTypeNodePort
Expand Down Expand Up @@ -660,12 +660,16 @@ func TestReconcile(t *testing.T) {
}, {
name: "update-eventlistener-labels",
key: reconcileKey,
// Resources before reconcile starts: EL has extra label that deployment/svc does not
startResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{eventListener2},
Deployments: []*appsv1.Deployment{deployment1},
Services: []*corev1.Service{service1},
},
// We expect the deployment and services to propagate the extra label
// but the selectors in both Service and deployment should have the same
// label
endResources: test.Resources{
Namespaces: []*corev1.Namespace{namespaceResource},
EventListeners: []*v1alpha1.EventListener{eventListener2},
Expand Down

0 comments on commit fdf0b3c

Please sign in to comment.