Skip to content

Commit 6782fdf

Browse files
authored
Fix defaulting a component with empty value (#3690)
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 654875e commit 6782fdf

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

.chloggen/3452.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Fix config handling with null values.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3452]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: |
17+
Fix the defaulting webhook error `src and dst must not be nil` caused by defaulting a known component with a null value:
18+
e.g.
19+
```yaml
20+
receivers:
21+
zipkin:
22+
```

apis/v1beta1/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ func (c *Config) applyDefaultForComponentKinds(logger logr.Logger, componentKind
306306
continue
307307
}
308308

309+
if componentConf == nil {
310+
componentConf = map[string]interface{}{}
311+
}
309312
if err := mergo.Merge(&mappedCfg, componentConf); err != nil {
310313
return err
311314
}

apis/v1beta1/config_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ func TestNullObjects(t *testing.T) {
7777
assert.Equal(t, []string{"connectors.spanmetrics:", "exporters.otlp.endpoint:", "extensions.health_check:", "processors.batch:", "receivers.otlp.protocols.grpc:", "receivers.otlp.protocols.http:"}, nullObjects)
7878
}
7979

80+
func TestNullObjects_issue_3445(t *testing.T) {
81+
collectorYaml, err := os.ReadFile("./testdata/issue-3452.yaml")
82+
require.NoError(t, err)
83+
84+
collectorJson, err := yaml.YAMLToJSON(collectorYaml)
85+
require.NoError(t, err)
86+
87+
cfg := &Config{}
88+
err = json.Unmarshal(collectorJson, cfg)
89+
require.NoError(t, err)
90+
91+
err = cfg.ApplyDefaults(logr.Discard())
92+
require.NoError(t, err)
93+
assert.Empty(t, cfg.nullObjects())
94+
}
95+
8096
func TestConfigFiles_go_yaml(t *testing.T) {
8197
files, err := os.ReadDir("./testdata")
8298
require.NoError(t, err)

apis/v1beta1/testdata/issue-3452.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
receivers:
2+
zipkin:
3+
service:
4+
pipelines:
5+
traces:
6+
receivers: [zipkin]

0 commit comments

Comments
 (0)