@@ -19,6 +19,10 @@ package source
1919import (
2020 "fmt"
2121
22+ "knative.dev/eventing/pkg/apis/feature"
23+ "knative.dev/eventing/pkg/auth"
24+ "knative.dev/pkg/ptr"
25+
2226 "knative.dev/eventing/pkg/reconciler/integration"
2327
2428 corev1 "k8s.io/api/core/v1"
@@ -162,6 +166,36 @@ func TestReconcile(t *testing.T) {
162166 WithIntegrationSourcePropagateContainerSourceStatus (makeContainerSourceStatus (& conditionTrue )),
163167 ),
164168 }},
169+ }, {
170+ Name : "OIDC: IntegrationSource uses OIDC service account of containersource" ,
171+ Key : testNS + "/" + sourceName ,
172+ Ctx : feature .ToContext (context .Background (), feature.Flags {
173+ feature .OIDCAuthentication : feature .Enabled ,
174+ }),
175+ Objects : []runtime.Object {
176+ NewIntegrationSource (sourceName , testNS ,
177+ WithIntegrationSourceUID (sourceUID ),
178+ WithIntegrationSourceSpec (makeIntegrationSourceSpec (sinkDest )),
179+ ),
180+ makeContainerSourceOIDC (NewIntegrationSource (sourceName , testNS ,
181+ WithIntegrationSourceUID (sourceUID ),
182+ WithIntegrationSourceSpec (makeIntegrationSourceSpec (sinkDest )),
183+ ), & conditionTrue ),
184+ },
185+ WantErr : false ,
186+ WantStatusUpdates : []clientgotesting.UpdateActionImpl {{
187+ Object : NewIntegrationSource (sourceName , testNS ,
188+ WithIntegrationSourceUID (sourceUID ),
189+ WithIntegrationSourceSpec (makeIntegrationSourceSpec (sinkDest )),
190+ WithInitIntegrationSourceConditions ,
191+ WithIntegrationSourceStatusObservedGeneration (generation ),
192+ WithIntegrationSourcePropagateContainerSourceStatus (makeContainerSourceStatus (& conditionTrue )),
193+ WithIntegrationSourceOIDCServiceAccountName (getOIDCServiceAccountNameForContainerSource ()),
194+ ),
195+ }},
196+ WantEvents : []string {
197+ Eventf (corev1 .EventTypeNormal , sourceReconciled , `IntegrationSource reconciled: "%s/%s"` , testNS , sourceName ),
198+ },
165199 }}
166200 logger := logtesting .TestLogger (t )
167201
@@ -182,7 +216,47 @@ func TestReconcile(t *testing.T) {
182216 ))
183217}
184218
185- func makeContainerSource (source * sourcesv1alpha1.IntegrationSource , ready * corev1.ConditionStatus ) runtime.Object {
219+ func makeContainerSourceOIDC (source * sourcesv1alpha1.IntegrationSource , ready * corev1.ConditionStatus ) * sourcesv1.ContainerSource {
220+ cs := makeContainerSource (source , ready )
221+
222+ // replace all env_vars for inserting the OIDC ones at the right order/index
223+ cs .Spec .Template .Spec .Containers [0 ].Env = []corev1.EnvVar {
224+ {
225+ Name : "CAMEL_KNATIVE_CLIENT_SSL_ENABLED" ,
226+ Value : "true" ,
227+ },
228+ {
229+ Name : "CAMEL_KNATIVE_CLIENT_SSL_CERT_PATH" ,
230+ Value : "/knative-custom-certs/knative-eventing-bundle.pem" ,
231+ },
232+ {
233+ Name : "CAMEL_KNATIVE_CLIENT_OIDC_ENABLED" ,
234+ Value : "true" ,
235+ },
236+ {
237+ Name : "CAMEL_KNATIVE_CLIENT_OIDC_TOKEN_PATH" ,
238+ Value : "file:///oidc/token" ,
239+ },
240+ {
241+ Name : "CAMEL_KAMELET_TIMER_SOURCE_PERIOD" ,
242+ Value : "1000" ,
243+ },
244+ {
245+ Name : "CAMEL_KAMELET_TIMER_SOURCE_MESSAGE" ,
246+ Value : "Hallo" ,
247+ },
248+ {
249+ Name : "CAMEL_KAMELET_TIMER_SOURCE_REPEATCOUNT" ,
250+ Value : "0" ,
251+ },
252+ }
253+
254+ cs .Status = * makeContainerSourceStatusOIDC (ready )
255+
256+ return cs
257+ }
258+
259+ func makeContainerSource (source * sourcesv1alpha1.IntegrationSource , ready * corev1.ConditionStatus ) * sourcesv1.ContainerSource {
186260 cs := & sourcesv1.ContainerSource {
187261 ObjectMeta : metav1.ObjectMeta {
188262 OwnerReferences : []metav1.OwnerReference {
@@ -252,6 +326,21 @@ func makeContainerSourceStatus(ready *corev1.ConditionStatus) *sourcesv1.Contain
252326 }
253327}
254328
329+ func makeContainerSourceStatusOIDC (ready * corev1.ConditionStatus ) * sourcesv1.ContainerSourceStatus {
330+ css := makeContainerSourceStatus (ready )
331+ css .Auth = & duckv1.AuthStatus {
332+ ServiceAccountName : ptr .String (getOIDCServiceAccountNameForContainerSource ()),
333+ }
334+ return css
335+ }
336+
337+ func getOIDCServiceAccountNameForContainerSource () string {
338+ return auth .GetOIDCServiceAccountNameForResource (sourcesv1 .SchemeGroupVersion .WithKind ("ContainerSource" ), metav1.ObjectMeta {
339+ Name : containerSourceName ,
340+ Namespace : testNS ,
341+ })
342+ }
343+
255344func makeIntegrationSourceSpec (sink duckv1.Destination ) sourcesv1alpha1.IntegrationSourceSpec {
256345 return sourcesv1alpha1.IntegrationSourceSpec {
257346 Timer : & sourcesv1alpha1.Timer {
0 commit comments