Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling collector to mount multiple configMaps #1989

Merged
merged 19 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented path on ConfigMapsSpec
Signed-off-by: Yuri Sa <yurimsa@gmail.com>
  • Loading branch information
yuriolisa committed Aug 7, 2023
commit c684a24199f55ecc61646609582d51fe81851ccf
1 change: 1 addition & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ type ConfigMapsSpec struct {
Name string `json:"name,omitempty"`
MountPath string `json:"mountpath,omitempty"`
}

func init() {
SchemeBuilder.Register(&OpenTelemetryCollector{}, &OpenTelemetryCollectorList{})
}
4 changes: 2 additions & 2 deletions internal/manifests/collector/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
if len(otelcol.Spec.ConfigMaps) > 0 {
for keyCfgMap := range otelcol.Spec.ConfigMaps {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
yuriolisa marked this conversation as resolved.
Show resolved Hide resolved
Name: otelcol.Spec.ConfigMaps[keyCfgMap].Name,
MountPath: otelcol.Spec.ConfigMaps[keyCfgMap].MountPath+"/"+otelcol.Spec.ConfigMaps[keyCfgMap].Name,
Name: otelcol.Spec.ConfigMaps[keyCfgMap].Name,
MountPath: otelcol.Spec.ConfigMaps[keyCfgMap].MountPath + "/" + otelcol.Spec.ConfigMaps[keyCfgMap].Name,
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
swiatekm marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand Down
26 changes: 26 additions & 0 deletions internal/manifests/collector/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,32 @@ func TestContainerCustomVolumes(t *testing.T) {
assert.Equal(t, "custom-volume-mount", c.VolumeMounts[1].Name)
}

func TestContainerCustomConfigMapsVolumes(t *testing.T) {
// prepare
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
ConfigMaps: []v1alpha1.ConfigMapsSpec{{
Name: "configmap-test",
MountPath: "/var/conf",
},
{
Name: "configmap-test2",
MountPath: "/var/conf",
},
},
},
}
cfg := config.New()

// test
c := Container(cfg, logger, otelcol, true)

// verify
assert.Len(t, c.VolumeMounts, 3)
assert.Equal(t, "configmap-test", c.VolumeMounts[1].Name)
assert.Equal(t, "configmap-test2", c.VolumeMounts[2].Name)
}

func TestContainerCustomSecurityContext(t *testing.T) {
// default config without security context
c1 := Container(config.New(), logger, v1alpha1.OpenTelemetryCollector{Spec: v1alpha1.OpenTelemetryCollectorSpec{}}, true)
Expand Down
13 changes: 6 additions & 7 deletions internal/manifests/collector/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ func TestVolumeWithMoreConfigMaps(t *testing.T) {
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
ConfigMaps: []v1alpha1.ConfigMapsSpec{{
Name: "configmap-test",
MountPath: "/var/conf/",
},
{
Name: "configmap-test2",
MountPath: "/var/conf/",
},
Name: "configmap-test",
MountPath: "/var/conf",
},
{
Name: "configmap-test2",
MountPath: "/var/conf",
}},
},
}
cfg := config.New()
Expand Down