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

feat: allow resource configuration on collector spec #248

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions api/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type OpenTelemetryCollectorSpec struct {
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Env []v1.EnvVar `json:"env,omitempty"`

// Resources to set on the OpenTelemetry Collector pods.
// +optional
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector.
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,32 @@ spec:
OpenTelemetry Collector
format: int32
type: integer
resources:
description: Resources to set on the OpenTelemetry Collector pods.
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute resources
allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
serviceAccount:
description: ServiceAccount indicates the name of an existing service
account to use with this instance.
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
VolumeMounts: volumeMounts,
Args: args,
Env: envVars,
Resources: otelcol.Spec.Resources,
}
}
43 changes: 43 additions & 0 deletions pkg/collector/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -133,3 +134,45 @@ func TestContainerEmptyEnvVarsByDefault(t *testing.T) {
// verify
assert.Empty(t, c.Env)
}

func TestContainerResourceRequirements(t *testing.T) {
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("100m"),
corev1.ResourceMemory: resource.MustParse("128M"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("200m"),
corev1.ResourceMemory: resource.MustParse("256M"),
},
},
},
}

cfg := config.New()

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

// verify
assert.Equal(t, resource.MustParse("100m"), *c.Resources.Limits.Cpu())
assert.Equal(t, resource.MustParse("128M"), *c.Resources.Limits.Memory())
assert.Equal(t, resource.MustParse("200m"), *c.Resources.Requests.Cpu())
assert.Equal(t, resource.MustParse("256M"), *c.Resources.Requests.Memory())
}

func TestContainerDefaultResourceRequirements(t *testing.T) {
otelcol := v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{},
}

cfg := config.New()

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

// verify
assert.Empty(t, c.Resources)
}