Skip to content

Commit

Permalink
Align label generation and apply on container-source as well (#8355)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew authored Nov 28, 2024
1 parent cb31cb2 commit f577063
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
6 changes: 6 additions & 0 deletions pkg/reconciler/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ func MakeSSLEnvVar() []corev1.EnvVar {
},
}
}

func Labels(name string) map[string]string {
return map[string]string{
"app.kubernetes.io/name": name,
}
}
13 changes: 7 additions & 6 deletions pkg/reconciler/integration/sink/integrationsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package sink
import (
"fmt"

"knative.dev/eventing/pkg/reconciler/integration"

"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"knative.dev/pkg/apis"
Expand All @@ -33,7 +35,6 @@ import (
sinksv1alpha1 "knative.dev/eventing/pkg/apis/sinks/v1alpha1"
fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake"
"knative.dev/eventing/pkg/client/injection/reconciler/sinks/v1alpha1/integrationsink"
"knative.dev/eventing/pkg/reconciler/integration/sink/resources"
fakekubeclient "knative.dev/pkg/client/injection/kube/client/fake"
"knative.dev/pkg/kmeta"
"knative.dev/pkg/logging"
Expand Down Expand Up @@ -187,16 +188,16 @@ func makeDeployment(sink *sinksv1alpha1.IntegrationSink, ready *corev1.Condition
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(sink),
},
Labels: resources.Labels(sink.Name),
Labels: integration.Labels(sink.Name),
},
Status: status,
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: resources.Labels(sink.Name),
MatchLabels: integration.Labels(sink.Name),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: resources.Labels(sink.Name),
Labels: integration.Labels(sink.Name),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
Expand Down Expand Up @@ -274,7 +275,7 @@ func makeService(name, namespace string) *corev1.Service {
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: resources.Labels(sinkName),
Labels: integration.Labels(sinkName),
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "sinks.knative.dev/v1alpha1",
Expand All @@ -295,7 +296,7 @@ func makeService(name, namespace string) *corev1.Service {
TargetPort: intstr.IntOrString{IntVal: 8080},
},
},
Selector: resources.Labels(sinkName),
Selector: integration.Labels(sinkName),
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/integration/sink/resources/container_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func MakeDeploymentSpec(sink *v1alpha1.IntegrationSink) *appsv1.Deployment {
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(sink),
},
Labels: Labels(sink.Name),
Labels: integration.Labels(sink.Name),
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: Labels(sink.Name),
MatchLabels: integration.Labels(sink.Name),
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: Labels(sink.Name),
Labels: integration.Labels(sink.Name),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
Expand Down Expand Up @@ -84,10 +84,10 @@ func MakeService(sink *v1alpha1.IntegrationSink) *corev1.Service {
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(sink),
},
Labels: Labels(sink.Name),
Labels: integration.Labels(sink.Name),
},
Spec: corev1.ServiceSpec{
Selector: Labels(sink.Name),
Selector: integration.Labels(sink.Name),
Ports: []corev1.ServicePort{
{
Name: "http",
Expand Down
24 changes: 0 additions & 24 deletions pkg/reconciler/integration/sink/resources/labels.go

This file was deleted.

6 changes: 6 additions & 0 deletions pkg/reconciler/integration/source/integrationsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package source
import (
"fmt"

"knative.dev/eventing/pkg/reconciler/integration"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -188,9 +190,13 @@ func makeContainerSource(source *sourcesv1alpha1.IntegrationSource, ready *corev
},
Name: containerSourceName,
Namespace: source.Namespace,
Labels: integration.Labels(source.Name),
},
Spec: sourcesv1.ContainerSourceSpec{
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: integration.Labels(source.Name),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ func NewContainerSource(source *v1alpha1.IntegrationSource) *sourcesv1.Container
},
Name: ContainerSourceName(source),
Namespace: source.Namespace,
Labels: integration.Labels(source.Name),
},
Spec: sourcesv1.ContainerSourceSpec{

Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: integration.Labels(source.Name),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"testing"

"knative.dev/eventing/pkg/reconciler/integration"

sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/pkg/apis"
"knative.dev/pkg/kmeta"
Expand Down Expand Up @@ -67,9 +69,13 @@ func TestNewContainerSource(t *testing.T) {
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(source),
},
Labels: integration.Labels(source.Name),
},
Spec: sourcesv1.ContainerSourceSpec{
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: integration.Labels(source.Name),
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Expand Down

0 comments on commit f577063

Please sign in to comment.