From 2938b0c4725d407d86032e59c671674faaf70c54 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Mon, 24 Feb 2025 18:24:46 +0100 Subject: [PATCH] Inject integration images from ConfigMap Signed-off-by: Pierangelo Di Pilato --- config/core/deployments/controller.yaml | 48 +++++++++++++++++++ .../integration/sink/integrationsink_test.go | 5 +- .../sink/resources/container_image.go | 18 +++---- .../source/integrationsource_test.go | 5 +- .../source/resources/containersource.go | 19 +++----- .../source/resources/containersource_test.go | 5 +- 6 files changed, 74 insertions(+), 26 deletions(-) diff --git a/config/core/deployments/controller.yaml b/config/core/deployments/controller.yaml index 4292d5d1000..657e6db6cc3 100644 --- a/config/core/deployments/controller.yaml +++ b/config/core/deployments/controller.yaml @@ -83,6 +83,54 @@ spec: key: transform-jsonata name: eventing-transformations-images + - name: INTEGRATION_SOURCE_TIMER_IMAGE + valueFrom: + configMapKeyRef: + key: timer-source + name: eventing-integrations-images + + - name: INTEGRATION_SOURCE_AWS_S3_IMAGE + valueFrom: + configMapKeyRef: + key: aws-s3-source + name: eventing-integrations-images + + - name: INTEGRATION_SOURCE_AWS_SQS_IMAGE + valueFrom: + configMapKeyRef: + key: aws-sqs-source + name: eventing-integrations-images + + - name: INTEGRATION_SOURCE_AWS_DDB_STREAMS_IMAGE + valueFrom: + configMapKeyRef: + key: aws-ddb-streams-source + name: eventing-integrations-images + + - name: INTEGRATION_SINK_LOG_IMAGE + valueFrom: + configMapKeyRef: + key: log-sink + name: eventing-integrations-images + + - name: INTEGRATION_SINK_AWS_S3_IMAGE + valueFrom: + configMapKeyRef: + key: aws-s3-sink + name: eventing-integrations-images + + - name: INTEGRATION_SINK_AWS_SQS_IMAGE + valueFrom: + configMapKeyRef: + key: aws-sqs-sink + name: eventing-integrations-images + + - name: INTEGRATION_SINK_AWS_SNS_IMAGE + valueFrom: + configMapKeyRef: + key: aws-sns-sink + name: eventing-integrations-images + ## Adapter settings # - name: K_LOGGING_CONFIG # value: '' diff --git a/pkg/reconciler/integration/sink/integrationsink_test.go b/pkg/reconciler/integration/sink/integrationsink_test.go index 59697487d51..063c63f8326 100644 --- a/pkg/reconciler/integration/sink/integrationsink_test.go +++ b/pkg/reconciler/integration/sink/integrationsink_test.go @@ -58,6 +58,8 @@ const ( sinkName = "test-integration-sink" sinkUID = "1234-5678-90" testNS = "test-namespace" + + logSinkImage = "quay.io/fake-image/log-sink" ) var ( @@ -74,6 +76,7 @@ var ( ) func TestReconcile(t *testing.T) { + t.Setenv("INTEGRATION_SINK_LOG_IMAGE", logSinkImage) table := TableTest{ { @@ -202,7 +205,7 @@ func makeDeployment(sink *sinksv1alpha1.IntegrationSink, ready *corev1.Condition Containers: []corev1.Container{ { Name: "sink", - Image: "gcr.io/knative-nightly/log-sink:latest", + Image: logSinkImage, ImagePullPolicy: corev1.PullIfNotPresent, Ports: []corev1.ContainerPort{ { diff --git a/pkg/reconciler/integration/sink/resources/container_image.go b/pkg/reconciler/integration/sink/resources/container_image.go index dda42d1982f..65797a04407 100644 --- a/pkg/reconciler/integration/sink/resources/container_image.go +++ b/pkg/reconciler/integration/sink/resources/container_image.go @@ -17,6 +17,8 @@ limitations under the License. package resources import ( + "os" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -28,13 +30,6 @@ import ( "knative.dev/pkg/kmeta" ) -var sinkImageMap = map[string]string{ - "log": "gcr.io/knative-nightly/log-sink:latest", - "aws-s3": "gcr.io/knative-nightly/aws-s3-sink:latest", - "aws-sqs": "gcr.io/knative-nightly/aws-sqs-sink:latest", - "aws-sns": "gcr.io/knative-nightly/aws-sns-sink:latest", -} - func MakeDeploymentSpec(sink *v1alpha1.IntegrationSink, featureFlags feature.Flags) *appsv1.Deployment { //t := true @@ -219,15 +214,16 @@ func makeEnv(sink *v1alpha1.IntegrationSink, featureFlags feature.Flags) []corev } func selectImage(sink *v1alpha1.IntegrationSink) string { + // Injected in ./config/core/deployments/controller.yaml switch { case sink.Spec.Log != nil: - return sinkImageMap["log"] + return os.Getenv("INTEGRATION_SINK_LOG_IMAGE") case sink.Spec.Aws != nil && sink.Spec.Aws.S3 != nil: - return sinkImageMap["aws-s3"] + return os.Getenv("INTEGRATION_SINK_AWS_S3_IMAGE") case sink.Spec.Aws != nil && sink.Spec.Aws.SQS != nil: - return sinkImageMap["aws-sqs"] + return os.Getenv("INTEGRATION_SINK_AWS_SQS_IMAGE") case sink.Spec.Aws != nil && sink.Spec.Aws.SNS != nil: - return sinkImageMap["aws-sns"] + return os.Getenv("INTEGRATION_SINK_AWS_SNS_IMAGE") default: return "" } diff --git a/pkg/reconciler/integration/source/integrationsource_test.go b/pkg/reconciler/integration/source/integrationsource_test.go index 8190fe96ff5..24bc0be65b6 100644 --- a/pkg/reconciler/integration/source/integrationsource_test.go +++ b/pkg/reconciler/integration/source/integrationsource_test.go @@ -58,6 +58,8 @@ const ( testNS = "testnamespace" sinkName = "testsink" generation = 1 + + timerSourceImage = "quay.io/fake-image/timer-source" ) var ( @@ -75,6 +77,7 @@ var ( ) func TestReconcile(t *testing.T) { + t.Setenv("INTEGRATION_SOURCE_TIMER_IMAGE", timerSourceImage) table := TableTest{ { @@ -242,7 +245,7 @@ func makeContainerSource(source *sourcesv1alpha1.IntegrationSource, ready *corev Containers: []corev1.Container{ { Name: "source", - Image: "gcr.io/knative-nightly/timer-source:latest", + Image: timerSourceImage, ImagePullPolicy: corev1.PullIfNotPresent, Env: []corev1.EnvVar{ { diff --git a/pkg/reconciler/integration/source/resources/containersource.go b/pkg/reconciler/integration/source/resources/containersource.go index 530318287bc..5b980a26c19 100644 --- a/pkg/reconciler/integration/source/resources/containersource.go +++ b/pkg/reconciler/integration/source/resources/containersource.go @@ -17,6 +17,8 @@ limitations under the License. package resources import ( + "os" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" commonv1a1 "knative.dev/eventing/pkg/apis/common/integration/v1alpha1" @@ -26,14 +28,6 @@ import ( "knative.dev/pkg/kmeta" ) -// TODO: replace with ConfigMap -var sourceImageMap = map[string]string{ - "timer": "gcr.io/knative-nightly/timer-source:latest", - "aws-s3": "gcr.io/knative-nightly/aws-s3-source:latest", - "aws-sqs": "gcr.io/knative-nightly/aws-sqs-source:latest", - "aws-ddb-streams": "gcr.io/knative-nightly/aws-ddb-streams-source:latest", -} - func NewContainerSource(source *v1alpha1.IntegrationSource, oidc bool) *sourcesv1.ContainerSource { return &sourcesv1.ContainerSource{ ObjectMeta: metav1.ObjectMeta{ @@ -135,15 +129,16 @@ func makeEnv(source *v1alpha1.IntegrationSource, oidc bool) []corev1.EnvVar { } func selectImage(source *v1alpha1.IntegrationSource) string { + // Injected in ./config/core/deployments/controller.yaml switch { case source.Spec.Timer != nil: - return sourceImageMap["timer"] + return os.Getenv("INTEGRATION_SOURCE_TIMER_IMAGE") case source.Spec.Aws != nil && source.Spec.Aws.S3 != nil: - return sourceImageMap["aws-s3"] + return os.Getenv("INTEGRATION_SOURCE_AWS_S3_IMAGE") case source.Spec.Aws != nil && source.Spec.Aws.SQS != nil: - return sourceImageMap["aws-sqs"] + return os.Getenv("INTEGRATION_SOURCE_AWS_SQS_IMAGE") case source.Spec.Aws != nil && source.Spec.Aws.DDBStreams != nil: - return sourceImageMap["aws-ddb-streams"] + return os.Getenv("INTEGRATION_SOURCE_AWS_DDB_STREAMS_IMAGE") default: return "" } diff --git a/pkg/reconciler/integration/source/resources/containersource_test.go b/pkg/reconciler/integration/source/resources/containersource_test.go index ecdafe788c5..e342b1900cd 100644 --- a/pkg/reconciler/integration/source/resources/containersource_test.go +++ b/pkg/reconciler/integration/source/resources/containersource_test.go @@ -40,6 +40,9 @@ const ( ) func TestNewContainerSource(t *testing.T) { + const timerImage = "quay.io/timer-image" + t.Setenv("INTEGRATION_SOURCE_TIMER_IMAGE", timerImage) + source := &v1alpha1.IntegrationSource{ ObjectMeta: metav1.ObjectMeta{ @@ -80,7 +83,7 @@ func TestNewContainerSource(t *testing.T) { Containers: []corev1.Container{ { Name: "source", - Image: "gcr.io/knative-nightly/timer-source:latest", + Image: timerImage, ImagePullPolicy: corev1.PullIfNotPresent, Env: []corev1.EnvVar{ {Name: "CAMEL_KNATIVE_CLIENT_SSL_ENABLED", Value: "true"},