From a6a40978b6c25c20e94100779d6ebc417b52cd48 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Thu, 26 Sep 2024 10:02:53 +0200 Subject: [PATCH] Add Istio inject label Signed-off-by: Pierangelo Di Pilato --- .../storage-version-migrator.yaml | 1 + .../resources/receive_adapter.go | 20 +++++++++++++++++-- .../resources/receive_adapter_test.go | 5 +++-- test/config/monitoring/monitoring.yaml | 1 + test/upgrade/prober/forwarder.go | 4 ++++ test/upgrade/prober/receiver.go | 3 ++- test/upgrade/prober/sender.go | 3 ++- test/upgrade/prober/verify.go | 3 ++- 8 files changed, 33 insertions(+), 7 deletions(-) diff --git a/config/post-install/storage-version-migrator.yaml b/config/post-install/storage-version-migrator.yaml index 845c8bd7aae..65003a8a12f 100644 --- a/config/post-install/storage-version-migrator.yaml +++ b/config/post-install/storage-version-migrator.yaml @@ -32,6 +32,7 @@ spec: app.kubernetes.io/name: knative-eventing app.kubernetes.io/component: storage-version-migration-job app.kubernetes.io/version: devel + sidecar.istio.io/inject: "false" annotations: sidecar.istio.io/inject: "false" spec: diff --git a/pkg/reconciler/apiserversource/resources/receive_adapter.go b/pkg/reconciler/apiserversource/resources/receive_adapter.go index 4964f2a48b5..4d529c5a337 100644 --- a/pkg/reconciler/apiserversource/resources/receive_adapter.go +++ b/pkg/reconciler/apiserversource/resources/receive_adapter.go @@ -26,11 +26,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/intstr" - "knative.dev/eventing/pkg/adapter/v2" "knative.dev/pkg/kmeta" "knative.dev/pkg/ptr" "knative.dev/pkg/system" + "knative.dev/eventing/pkg/adapter/v2" + "knative.dev/eventing/pkg/adapter/apiserver" v1 "knative.dev/eventing/pkg/apis/sources/v1" reconcilersource "knative.dev/eventing/pkg/reconciler/source" @@ -80,7 +81,7 @@ func MakeReceiveAdapter(args *ReceiveAdapterArgs) (*appsv1.Deployment, error) { Annotations: map[string]string{ "sidecar.istio.io/inject": "true", }, - Labels: args.Labels, + Labels: maybeAddKeyValue(args.Labels, "sidecar.istio.io/inject", "true"), }, Spec: corev1.PodSpec{ NodeSelector: args.NodeSelector, @@ -210,3 +211,18 @@ func makeEnv(args *ReceiveAdapterArgs) ([]corev1.EnvVar, error) { } return envs, nil } + +func maybeAddKeyValue(labels map[string]string, key string, value string) map[string]string { + if labels == nil { + return map[string]string{key: value} + } + ret := labels + if _, ok := labels[key]; !ok { + ret = make(map[string]string, len(labels)+1) + for k, v := range labels { + ret[k] = v + } + ret[key] = value + } + return ret +} diff --git a/pkg/reconciler/apiserversource/resources/receive_adapter_test.go b/pkg/reconciler/apiserversource/resources/receive_adapter_test.go index 7093b652f2b..48abe550c0e 100644 --- a/pkg/reconciler/apiserversource/resources/receive_adapter_test.go +++ b/pkg/reconciler/apiserversource/resources/receive_adapter_test.go @@ -128,8 +128,9 @@ O2dgzikq8iSy1BlRsVw= "sidecar.istio.io/inject": "true", }, Labels: map[string]string{ - "test-key1": "test-value1", - "test-key2": "test-value2", + "sidecar.istio.io/inject": "true", + "test-key1": "test-value1", + "test-key2": "test-value2", }, }, Spec: corev1.PodSpec{ diff --git a/test/config/monitoring/monitoring.yaml b/test/config/monitoring/monitoring.yaml index 9d9ec3dbdda..ca524484110 100644 --- a/test/config/monitoring/monitoring.yaml +++ b/test/config/monitoring/monitoring.yaml @@ -38,6 +38,7 @@ spec: metadata: labels: app: zipkin + sidecar.istio.io/inject: "false" annotations: sidecar.istio.io/inject: "false" spec: diff --git a/test/upgrade/prober/forwarder.go b/test/upgrade/prober/forwarder.go index a7ee1d1ab67..1e96d7168f3 100644 --- a/test/upgrade/prober/forwarder.go +++ b/test/upgrade/prober/forwarder.go @@ -20,6 +20,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + testlib "knative.dev/eventing/test/lib" "knative.dev/eventing/test/lib/duck" "knative.dev/eventing/test/lib/resources" @@ -69,6 +70,9 @@ func (p *prober) forwarderKService(name, namespace string) *unstructured.Unstruc "spec": map[string]interface{}{ "template": map[string]interface{}{ "metadata": map[string]interface{}{ + "labels": map[string]interface{}{ + "sidecar.istio.io/inject": "true", + }, "annotations": map[string]interface{}{ "sidecar.istio.io/inject": "true", "sidecar.istio.io/rewriteAppHTTPProbers": "true", diff --git a/test/upgrade/prober/receiver.go b/test/upgrade/prober/receiver.go index ddd75fd6641..47c574e2d88 100644 --- a/test/upgrade/prober/receiver.go +++ b/test/upgrade/prober/receiver.go @@ -91,7 +91,8 @@ func (p *prober) createReceiverDeployment() *appsv1.Deployment { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "app": receiver.Name, + "app": receiver.Name, + "sidecar.istio.io/inject": "true", }, Annotations: map[string]string{ "sidecar.istio.io/inject": "true", diff --git a/test/upgrade/prober/sender.go b/test/upgrade/prober/sender.go index df9173a1f09..4e1a26bc2c8 100644 --- a/test/upgrade/prober/sender.go +++ b/test/upgrade/prober/sender.go @@ -52,7 +52,8 @@ func (p *prober) deploySender() { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "app": sender.Name, + "app": sender.Name, + "sidecar.istio.io/inject": "true", }, Annotations: map[string]string{ "sidecar.istio.io/inject": "true", diff --git a/test/upgrade/prober/verify.go b/test/upgrade/prober/verify.go index 9810daf8cc1..069e3a1821c 100644 --- a/test/upgrade/prober/verify.go +++ b/test/upgrade/prober/verify.go @@ -255,7 +255,8 @@ func (p *prober) deployFetcher() *batchv1.Job { Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "app": fetcherName, + "app": fetcherName, + "sidecar.istio.io/inject": "true", }, Annotations: map[string]string{ "sidecar.istio.io/inject": "true",