Skip to content

Commit 1e27f02

Browse files
committed
added a config option for enabling mTLS for Target Allocator
Signed-off-by: Praful Khanduri <holiodin@gmail.com>
1 parent 2b0c71f commit 1e27f02

30 files changed

Lines changed: 179 additions & 115 deletions

apis/v1alpha1/convert.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ func tov1beta1Ports(in []PortsSpec) []v1beta1.PortsSpec {
174174
}
175175

176176
func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedded {
177+
var mtls *v1beta1.TargetAllocatorMTLS
178+
if in.Mtls != nil {
179+
mtls = &v1beta1.TargetAllocatorMTLS{
180+
Enabled: in.Mtls.Enabled,
181+
}
182+
}
183+
177184
return v1beta1.TargetAllocatorEmbedded{
178185
Replicas: in.Replicas,
179186
NodeSelector: in.NodeSelector,
@@ -208,6 +215,7 @@ func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedde
208215
},
209216
},
210217
PodDisruptionBudget: tov1beta1PodDisruptionBudget(in.PodDisruptionBudget),
218+
Mtls: mtls,
211219
}
212220
}
213221

@@ -445,6 +453,12 @@ func tov1alpha1TA(in v1beta1.TargetAllocatorEmbedded) OpenTelemetryTargetAllocat
445453
if in.PrometheusCR.ServiceMonitorSelector != nil {
446454
serviceMonitorSelector = in.PrometheusCR.ServiceMonitorSelector.MatchLabels
447455
}
456+
var mtls *TargetAllocatorMTLS
457+
if in.Mtls != nil {
458+
mtls = &TargetAllocatorMTLS{
459+
Enabled: in.Mtls.Enabled,
460+
}
461+
}
448462

449463
return OpenTelemetryTargetAllocator{
450464
Replicas: in.Replicas,
@@ -475,6 +489,7 @@ func tov1alpha1TA(in v1beta1.TargetAllocatorEmbedded) OpenTelemetryTargetAllocat
475489
},
476490
},
477491
PodDisruptionBudget: tov1alpha1PodDisruptionBudget(in.PodDisruptionBudget),
492+
Mtls: mtls,
478493
}
479494
}
480495

apis/v1alpha1/opentelemetrycollector_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ type OpenTelemetryTargetAllocator struct {
381381
//
382382
// +optional
383383
PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
384+
385+
// Mtls defines the mTLS configuration for the target allocator. If enabled, the target allocator will communicate with the collector over mTLS.
386+
Mtls *TargetAllocatorMTLS `json:"mtls,omitempty"`
384387
}
385388

386389
type OpenTelemetryTargetAllocatorPrometheusCR struct {
@@ -613,3 +616,9 @@ type ConfigMapsSpec struct {
613616
Name string `json:"name"`
614617
MountPath string `json:"mountpath"`
615618
}
619+
620+
type TargetAllocatorMTLS struct {
621+
// Enabled indicates whether to enable mTLS between the target allocator and the collector.
622+
// +optional
623+
Enabled bool `json:"enabled,omitempty"`
624+
}

apis/v1alpha1/targetallocator_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type TargetAllocatorSpec struct {
9393
// +kubebuilder:default:="30s"
9494
// +kubebuilder:validation:Format:=duration
9595
CollectorNotReadyGracePeriod *metav1.Duration `json:"collectorNotReadyGracePeriod,omitempty"`
96+
// Mtls defines the mTLS configuration for the target allocator. If enabled, the target allocator will communicate with the collector over mTLS.
97+
// +optional
98+
Mtls *TargetAllocatorMTLS `json:"mtls,omitempty"`
9699
// LivenessProbe defines the liveness probe configuration for the Target Allocator container.
97100
// +optional
98101
LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty"`

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1beta1/opentelemetrycollector_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ type TargetAllocatorEmbedded struct {
237237
// +kubebuilder:default:="30s"
238238
// +kubebuilder:validation:Format:=duration
239239
CollectorTargetReloadInterval *metav1.Duration `json:"collectorTargetReloadInterval,omitempty"`
240+
241+
// Mtls defines the mTLS configuration for the target allocator. If enabled, the target allocator will communicate with the collector over mTLS.
242+
// +optional
243+
Mtls *TargetAllocatorMTLS `json:"mtls,omitempty"`
244+
}
245+
246+
type TargetAllocatorMTLS struct {
247+
// Enabled indicates whether to enable mTLS between the target allocator and the collector.
248+
// +optional
249+
Enabled bool `json:"enabled,omitempty"`
240250
}
241251

242252
// Probe defines the OpenTelemetry's pod probe config.

apis/v1beta1/zz_generated.deepcopy.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controllers/builder_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
3131
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
3232
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator"
33-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3433
)
3534

3635
var (
@@ -2853,6 +2852,9 @@ prometheus_cr:
28532852
},
28542853
Spec: v1alpha1.TargetAllocatorSpec{
28552854
FilterStrategy: v1beta1.TargetAllocatorFilterStrategyRelabelConfig,
2855+
Mtls: &v1alpha1.TargetAllocatorMTLS{
2856+
Enabled: true,
2857+
},
28562858
PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{
28572859
Enabled: true,
28582860
},
@@ -3337,7 +3339,6 @@ prometheus_cr:
33373339
TargetAllocatorConfigMapEntry: "targetallocator.yaml",
33383340
CollectorConfigMapEntry: "collector.yaml",
33393341
},
3340-
featuregates: []*colfeaturegate.Gate{featuregate.EnableTargetAllocatorMTLS},
33413342
},
33423343
}
33433344
for _, tt := range tests {

internal/controllers/targetallocator_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator"
3636
taStatus "github.com/open-telemetry/opentelemetry-operator/internal/status/targetallocator"
3737
"github.com/open-telemetry/opentelemetry-operator/pkg/constants"
38-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3938
)
4039

4140
// TargetAllocatorReconciler reconciles a TargetAllocator object.
@@ -199,7 +198,7 @@ func (r *TargetAllocatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
199198
ctrlBuilder.Owns(&monitoringv1.PodMonitor{})
200199
}
201200

202-
if r.config.CertManagerAvailability == certmanager.Available && featuregate.EnableTargetAllocatorMTLS.IsEnabled() {
201+
if r.config.CertManagerAvailability == certmanager.Available {
203202
ctrlBuilder.Owns(&cmv1.Certificate{})
204203
ctrlBuilder.Owns(&cmv1.Issuer{})
205204
}

internal/manifests/collector/configmap.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
1717
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
1818
"github.com/open-telemetry/opentelemetry-operator/pkg/constants"
19-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2019
)
2120

2221
func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
@@ -49,7 +48,10 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
4948

5049
replaceCfgOpts := []ta.TAOption{}
5150

52-
if otelCol.Spec.TargetAllocator.Enabled && params.Config.CertManagerAvailability == certmanager.Available && featuregate.EnableTargetAllocatorMTLS.IsEnabled() {
51+
if otelCol.Spec.TargetAllocator.Enabled &&
52+
otelCol.Spec.TargetAllocator.Mtls != nil &&
53+
otelCol.Spec.TargetAllocator.Mtls.Enabled &&
54+
params.Config.CertManagerAvailability == certmanager.Available {
5355
replaceCfgOpts = append(replaceCfgOpts, ta.WithTLSConfig(
5456
filepath.Join(constants.TACollectorTLSDirPath, constants.TACollectorCAFileName),
5557
filepath.Join(constants.TACollectorTLSDirPath, constants.TACollectorTLSCertFileName),

internal/manifests/collector/configmap_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ import (
88

99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
11-
colfg "go.opentelemetry.io/collector/featuregate"
1211

12+
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
1313
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/certmanager"
1414
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift"
1515
"github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus"
1616
"github.com/open-telemetry/opentelemetry-operator/internal/config"
1717
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
1818
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
19-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2019
)
2120

2221
func TestDesiredConfigMap(t *testing.T) {
@@ -150,9 +149,6 @@ service:
150149
CertManagerAvailability: certmanager.Available,
151150
})
152151
require.NoError(t, err)
153-
flgs := featuregate.Flags(colfg.GlobalRegistry())
154-
err = flgs.Parse([]string{"--feature-gates=operator.targetallocator.mtls"})
155-
require.NoError(t, err)
156152

157153
hash, _ := manifestutils.GetConfigMapSHA(param.OtelCol.Spec.Config)
158154
expectedName := naming.ConfigMap("test", hash)
@@ -162,6 +158,7 @@ service:
162158
expectedLables["app.kubernetes.io/version"] = "latest"
163159

164160
param.OtelCol.Spec.TargetAllocator.Enabled = true
161+
param.OtelCol.Spec.TargetAllocator.Mtls = &v1beta1.TargetAllocatorMTLS{Enabled: true}
165162
actual, err := ConfigMap(param)
166163

167164
assert.NoError(t, err)
@@ -210,10 +207,7 @@ service:
210207
CertManagerAvailability: certmanager.Available,
211208
})
212209
require.NoError(t, err)
213-
flgs := featuregate.Flags(colfg.GlobalRegistry())
214-
err = flgs.Parse([]string{"--feature-gates=operator.targetallocator.mtls"})
215210
param.TargetAllocator = nil
216-
require.NoError(t, err)
217211

218212
hash, _ := manifestutils.GetConfigMapSHA(param.OtelCol.Spec.Config)
219213
expectedName := naming.ConfigMap("test", hash)

0 commit comments

Comments
 (0)