Skip to content

Commit

Permalink
Remove single-field configs
Browse files Browse the repository at this point in the history
  • Loading branch information
skhalash committed Dec 6, 2024
1 parent 03be612 commit f28e9e1
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 85 deletions.
6 changes: 1 addition & 5 deletions controllers/telemetry/logpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,13 @@ func configureFluentBitReconciler(client client.Client, config LogPipelineContro

//nolint:unparam // error is always nil: An error could be returned after implementing the IstioStatusChecker (TODO)
func configureOtelReconciler(client client.Client, config LogPipelineControllerConfig, _ *prober.LogPipelineProber) (*logpipelineotel.Reconciler, error) {
otelConfig := logpipelineotel.Config{
TelemetryNamespace: config.TelemetryNamespace,
}

pipelineValidator := &logpipelineotel.Validator{
// TODO: Add validators
}

otelReconciler := logpipelineotel.New(
client,
otelConfig,
config.TelemetryNamespace,
otelcollector.NewLogGatewayApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.LogGatewayPriorityClassName),
&gateway.Builder{Reader: client},
&workloadstatus.DeploymentProber{Client: client},
Expand Down
8 changes: 2 additions & 6 deletions controllers/telemetry/metricpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,10 @@ func NewMetricPipelineController(client client.Client, reconcileTriggerChan <-ch

gatewayConfigBuilder := &gateway.Builder{Reader: client}

reconcilerConfig := metricpipeline.Config{
ModuleVersion: config.ModuleVersion,
TelemetryNamespace: config.TelemetryNamespace,
}

reconciler := metricpipeline.New(
client,
reconcilerConfig,
config.TelemetryNamespace,
config.ModuleVersion,
otelcollector.NewMetricAgentApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.MetricAgentPriorityClassName),
agentConfigBuilder,
&workloadstatus.DaemonSetProber{Client: client},
Expand Down
6 changes: 1 addition & 5 deletions controllers/telemetry/tracepipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@ func NewTracePipelineController(client client.Client, reconcileTriggerChan <-cha
return nil, err
}

reconcilerConfig := tracepipeline.Config{
TelemetryNamespace: config.TelemetryNamespace,
}

reconciler := tracepipeline.New(
client,
reconcilerConfig,
config.TelemetryNamespace,
flowHealthProber,
otelcollector.NewTraceGatewayApplierDeleter(config.OTelCollectorImage, config.TelemetryNamespace, config.TraceGatewayPriorityClassName),
&gateway.Builder{Reader: client},
Expand Down
10 changes: 3 additions & 7 deletions internal/reconciler/logpipeline/otel/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import (

const defaultReplicaCount int32 = 2

type Config struct {
TelemetryNamespace string
}

type GatewayConfigBuilder interface {
Build(ctx context.Context, pipelines []telemetryv1alpha1.LogPipeline) (*gateway.Config, otlpexporter.EnvVars, error)
}
Expand All @@ -47,7 +43,7 @@ var _ logpipeline.LogPipelineReconciler = &Reconciler{}
type Reconciler struct {
client.Client

config Config
telemetryNamespace string

// Dependencies
gatewayApplierDeleter GatewayApplierDeleter
Expand All @@ -59,7 +55,7 @@ type Reconciler struct {

func New(
client client.Client,
config Config,
telemetryNamespace string,
gatewayApplierDeleter GatewayApplierDeleter,
gatewayConfigBuilder GatewayConfigBuilder,
gatewayProber commonstatus.Prober,
Expand All @@ -68,7 +64,7 @@ func New(
) *Reconciler {
return &Reconciler{
Client: client,
config: config,
telemetryNamespace: telemetryNamespace,
gatewayApplierDeleter: gatewayApplierDeleter,
gatewayConfigBuilder: gatewayConfigBuilder,
gatewayProber: gatewayProber,
Expand Down
10 changes: 4 additions & 6 deletions internal/reconciler/logpipeline/otel/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func TestReconcile(t *testing.T) {
overridesHandlerStub := &logpipelinemocks.OverridesHandler{}
overridesHandlerStub.On("LoadOverrides", context.Background()).Return(&overrides.Config{}, nil)

testConfig := Config{
TelemetryNamespace: "default",
}
telemetryNamespace := "default"

t.Run("log gateway probing failed", func(t *testing.T) {
pipeline := testutils.NewLogPipelineBuilder().WithName("pipeline").WithOTLPOutput().Build()
Expand All @@ -61,7 +59,7 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
gatewayApplierDeleterMock,
gatewayConfigBuilderMock,
gatewayProberStub,
Expand Down Expand Up @@ -109,7 +107,7 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
gatewayApplierDeleterMock,
gatewayConfigBuilderMock,
gatewayProberStub,
Expand Down Expand Up @@ -157,7 +155,7 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
gatewayApplierDeleterMock,
gatewayConfigBuilderMock,
gatewayProberStub,
Expand Down
2 changes: 1 addition & 1 deletion internal/reconciler/logpipeline/otel/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (r *Reconciler) updateStatus(ctx context.Context, pipelineName string) erro

func (r *Reconciler) setGatewayHealthyCondition(ctx context.Context, pipeline *telemetryv1alpha1.LogPipeline) {
condition := commonstatus.GetGatewayHealthyCondition(ctx,
r.gatewayProber, types.NamespacedName{Name: otelcollector.LogGatewayName, Namespace: r.config.TelemetryNamespace},
r.gatewayProber, types.NamespacedName{Name: otelcollector.LogGatewayName, Namespace: r.telemetryNamespace},
r.errToMessageConverter,
commonstatus.SignalTypeLogs)
condition.ObservedGeneration = pipeline.Generation
Expand Down
23 changes: 11 additions & 12 deletions internal/reconciler/metricpipeline/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ import (

const defaultReplicaCount int32 = 2

type Config struct {
ModuleVersion string
TelemetryNamespace string
}

type AgentConfigBuilder interface {
Build(pipelines []telemetryv1alpha1.MetricPipeline, options agent.BuildOptions) *agent.Config
}
Expand Down Expand Up @@ -71,7 +66,9 @@ type IstioStatusChecker interface {
type Reconciler struct {
client.Client

config Config
telemetryNamespace string
// TODO(skhalash): introduce an embed pkg exposing the module version set by go build
moduleVersion string

agentApplierDeleter AgentApplierDeleter
agentConfigBuilder AgentConfigBuilder
Expand All @@ -89,7 +86,8 @@ type Reconciler struct {

func New(
client client.Client,
config Config,
telemetryNamespace string,
moduleVersion string,
agentApplierDeleter AgentApplierDeleter,
agentConfigBuilder AgentConfigBuilder,
agentProber commonstatus.Prober,
Expand All @@ -105,7 +103,8 @@ func New(
) *Reconciler {
return &Reconciler{
Client: client,
config: config,
telemetryNamespace: telemetryNamespace,
moduleVersion: moduleVersion,
agentApplierDeleter: agentApplierDeleter,
agentConfigBuilder: agentConfigBuilder,
agentProber: agentProber,
Expand Down Expand Up @@ -244,8 +243,8 @@ func isMetricAgentRequired(pipeline *telemetryv1alpha1.MetricPipeline) bool {

func (r *Reconciler) reconcileMetricGateway(ctx context.Context, pipeline *telemetryv1alpha1.MetricPipeline, allPipelines []telemetryv1alpha1.MetricPipeline) error {
collectorConfig, collectorEnvVars, err := r.gatewayConfigBuilder.Build(ctx, allPipelines, gateway.BuildOptions{
GatewayNamespace: r.config.TelemetryNamespace,
InstrumentationScopeVersion: r.config.ModuleVersion,
GatewayNamespace: r.telemetryNamespace,
InstrumentationScopeVersion: r.moduleVersion,
})

if err != nil {
Expand Down Expand Up @@ -290,8 +289,8 @@ func (r *Reconciler) reconcileMetricAgents(ctx context.Context, pipeline *teleme
agentConfig := r.agentConfigBuilder.Build(allPipelines, agent.BuildOptions{
IstioEnabled: isIstioActive,
IstioCertPath: otelcollector.IstioCertPath,
InstrumentationScopeVersion: r.config.ModuleVersion,
AgentNamespace: r.config.TelemetryNamespace,
InstrumentationScopeVersion: r.moduleVersion,
AgentNamespace: r.telemetryNamespace,
})

agentConfigYAML, err := yaml.Marshal(agentConfig)
Expand Down
50 changes: 32 additions & 18 deletions internal/reconciler/metricpipeline/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ func TestReconcile(t *testing.T) {

istioStatusCheckerStub := &stubs.IstioStatusChecker{IsActive: false}

testConfig := Config{
TelemetryNamespace: "default",
}
telemetryNamespace := "default"
moduleVersion := "1.0.0"

t.Run("metric gateway deployment is not ready", func(t *testing.T) {
pipeline := testutils.NewMetricPipelineBuilder().Build()
Expand Down Expand Up @@ -81,7 +80,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -141,7 +141,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -201,7 +202,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -267,7 +269,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
agentApplierDeleterMock,
agentConfigBuilderMock,
agentProberStub,
Expand Down Expand Up @@ -335,7 +338,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
agentApplierDeleterMock,
agentConfigBuilderMock,
agentProberStub,
Expand Down Expand Up @@ -403,7 +407,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
agentApplierDeleterMock,
agentConfigBuilderMock,
agentProberStub,
Expand Down Expand Up @@ -472,7 +477,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -535,7 +541,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
agentApplierDeleterMock,
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -599,7 +606,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -761,7 +769,8 @@ func TestReconcile(t *testing.T) {
errToMsg := &conditions.ErrorToMessageConverter{}
sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -905,7 +914,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
agentApplierDeleterMock,
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -990,7 +1000,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -1060,7 +1071,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
&mocks.AgentApplierDeleter{},
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -1134,7 +1146,8 @@ func TestReconcile(t *testing.T) {

sut := New(
fakeClient,
testConfig,
telemetryNamespace,
moduleVersion,
agentApplierDeleterMock,
&mocks.AgentConfigBuilder{},
agentProberStub,
Expand Down Expand Up @@ -1259,7 +1272,8 @@ func TestReconcile(t *testing.T) {

sut := Reconciler{
Client: fakeClient,
config: testConfig,
telemetryNamespace: telemetryNamespace,
moduleVersion: moduleVersion,
agentConfigBuilder: agentConfigBuilderMock,
gatewayConfigBuilder: gatewayConfigBuilderMock,
agentApplierDeleter: agentApplierDeleterMock,
Expand Down
4 changes: 2 additions & 2 deletions internal/reconciler/metricpipeline/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *Reconciler) setAgentHealthyCondition(ctx context.Context, pipeline *tel
if isMetricAgentRequired(pipeline) {
condition = commonstatus.GetAgentHealthyCondition(ctx,
r.agentProber,
types.NamespacedName{Name: otelcollector.MetricAgentName, Namespace: r.config.TelemetryNamespace},
types.NamespacedName{Name: otelcollector.MetricAgentName, Namespace: r.telemetryNamespace},
r.errToMsgConverter,
commonstatus.SignalTypeMetrics)
}
Expand All @@ -72,7 +72,7 @@ func (r *Reconciler) setAgentHealthyCondition(ctx context.Context, pipeline *tel

func (r *Reconciler) setGatewayHealthyCondition(ctx context.Context, pipeline *telemetryv1alpha1.MetricPipeline) {
condition := commonstatus.GetGatewayHealthyCondition(ctx,
r.gatewayProber, types.NamespacedName{Name: otelcollector.MetricGatewayName, Namespace: r.config.TelemetryNamespace},
r.gatewayProber, types.NamespacedName{Name: otelcollector.MetricGatewayName, Namespace: r.telemetryNamespace},
r.errToMsgConverter,
commonstatus.SignalTypeMetrics)
condition.ObservedGeneration = pipeline.Generation
Expand Down
Loading

0 comments on commit f28e9e1

Please sign in to comment.