From 5cbd1e58953599cdd3a4db20fb78eda5a47d4c9f Mon Sep 17 00:00:00 2001 From: Luis Sergio Carneiro Date: Thu, 23 Jul 2026 10:32:54 -0300 Subject: [PATCH] Fix #6724: Allow setting enableServiceLinks on the Integration pod template Add an EnableServiceLinks *bool field to the curated v1.PodSpec used by spec.template.spec, so users can control the Kubernetes pod-level enableServiceLinks flag (defaults to true) on an Integration. The pod trait applies spec.template.spec as a strategic merge patch onto the workload pod spec, so the new field propagates to Deployment, CronJob and Knative Service pods with no further trait changes. Regenerated the CRDs (integrations, pipes), the Helm CRD bundle, deepcopy and the apply-configuration client. Added a unit test covering enableServiceLinks: false. Note: PodSpecTemplate / v1.PodSpec and the pod trait are deprecated, but this is currently the only mechanism able to set a pod-level flag such as enableServiceLinks (no non-deprecated trait covers it). Co-Authored-By: Claude Opus 4.8 (1M context) --- helm/camel-k/crds/camel-k-crds.yaml | 12 ++++++++++++ pkg/apis/camel/v1/integration_types.go | 2 ++ pkg/apis/camel/v1/zz_generated.deepcopy.go | 5 +++++ .../camel/applyconfiguration/camel/v1/podspec.go | 10 ++++++++++ .../crd/bases/camel.apache.org_integrations.yaml | 6 ++++++ .../config/crd/bases/camel.apache.org_pipes.yaml | 6 ++++++ pkg/trait/pod_test.go | 8 ++++++++ 7 files changed, 49 insertions(+) diff --git a/helm/camel-k/crds/camel-k-crds.yaml b/helm/camel-k/crds/camel-k-crds.yaml index cfa3ce7d57..20c9d6430f 100644 --- a/helm/camel-k/crds/camel-k-crds.yaml +++ b/helm/camel-k/crds/camel-k-crds.yaml @@ -15093,6 +15093,12 @@ spec: dnsPolicy: description: DNSPolicy type: string + enableServiceLinks: + description: EnableServiceLinks indicates whether information + about services should be injected into the Pod's environment + variables, matching the syntax of Docker links. Defaults + to true. + type: boolean ephemeralContainers: description: EphemeralContainers items: @@ -28057,6 +28063,12 @@ spec: dnsPolicy: description: DNSPolicy type: string + enableServiceLinks: + description: EnableServiceLinks indicates whether information + about services should be injected into the Pod's environment + variables, matching the syntax of Docker links. Defaults + to true. + type: boolean ephemeralContainers: description: EphemeralContainers items: diff --git a/pkg/apis/camel/v1/integration_types.go b/pkg/apis/camel/v1/integration_types.go index a74e53955e..b96e340cf9 100644 --- a/pkg/apis/camel/v1/integration_types.go +++ b/pkg/apis/camel/v1/integration_types.go @@ -327,6 +327,8 @@ type PodSpecTemplate struct { type PodSpec struct { // AutomountServiceAccountToken AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" protobuf:"varint,21,opt,name=automountServiceAccountToken"` + // EnableServiceLinks indicates whether information about services should be injected into the Pod's environment variables, matching the syntax of Docker links. Defaults to true. + EnableServiceLinks *bool `json:"enableServiceLinks,omitempty" protobuf:"varint,30,opt,name=enableServiceLinks"` // Volumes Volumes []corev1.Volume `json:"volumes,omitempty" patchMergeKey:"name" patchStrategy:"merge,retainKeys" protobuf:"bytes,1,rep,name=volumes"` // InitContainers diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go index f267d27334..778431077a 100644 --- a/pkg/apis/camel/v1/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go @@ -2749,6 +2749,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) { *out = new(bool) **out = **in } + if in.EnableServiceLinks != nil { + in, out := &in.EnableServiceLinks, &out.EnableServiceLinks + *out = new(bool) + **out = **in + } if in.Volumes != nil { in, out := &in.Volumes, &out.Volumes *out = make([]corev1.Volume, len(*in)) diff --git a/pkg/client/camel/applyconfiguration/camel/v1/podspec.go b/pkg/client/camel/applyconfiguration/camel/v1/podspec.go index 7e14ad6cf8..29f8de035e 100644 --- a/pkg/client/camel/applyconfiguration/camel/v1/podspec.go +++ b/pkg/client/camel/applyconfiguration/camel/v1/podspec.go @@ -32,6 +32,8 @@ import ( type PodSpecApplyConfiguration struct { // AutomountServiceAccountToken AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty"` + // EnableServiceLinks indicates whether information about services should be injected into the Pod's environment variables, matching the syntax of Docker links. Defaults to true. + EnableServiceLinks *bool `json:"enableServiceLinks,omitempty"` // Volumes Volumes []corev1.Volume `json:"volumes,omitempty"` // InitContainers @@ -70,6 +72,14 @@ func (b *PodSpecApplyConfiguration) WithAutomountServiceAccountToken(value bool) return b } +// WithEnableServiceLinks sets the EnableServiceLinks field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the EnableServiceLinks field is set to the value of the last call. +func (b *PodSpecApplyConfiguration) WithEnableServiceLinks(value bool) *PodSpecApplyConfiguration { + b.EnableServiceLinks = &value + return b +} + // WithVolumes adds the given value to the Volumes field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Volumes field. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml index b28553df19..cfe9de6503 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml @@ -1836,6 +1836,12 @@ spec: dnsPolicy: description: DNSPolicy type: string + enableServiceLinks: + description: EnableServiceLinks indicates whether information + about services should be injected into the Pod's environment + variables, matching the syntax of Docker links. Defaults + to true. + type: boolean ephemeralContainers: description: EphemeralContainers items: diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml index 035b9133af..67c512db62 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml @@ -1843,6 +1843,12 @@ spec: dnsPolicy: description: DNSPolicy type: string + enableServiceLinks: + description: EnableServiceLinks indicates whether information + about services should be injected into the Pod's environment + variables, matching the syntax of Docker links. Defaults + to true. + type: boolean ephemeralContainers: description: EphemeralContainers items: diff --git a/pkg/trait/pod_test.go b/pkg/trait/pod_test.go index 68fc25cd51..c48e6d07cf 100755 --- a/pkg/trait/pod_test.go +++ b/pkg/trait/pod_test.go @@ -112,6 +112,14 @@ func TestAutomountServiceAccountToken(t *testing.T) { assert.False(t, *templateSpec.Spec.AutomountServiceAccountToken) } +func TestEnableServiceLinks(t *testing.T) { + templateString := `enableServiceLinks: false` + templateSpec := testPodTemplateSpec(t, templateString) + + assert.NotNil(t, templateSpec.Spec.EnableServiceLinks) + assert.False(t, *templateSpec.Spec.EnableServiceLinks) +} + // nolint: unparam func createPodTest(podSpecTemplate string) (*podTrait, *Environment, *appsv1.Deployment) { trait, _ := newPodTrait().(*podTrait)